Skip to content

Commit a647510

Browse files
committed
[flang][OpenMP][Semantics] resolve objects in the flush arg list
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.
1 parent 358ebdd commit a647510

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,19 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
409409
}
410410
void Post(const parser::OpenMPDepobjConstruct &) { PopContext(); }
411411

412+
bool Pre(const parser::OpenMPFlushConstruct &x) {
413+
PushContext(x.source, llvm::omp::Directive::OMPD_flush);
414+
for (auto &arg : x.v.Arguments().v) {
415+
if (auto *locator{std::get_if<parser::OmpLocator>(&arg.u)}) {
416+
if (auto *object{std::get_if<parser::OmpObject>(&locator->u)}) {
417+
ResolveOmpObject(*object, Symbol::Flag::OmpDependObject);
418+
}
419+
}
420+
}
421+
return true;
422+
}
423+
void Post(const parser::OpenMPFlushConstruct &) { PopContext(); }
424+
412425
bool Pre(const parser::OpenMPRequiresConstruct &x) {
413426
using Flags = WithOmpDeclarative::RequiresFlags;
414427
using Requires = WithOmpDeclarative::RequiresFlag;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
3+
! Regression test to ensure that the name /c/ in the flush argument list is
4+
! resolved to the common block symbol.
5+
6+
common /c/ x
7+
real :: x
8+
!ERROR: FLUSH argument must be a variable list item
9+
!$omp flush(/c/)
10+
end
11+

0 commit comments

Comments
 (0)