Skip to content

Commit

Permalink
[flang][openacc] Fix name resolution for fct name in acc routine
Browse files Browse the repository at this point in the history
Name resolution was failing when the routine name is
a function/subroutine in the parent scope.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D154002
  • Loading branch information
clementval committed Jun 29, 2023
1 parent 6bf66d8 commit 45c97af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
void ResolveAccObject(const parser::AccObject &, Symbol::Flag);
Symbol *ResolveAcc(const parser::Name &, Symbol::Flag, Scope &);
Symbol *ResolveAcc(Symbol &, Symbol::Flag, Scope &);
Symbol *ResolveName(const parser::Name &);
Symbol *ResolveName(const parser::Name &, bool parentScope = false);
Symbol *ResolveAccCommonBlockName(const parser::Name *);
Symbol *DeclareOrMarkOtherAccessEntity(const parser::Name &, Symbol::Flag);
Symbol *DeclareOrMarkOtherAccessEntity(Symbol &, Symbol::Flag);
Expand Down Expand Up @@ -790,8 +790,13 @@ bool AccAttributeVisitor::Pre(const parser::OpenACCStandaloneConstruct &x) {
return true;
}

Symbol *AccAttributeVisitor::ResolveName(const parser::Name &name) {
Symbol *AccAttributeVisitor::ResolveName(
const parser::Name &name, bool parentScope) {
Symbol *prev{currScope().FindSymbol(name.source)};
// Check in parent scope if asked for.
if (!prev && parentScope) {
prev = currScope().parent().FindSymbol(name.source);
}
if (prev != name.symbol) {
name.symbol = prev;
}
Expand All @@ -801,7 +806,7 @@ Symbol *AccAttributeVisitor::ResolveName(const parser::Name &name) {
bool AccAttributeVisitor::Pre(const parser::OpenACCRoutineConstruct &x) {
const auto &optName{std::get<std::optional<parser::Name>>(x.t)};
if (optName) {
if (!ResolveName(*optName)) {
if (!ResolveName(*optName, true)) {
context_.Say((*optName).source,
"No function or subroutine declared for '%s'"_err_en_US,
(*optName).source);
Expand Down
11 changes: 11 additions & 0 deletions flang/test/Semantics/OpenACC/acc-routine.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenacc

subroutine sub1(a)
real, dimension(10) :: a
end subroutine

subroutine sub2(a)
!$acc routine(sub1) gang(dim:1)
real, dimension(10) :: a
call sub1(a)
end subroutine

0 comments on commit 45c97af

Please sign in to comment.