diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp index 8b1caca34a6a7..e34c48c1983ca 100644 --- a/flang/lib/Semantics/resolve-directives.cpp +++ b/flang/lib/Semantics/resolve-directives.cpp @@ -409,6 +409,26 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor { } 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(&arg.u)}) { + if (auto *object{std::get_if(&locator->u)}) { + if (auto *name{std::get_if(&object->u)}) { + // ResolveOmpCommonBlockName resolves the symbol as a side effect + if (!ResolveOmpCommonBlockName(name)) { + context_.Say(name->source, // 2.15.3 + "COMMON block must be declared in the same scoping unit " + "in which the OpenMP directive or clause appears"_err_en_US); + } + } + } + } + } + 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 +