[flang-commits] [flang] [flang][OpenMP] Diagnose task reduction array sections and elements (PR #215997)
via flang-commits
flang-commits at lists.llvm.org
Tue Aug 25 12:18:39 PDT 2026
================
@@ -182,6 +180,124 @@ static bool hasPrivatizedArrayElementReduction(
return false;
}
+static bool
+hasPartialArrayReductionObject(llvm::ArrayRef<Object> reductionObjects,
+ semantics::SemanticsContext &semaCtx) {
+ for (const Object &object : reductionObjects) {
+ if (!object.ref() || isWholeArraySection(object, semaCtx))
+ continue;
+ if (evaluate::IsArraySection(*object.ref()))
+ return true;
+ }
+ return false;
+}
+
+static void checkTaskModifierPartialArrayReduction(
+ mlir::Location loc, semantics::SemanticsContext &semaCtx,
+ mlir::omp::ReductionModifierAttr reductionMod,
+ llvm::ArrayRef<Object> reductionObjects) {
+ if (reductionMod &&
----------------
MattPD wrote:
Just to clarify, I do not think this requires changing the MLIR representation. In the clause AST, each `reduction` clause still carries its own modifier and its own object list until lowering flattens them.
At `db4b1b6`, a `task`-modified user-defined reduction on an array section followed by a `default`-modified scalar compiles with no diagnostic, and the reduction covers the whole array rather than that section. Reversing the order of the two clauses produces the expected diagnostic. In the other direction, a `task`-modified scalar followed by a user-defined reduction item with no modifier makes the compiler diagnose that second item.
Could the `task` modifier checks scan `item->clauses` with `ClauseFinder::findRepeatableClause<clause::Reduction>`, read the modifier from each clause tuple, and check only that clause's `ObjectList`? That looks like it would leave MLIR operation construction unchanged. The existing single-modifier limitation in the dialect could stay out of scope here, or get a separate not-yet-implemented diagnostic.
https://github.com/llvm/llvm-project/pull/215997
More information about the flang-commits
mailing list