Skip to content

Commit c3afa79

Browse files
committed
[flang][openacc] Fix function name resolution in acc routine
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
1 parent 3dbabea commit c3afa79

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
265265
Symbol *ResolveAcc(const parser::Name &, Symbol::Flag, Scope &);
266266
Symbol *ResolveAcc(Symbol &, Symbol::Flag, Scope &);
267267
Symbol *ResolveName(const parser::Name &, bool parentScope = false);
268+
Symbol *ResolveFctName(const parser::Name &);
268269
Symbol *ResolveAccCommonBlockName(const parser::Name *);
269270
Symbol *DeclareOrMarkOtherAccessEntity(const parser::Name &, Symbol::Flag);
270271
Symbol *DeclareOrMarkOtherAccessEntity(Symbol &, Symbol::Flag);
@@ -835,6 +836,17 @@ Symbol *AccAttributeVisitor::ResolveName(
835836
return prev;
836837
}
837838

839+
Symbol *AccAttributeVisitor::ResolveFctName(const parser::Name &name) {
840+
Symbol *prev{currScope().FindSymbol(name.source)};
841+
if (!prev || (prev && prev->IsFuncResult())) {
842+
prev = currScope().parent().FindSymbol(name.source);
843+
}
844+
if (prev != name.symbol) {
845+
name.symbol = prev;
846+
}
847+
return prev;
848+
}
849+
838850
template <typename T>
839851
common::IfNoLvalue<T, T> FoldExpr(
840852
evaluate::FoldingContext &foldingContext, T &&expr) {
@@ -907,7 +919,7 @@ void AccAttributeVisitor::AddRoutineInfoToSymbol(
907919
bool AccAttributeVisitor::Pre(const parser::OpenACCRoutineConstruct &x) {
908920
const auto &optName{std::get<std::optional<parser::Name>>(x.t)};
909921
if (optName) {
910-
if (Symbol *sym = ResolveName(*optName, true)) {
922+
if (Symbol *sym = ResolveFctName(*optName)) {
911923
Symbol &ultimate{sym->GetUltimate()};
912924
AddRoutineInfoToSymbol(ultimate, x);
913925
} else {

flang/test/Lower/OpenACC/acc-routine.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

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

7071
! CHECK-LABEL: func.func @_QPacc_routine9() attributes {acc.routine_info = #acc.routine_info<[@acc_routine_8]>}
72+
73+
function acc_routine10()
74+
!$acc routine(acc_routine10) seq
75+
end function
76+
77+
! CHECK-LABEL: func.func @_QPacc_routine10() -> f32 attributes {acc.routine_info = #acc.routine_info<[@acc_routine_9]>}

0 commit comments

Comments
 (0)