Skip to content

Commit

Permalink
[flang][openacc] Fix function name resolution in acc routine
Browse files Browse the repository at this point in the history
When acc routine is in a function, the first symbol resolved
was the function result and not the function name itself. It was
then failing the deferred attachment because the mangled name
had the entity attach to it. This patch fix the name resolution
for the function name in acc routine directive.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158868
  • Loading branch information
clementval committed Aug 25, 2023
1 parent 3dbabea commit c3afa79
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
Symbol *ResolveAcc(const parser::Name &, Symbol::Flag, Scope &);
Symbol *ResolveAcc(Symbol &, Symbol::Flag, Scope &);
Symbol *ResolveName(const parser::Name &, bool parentScope = false);
Symbol *ResolveFctName(const parser::Name &);
Symbol *ResolveAccCommonBlockName(const parser::Name *);
Symbol *DeclareOrMarkOtherAccessEntity(const parser::Name &, Symbol::Flag);
Symbol *DeclareOrMarkOtherAccessEntity(Symbol &, Symbol::Flag);
Expand Down Expand Up @@ -835,6 +836,17 @@ Symbol *AccAttributeVisitor::ResolveName(
return prev;
}

Symbol *AccAttributeVisitor::ResolveFctName(const parser::Name &name) {
Symbol *prev{currScope().FindSymbol(name.source)};
if (!prev || (prev && prev->IsFuncResult())) {
prev = currScope().parent().FindSymbol(name.source);
}
if (prev != name.symbol) {
name.symbol = prev;
}
return prev;
}

template <typename T>
common::IfNoLvalue<T, T> FoldExpr(
evaluate::FoldingContext &foldingContext, T &&expr) {
Expand Down Expand Up @@ -907,7 +919,7 @@ void AccAttributeVisitor::AddRoutineInfoToSymbol(
bool AccAttributeVisitor::Pre(const parser::OpenACCRoutineConstruct &x) {
const auto &optName{std::get<std::optional<parser::Name>>(x.t)};
if (optName) {
if (Symbol *sym = ResolveName(*optName, true)) {
if (Symbol *sym = ResolveFctName(*optName)) {
Symbol &ultimate{sym->GetUltimate()};
AddRoutineInfoToSymbol(ultimate, x);
} else {
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Lower/OpenACC/acc-routine.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s

! CHECK: acc.routine @acc_routine_9 func(@_QPacc_routine10) seq
! CHECK: acc.routine @acc_routine_8 func(@_QPacc_routine9) bind("_QPacc_routine9a")
! CHECK: acc.routine @acc_routine_7 func(@_QPacc_routine8) bind("routine8_")
! CHECK: acc.routine @acc_routine_6 func(@_QPacc_routine7) gang(dim = 1 : i32)
Expand Down Expand Up @@ -68,3 +69,9 @@ subroutine acc_routine9()
end subroutine

! CHECK-LABEL: func.func @_QPacc_routine9() attributes {acc.routine_info = #acc.routine_info<[@acc_routine_8]>}

function acc_routine10()
!$acc routine(acc_routine10) seq
end function

! CHECK-LABEL: func.func @_QPacc_routine10() -> f32 attributes {acc.routine_info = #acc.routine_info<[@acc_routine_9]>}

0 comments on commit c3afa79

Please sign in to comment.