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

via flang-commits flang-commits at lists.llvm.org
Fri Oct 23 12:49:51 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:

I confirmed that Flang now diagnoses the invalid TASKWAIT and accepts the valid later declaration. Could you add regression tests for both cases?

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


More information about the flang-commits mailing list