[flang-commits] [flang] [flang][OpenMP] Improve clause checks on FLUSH construct (PR #226467)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Fri Sep 25 10:46:37 PDT 2026


================
@@ -3446,15 +3455,48 @@ void OmpStructureChecker::Leave(const parser::OpenMPFlushConstruct &x) {
       }
     }
 
-    if (FindClause(llvm::omp::Clause::OMPC_acquire) ||
-        FindClause(llvm::omp::Clause::OMPC_release) ||
-        FindClause(llvm::omp::Clause::OMPC_acq_rel)) {
-      context_.Say(flushList->source,
-          "If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive"_err_en_US);
+    for (const parser::OmpClause &clause : x.v.Clauses().v) {
+      if (memOrder.test(clause.Id())) {
+        context_.Say(flushList->source,
+            "If a 'memory-order' clause is specified, list items must not be specified on the FLUSH directive"_err_en_US);
+        break;
+      }
+    }
+  }
+
+  for (const parser::OmpClause &clause : x.v.Clauses().v) {
+    llvm::omp::Clause clauseId{clause.Id()};
+    if (!memOrder.test(clauseId)) {
+      continue;
+    }
+    if (version == 50) {
+      // In 5.0 only ACQ_REL, ACQUIRE or RELEASE are allowed.
+      switch (clauseId) {
+      case llvm::omp::Clause::OMPC_acq_rel:
+      case llvm::omp::Clause::OMPC_acquire:
+      case llvm::omp::Clause::OMPC_release:
+        continue;
+      default:
+        context_.Say(clause.source,
+            "Only ACQ_REL, ACQUIRE or RELEASE memory-order clauses are allowed"_err_en_US);
+        break;
+      }
+    } else if (version >= 51) {
+      // In 5.1+ only ACQ_REL, ACQUIRE, RELEASE or SEQ_CST are allowed.
+      switch (clauseId) {
+      case llvm::omp::Clause::OMPC_acq_rel:
+      case llvm::omp::Clause::OMPC_acquire:
+      case llvm::omp::Clause::OMPC_release:
+      case llvm::omp::Clause::OMPC_seq_cst:
+        continue;
+      default:
+        context_.Say(clause.source,
+            "Only ACQ_REL, ACQUIRE, RELEASE or SEQ_CST memory-order clauses are allowed"_err_en_US);
+        break;
+      }
----------------
abidh wrote:

Understood, thanks. I was not aware that generic path is on its way out. Although I will say that I liked the original message because it told user the clause, directive, the version and flag that will make it work. 

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


More information about the flang-commits mailing list