Skip to content

[flang][OpenMP][Semantics] resolve objects in the flush arg list #139522

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 13, 2025

Conversation

tblah
Copy link
Contributor

@tblah tblah commented May 12, 2025

Fixes #136583

Normally the flush argument list would contain a DataRef to some variable. All DataRefs are handled generically in resolve-names and so the problem wasn't observed. But when a common block name is specified, this is not parsed as a DataRef. There was already handling in resolve-directives for OmpObjectList but not for argument lists. I've added a visitor for FLUSH which ensures all of the arguments have been resolved.

The test is there to make sure the compiler doesn't crashed encountering the unresolved symbol. It shows that we currently deny flushing a common block. I'm not sure that it is right to restrict common blocks from flush argument lists, but fixing that can come in a different patch. This one is fixing an ICE.

Fixes llvm#136583

Normally the flush argument list would contain a DataRef to some
variable. All DataRefs are handled generically in resolve-names and so
the problem wasn't observed. But when a common block name is specified,
this is not parsed as a DataRef. There was already handling in
resolve-directives for OmpObjectList but not for argument lists. I've
added a visitor for FLUSH which ensures all of the arguments have been
resolved.

The test is there to make sure the compiler doesn't crashed encountering
the unresolved symbol. It shows that we currently deny flushing a common
block. I'm not sure that it is right to restrict common blocks from flush
argument lists, but fixing that can come in a different patch. This one
is fixing an ICE.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels May 12, 2025
@llvmbot
Copy link
Member

llvmbot commented May 12, 2025

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-semantics

Author: Tom Eccles (tblah)

Changes

Fixes #136583

Normally the flush argument list would contain a DataRef to some variable. All DataRefs are handled generically in resolve-names and so the problem wasn't observed. But when a common block name is specified, this is not parsed as a DataRef. There was already handling in resolve-directives for OmpObjectList but not for argument lists. I've added a visitor for FLUSH which ensures all of the arguments have been resolved.

The test is there to make sure the compiler doesn't crashed encountering the unresolved symbol. It shows that we currently deny flushing a common block. I'm not sure that it is right to restrict common blocks from flush argument lists, but fixing that can come in a different patch. This one is fixing an ICE.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+13)
  • (added) flang/test/Semantics/OpenMP/flush04.f90 (+11)
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/Semantics/OpenMP/flush04.f90 b/flang/test/Semantics/OpenMP/flush04.f90
new file mode 100644
index 0000000000000..ffc2273b692dc
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/flush04.f90
@@ -0,0 +1,11 @@
+! 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
+

tblah added a commit to tblah/llvm-project that referenced this pull request May 12, 2025
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 llvm#139522. Ignore the first commit in this PR.
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming this is a copy paste error. This is not a DependObject, so I think adding the Symbol::Flag::OmpDependObject is probably not right.

What do we want to do here? Is it just resolving the names in the flush argument list to the appropriate Fortran declarations? If so, we should use ResolveName.

Copy link
Contributor

Choose a reason for hiding this comment

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

If common blocks are not handled in ResolveName then you can probably use OmpFlushed as the Symbol in ResolveOmpObject.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it was a copy and paste error. Thanks for catching this.

I had assumed that given an object, the right way to resolve it was to call ResolveOmpObject. I have now changed to include only the relevant parts of the code inline.

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

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

LG.

Note: There is a CI failure.

@tblah
Copy link
Contributor Author

tblah commented May 13, 2025

The CI failure looks unrelated. Thanks for the quick review.

@tblah tblah merged commit 8ecb958 into llvm:main May 13, 2025
9 of 11 checks passed
tblah added a commit to tblah/llvm-project that referenced this pull request May 13, 2025
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 llvm#139522. Ignore the first commit in this PR.
tblah added a commit that referenced this pull request May 19, 2025
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.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request May 19, 2025
I think this was denied by accident in
llvm/llvm-project@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 llvm/llvm-project#139522. Ignore
the first commit in this PR.
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 6, 2025
I think this was denied by accident in
llvm@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 llvm#139522. Ignore
the first commit in this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:openmp flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang] [OpenMP] Common block name symbol is not found (with the prefix "Internal")
3 participants