[flang-commits] [flang] [flang][OpenMP] Diagnose invalid reduction modifiers (PR #92406)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Sat May 18 06:50:02 PDT 2024


================
@@ -2393,6 +2394,57 @@ void OmpStructureChecker::CheckReductionTypeList(
   }
 }
 
+void OmpStructureChecker::CheckReductionModifier(
+    const parser::OmpClause::Reduction &x) {
+  using ReductionModifier = parser::OmpReductionClause::ReductionModifier;
+  const auto &maybeModifier{std::get<std::optional<ReductionModifier>>(x.v.t)};
+  if (!maybeModifier || *maybeModifier == ReductionModifier::Default) {
+    // No modifier, or the default one is always ok.
+    return;
+  }
+  ReductionModifier modifier{*maybeModifier};
+  const DirectiveContext &dirCtx{GetContext()};
+  if (modifier == ReductionModifier::Task) {
+    // "Task" is only allowed on worksharing or "parallel" directive.
+    static llvm::omp::Directive worksharing[]{
+        llvm::omp::Directive::OMPD_do,
+        // llvm::omp::Directive::OMPD_for, C++ only
+        llvm::omp::Directive::OMPD_loop,
----------------
kiranchandramohan wrote:

In the restrictions for loop directive. Page 257 OMP 5.2
`If a reduction-modifier is specified in a reduction clause that appears on the directive then the reduction modifier must be default.`

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


More information about the flang-commits mailing list