[flang-commits] [flang] [flang][OpenMP] Allow flush of common block (PR #139528)

via flang-commits flang-commits at lists.llvm.org
Mon May 12 03:19:09 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Tom Eccles (tblah)

<details>
<summary>Changes</summary>

I think this was denied by accident in https://github.com/llvm/llvm-project/commit/68180d8d16f07db8200dfce7bae26a80c43ebc5e.

Flush of a common block is allowed by the standard on my reading. It is
not allowed by classic-flang but is supported by gfortran and ifx.

This doesn't need any lowering changes. The LLVM translation ignores the
flush argument list because the openmp runtime library doesn't support
flushing specific data.

Depends upon https://github.com/llvm/llvm-project/pull/139522. Ignore the first commit in this PR.

---
Full diff: https://github.com/llvm/llvm-project/pull/139528.diff


3 Files Affected:

- (modified) flang/lib/Semantics/check-omp-structure.cpp (-7) 
- (modified) flang/lib/Semantics/resolve-directives.cpp (+13) 
- (added) flang/test/Lower/OpenMP/flush-common.f90 (+13) 


``````````diff
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index f17de42ca2466..591f30db36baa 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2304,13 +2304,6 @@ void OmpStructureChecker::Leave(const parser::OpenMPFlushConstruct &x) {
   auto &flushList{std::get<std::optional<parser::OmpArgumentList>>(x.v.t)};
 
   if (flushList) {
-    for (const parser::OmpArgument &arg : flushList->v) {
-      if (auto *sym{GetArgumentSymbol(arg)}; sym && !IsVariableListItem(*sym)) {
-        context_.Say(arg.source,
-            "FLUSH argument must be a variable list item"_err_en_US);
-      }
-    }
-
     if (FindClause(llvm::omp::Clause::OMPC_acquire) ||
         FindClause(llvm::omp::Clause::OMPC_release) ||
         FindClause(llvm::omp::Clause::OMPC_acq_rel)) {
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 8b1caca34a6a7..68f8cf9f17620 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -409,6 +409,19 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
   }
   void Post(const parser::OpenMPDepobjConstruct &) { PopContext(); }
 
+  bool Pre(const parser::OpenMPFlushConstruct &x) {
+    PushContext(x.source, llvm::omp::Directive::OMPD_flush);
+    for (auto &arg : x.v.Arguments().v) {
+      if (auto *locator{std::get_if<parser::OmpLocator>(&arg.u)}) {
+        if (auto *object{std::get_if<parser::OmpObject>(&locator->u)}) {
+          ResolveOmpObject(*object, Symbol::Flag::OmpDependObject);
+        }
+      }
+    }
+    return true;
+  }
+  void Post(const parser::OpenMPFlushConstruct &) { PopContext(); }
+
   bool Pre(const parser::OpenMPRequiresConstruct &x) {
     using Flags = WithOmpDeclarative::RequiresFlags;
     using Requires = WithOmpDeclarative::RequiresFlag;
diff --git a/flang/test/Lower/OpenMP/flush-common.f90 b/flang/test/Lower/OpenMP/flush-common.f90
new file mode 100644
index 0000000000000..7656141dcb295
--- /dev/null
+++ b/flang/test/Lower/OpenMP/flush-common.f90
@@ -0,0 +1,13 @@
+! RUN: %flang_fc1 -fopenmp -emit-hlfir -o - %s | FileCheck %s
+
+! Regression test to ensure that the name /c/ in the flush argument list is
+! resolved to the common block symbol and common blocks are allowed in the
+! flush argument list.
+
+! CHECK: %[[GLBL:.*]] = fir.address_of({{.*}}) : !fir.ref<!fir.array<4xi8>>
+  common /c/ x
+  real :: x
+! CHECK: omp.flush(%[[GLBL]] : !fir.ref<!fir.array<4xi8>>)
+  !$omp flush(/c/)
+end
+

``````````

</details>


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


More information about the flang-commits mailing list