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

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.
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 5ae4bc2..c6c4fdf 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2303,9 +2303,15 @@
 void OmpStructureChecker::Leave(const parser::OpenMPFlushConstruct &x) {
   auto &flushList{std::get<std::optional<parser::OmpArgumentList>>(x.v.t)};
 
+  auto isVariableListItemOrCommonBlock{[this](const Symbol &sym) {
+    return IsVariableListItem(sym) ||
+        sym.detailsIf<semantics::CommonBlockDetails>();
+  }};
+
   if (flushList) {
     for (const parser::OmpArgument &arg : flushList->v) {
-      if (auto *sym{GetArgumentSymbol(arg)}; sym && !IsVariableListItem(*sym)) {
+      if (auto *sym{GetArgumentSymbol(arg)};
+          sym && !isVariableListItemOrCommonBlock(*sym)) {
         context_.Say(arg.source,
             "FLUSH argument must be a variable list item"_err_en_US);
       }
diff --git a/flang/test/Lower/OpenMP/flush-common.f90 b/flang/test/Lower/OpenMP/flush-common.f90
new file mode 100644
index 0000000..7656141
--- /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 ffc2273..0000000
--- 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
-