[flang-commits] [flang] [flang][OpenMP] Improve diagnosing invalid operators in DECLARE_REDUCTION (PR #232353)

via flang-commits flang-commits at lists.llvm.org
Sun Oct 25 20:45:15 PDT 2026


================
@@ -771,8 +771,26 @@ void OmpStructureChecker::Enter(const parser::OmpMetadirectiveDirective &x) {
   EnterDirectiveNest(MetadirectiveNest);
 }
 
-void OmpStructureChecker::Leave(const parser::OmpMetadirectiveDirective &) {
-  ExitDirectiveNest(MetadirectiveNest);
+void OmpStructureChecker::Leave(const parser::OmpMetadirectiveDirective &x) {
+  // Perform semantic checks on declarative variants on this METADIRECTIVE.
+  if (!partStack_.empty() && partStack_.back() == PartKind::SpecificationPart) {
+    OmpVariantMatchContext matchContext{context_};
+    for (const parser::OmpClause &clause : x.v.Clauses().v) {
+      auto *variant{GetDirectiveVariant(clause)};
+      if (!variant) {
+        continue;
+      }
+      if (!MayVariantBeSelected(
+              GetContextSelector(clause), context_, matchContext)) {
+        continue;
+      }
+      llvm::omp::Directive dirId{variant->DirId()};
+      if (dirId == llvm::omp::Directive::OMPD_declare_reduction) {
+        CheckDeclareReduction(*variant);
+      }
+    }
+    ExitDirectiveNest(MetadirectiveNest);
----------------
MattPD wrote:

The new TASKWAIT test detects the regression, but `f03` also passes with the defective nesting implementation. Could you add `!$omp metadirective otherwise(nothing)` immediately before `!$omp begin metadirective` in the v52 test?

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


More information about the flang-commits mailing list