[flang-commits] [flang] [flang][OpenMP] Diagnose privatized array section reductions (PR #215997)

via flang-commits flang-commits at lists.llvm.org
Tue Aug 18 18:56:48 PDT 2026


================
@@ -4922,14 +4919,16 @@ static mlir::omp::TaskloopContextOp genStandaloneTaskloop(
                            enableDelayedPrivatization, symTable);
   dsp.processStep1(&taskloopClauseOps);
 
-  if (hasPrivatizedArrayElementReduction(inReductionObjects,
-                                         dsp.getAllSymbolsToPrivatize()))
-    TODO(loc, "TASKLOOP construct with IN_REDUCTION of an array element whose "
-              "base array is privatized");
-  if (hasPrivatizedArrayElementReduction(reductionObjects,
-                                         dsp.getAllSymbolsToPrivatize()))
-    TODO(loc, "TASKLOOP construct with REDUCTION of an array element whose "
-              "base array is privatized");
+  if (hasPrivatizedArrayReductionObject(inReductionObjects,
+                                        dsp.getDelayedPrivSymbols()))
+    TODO(loc,
+         "TASKLOOP construct with IN_REDUCTION of an array element or section "
+         "whose base array is privatized");
+  if (hasPrivatizedArrayReductionObject(reductionObjects,
+                                        dsp.getDelayedPrivSymbols()))
----------------
MattPD wrote:

Confirmed, full-extent sections are covered now.

A user-defined reduction on a partial array section still bypasses the diagnostic when its base inherits `shared` from an enclosing parallel region:

```fortran
!$omp parallel shared(a)
!$omp single
!$omp taskloop reduction(myred : a(2:3))
```

In both eager and delayed privatization modes, the generated reduction initializes and combines the whole array, although the body accesses only `a(2:3)`.

Could partial array sections be diagnosed independently of whether their base is privatized? A negative test with a user-defined reduction over a shared base would pin that down.

https://github.com/llvm/llvm-project/pull/215997


More information about the flang-commits mailing list