Skip to content

Commit 8ecb958

Browse files
authored
[flang][OpenMP][Semantics] resolve objects in the flush arg list (#139522)
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 83ce8a4 commit 8ecb958

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,26 @@ 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+
if (auto *name{std::get_if<parser::Name>(&object->u)}) {
418+
// ResolveOmpCommonBlockName resolves the symbol as a side effect
419+
if (!ResolveOmpCommonBlockName(name)) {
420+
context_.Say(name->source, // 2.15.3
421+
"COMMON block must be declared in the same scoping unit "
422+
"in which the OpenMP directive or clause appears"_err_en_US);
423+
}
424+
}
425+
}
426+
}
427+
}
428+
return true;
429+
}
430+
void Post(const parser::OpenMPFlushConstruct &) { PopContext(); }
431+
412432
bool Pre(const parser::OpenMPRequiresConstruct &x) {
413433
using Flags = WithOmpDeclarative::RequiresFlags;
414434
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)