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

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Fri Sep 25 05:24:58 PDT 2026


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

Make the checks version-sensitive.

>From 108c55aad9d012d393d1223703489922674f1935 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 24 Sep 2026 16:02:58 -0500
Subject: [PATCH] [flang][OpenMP] Improve clause checks on FLUSH construct

Make the checks version-sensitive.
---
 flang/lib/Semantics/check-omp-structure.cpp   | 54 ++++++++++++++++---
 .../Semantics/OpenMP/clause-validity01.f90    |  3 +-
 flang/test/Semantics/OpenMP/flush02.f90       | 13 ++---
 flang/test/Semantics/OpenMP/flush03.f90       |  1 +
 4 files changed, 58 insertions(+), 13 deletions(-)

diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index c3fc7ced2bfdb5..0146ce2f2a6bf8 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -3430,8 +3430,17 @@ void OmpStructureChecker::Leave(
 }
 
 void OmpStructureChecker::Leave(const parser::OpenMPFlushConstruct &x) {
+  llvm::omp::Version version{context_.langOptions().getOpenMPVersion()};
   auto &flushList{std::get<std::optional<parser::OmpArgumentList>>(x.v.t)};
 
+  llvm::omp::Clauses memOrder{
+      llvm::omp::Clause::OMPC_acq_rel,
+      llvm::omp::Clause::OMPC_acquire,
+      llvm::omp::Clause::OMPC_relaxed,
+      llvm::omp::Clause::OMPC_release,
+      llvm::omp::Clause::OMPC_seq_cst,
+  };
+
   auto isVariableListItemOrCommonBlock{[](const Symbol &sym) {
     return IsVariableListItem(sym) ||
         sym.detailsIf<semantics::CommonBlockDetails>();
@@ -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;
+      }
     }
   }
 
-  llvm::omp::Version version{context_.langOptions().getOpenMPVersion()};
   if (version >= 52) {
     auto &flags{std::get<parser::OmpDirectiveSpecification::Flags>(x.v.t)};
     if (flags.test(parser::OmpDirectiveSpecification::Flag::DeprecatedSyntax)) {
diff --git a/flang/test/Semantics/OpenMP/clause-validity01.f90 b/flang/test/Semantics/OpenMP/clause-validity01.f90
index e65cb89b8be08e..38251e722112e7 100644
--- a/flang/test/Semantics/OpenMP/clause-validity01.f90
+++ b/flang/test/Semantics/OpenMP/clause-validity01.f90
@@ -522,11 +522,12 @@
   !WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
   !$omp flush acquire
   !WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
-  !ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
+  !ERROR: If a 'memory-order' clause is specified, list items must not be specified on the FLUSH directive
   !$omp flush release (c)
   !WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
   !$omp flush seq_cst
   !WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
+  !ERROR: Only ACQ_REL, ACQUIRE, RELEASE or SEQ_CST memory-order clauses are allowed
   !ERROR: RELAXED clause is not allowed on FLUSH directive
   !$omp flush relaxed
 
diff --git a/flang/test/Semantics/OpenMP/flush02.f90 b/flang/test/Semantics/OpenMP/flush02.f90
index db0cc12398b970..644843a29a157b 100644
--- a/flang/test/Semantics/OpenMP/flush02.f90
+++ b/flang/test/Semantics/OpenMP/flush02.f90
@@ -28,6 +28,7 @@
   if (omp_get_thread_num() == 1) THEN
     ! Not allowed clauses.
     !$omp flush seq_cst
+    !ERROR: Only ACQ_REL, ACQUIRE, RELEASE or SEQ_CST memory-order clauses are allowed
     !ERROR: RELAXED clause is not allowed on FLUSH directive
     !$omp flush relaxed
 
@@ -57,21 +58,21 @@
 
   array = (/1, 2, 3, 4, 5, 6, 7, 8, 9, 10/)
   if (omp_get_thread_num() == 3) THEN
-    !ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
+    !ERROR: If a 'memory-order' clause is specified, list items must not be specified on the FLUSH directive
     !$omp flush acq_rel (array)
-    !ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
+    !ERROR: If a 'memory-order' clause is specified, list items must not be specified on the FLUSH directive
     !$omp flush acq_rel (array, a, i)
 
     array = (/1, 2, 3, 4, 5, 6, 7, 8, 9, 10/)
-    !ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
+    !ERROR: If a 'memory-order' clause is specified, list items must not be specified on the FLUSH directive
     !$omp flush release (array)
-    !ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
+    !ERROR: If a 'memory-order' clause is specified, list items must not be specified on the FLUSH directive
     !$omp flush release (array, a)
 
     array = (/1, 2, 3, 4, 5, 6, 7, 8, 9, 10/)
-    !ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
+    !ERROR: If a 'memory-order' clause is specified, list items must not be specified on the FLUSH directive
     !$omp flush acquire (array)
-    !ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
+    !ERROR: If a 'memory-order' clause is specified, list items must not be specified on the FLUSH directive
     !$omp flush acquire (array, a, structObj%rr)
   END IF
   !$omp end parallel
diff --git a/flang/test/Semantics/OpenMP/flush03.f90 b/flang/test/Semantics/OpenMP/flush03.f90
index 82c5bef5f5b8d6..d92555c341d502 100644
--- a/flang/test/Semantics/OpenMP/flush03.f90
+++ b/flang/test/Semantics/OpenMP/flush03.f90
@@ -2,6 +2,7 @@
 
 subroutine f00(x)
   integer :: x
+!ERROR: If a 'memory-order' clause is specified, list items must not be specified on the FLUSH directive
 !ERROR: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
   !$omp flush seq_cst (x)
 end



More information about the flang-commits mailing list