Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2303,9 +2303,15 @@ void OmpStructureChecker::Enter(const parser::OpenMPFlushConstruct &x) {
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kparzysz is this an issue with the function IsVariableListItem?

A variable list item is one of the following:
2 • a variable that is not coindexed and that is not a substring;
3 • an array section that is not coindexed and that does not contain an element that is a substring;
4 • a named constant;
5 • an associate name that may appear in a variable definition context; or
6 • a common block name (enclosed in slashes).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether the following is the correct fix here.

 bool OmpStructureChecker::IsVariableListItem(const Symbol &sym) {
-  return evaluate::IsVariable(sym) || sym.attrs().test(Attr::POINTER);
+  return evaluate::IsVariable(sym) || sym.attrs().test(Attr::POINTER) ||
+      sym.detailsIf<semantics::CommonBlockDetails>();
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My worry was whether that would affect many other constructs. Especially through this use:

void OmpStructureChecker::Enter(const parser::OmpClause &x)

Even if it is wrong that those constructs currently do not accept common blocks, it is unlikely that they will all generate correct code in this case.

if (auto *sym{GetArgumentSymbol(arg)};
sym && !isVariableListItemOrCommonBlock(*sym)) {
context_.Say(arg.source,
"FLUSH argument must be a variable list item"_err_en_US);
}
Expand Down
13 changes: 13 additions & 0 deletions flang/test/Lower/OpenMP/flush-common.f90
Original file line number Diff line number Diff line change
@@ -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

11 changes: 0 additions & 11 deletions flang/test/Semantics/OpenMP/flush04.f90

This file was deleted.