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

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Tue May 13 02:55:17 PDT 2025


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

>From 3e6d5c3cd14a9b688ec6e35a4bd4436fe944860b Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Mon, 12 May 2025 10:13:08 +0000
Subject: [PATCH] [flang][OpenMP] Allow flush of common block

I think this was denied by accident in 68180d8.

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 #139522. Ignore the first commit in this PR.
---
 flang/lib/Semantics/check-omp-structure.cpp |  7 -------
 flang/test/Lower/OpenMP/flush-common.f90    | 13 +++++++++++++
 flang/test/Semantics/OpenMP/flush04.f90     | 11 -----------
 3 files changed, 13 insertions(+), 18 deletions(-)
 create mode 100644 flang/test/Lower/OpenMP/flush-common.f90
 delete mode 100644 flang/test/Semantics/OpenMP/flush04.f90

diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 8f6a623508aa7..3e44ef5329ce2 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/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
+
diff --git a/flang/test/Semantics/OpenMP/flush04.f90 b/flang/test/Semantics/OpenMP/flush04.f90
deleted file mode 100644
index ffc2273b692dc..0000000000000
--- a/flang/test/Semantics/OpenMP/flush04.f90
+++ /dev/null
@@ -1,11 +0,0 @@
-! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
-
-! Regression test to ensure that the name /c/ in the flush argument list is
-! resolved to the common block symbol.
-
-  common /c/ x
-  real :: x
-!ERROR: FLUSH argument must be a variable list item
-  !$omp flush(/c/)
-end
-



More information about the flang-commits mailing list