[flang-commits] [flang] c3afa79 - [flang][openacc] Fix function name resolution in acc routine

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Fri Aug 25 14:27:46 PDT 2023


Author: Valentin Clement
Date: 2023-08-25T14:27:40-07:00
New Revision: c3afa7901d00ca438d64f189cac569938499d7e5

URL: https://github.com/llvm/llvm-project/commit/c3afa7901d00ca438d64f189cac569938499d7e5
DIFF: https://github.com/llvm/llvm-project/commit/c3afa7901d00ca438d64f189cac569938499d7e5.diff

LOG: [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

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-directives.cpp
    flang/test/Lower/OpenACC/acc-routine.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 44c6804756c1f3..83c44a556d19fd 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -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);
@@ -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) {
@@ -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 {

diff  --git a/flang/test/Lower/OpenACC/acc-routine.f90 b/flang/test/Lower/OpenACC/acc-routine.f90
index d37ac60e45e842..9736c48fcb739f 100644
--- a/flang/test/Lower/OpenACC/acc-routine.f90
+++ b/flang/test/Lower/OpenACC/acc-routine.f90
@@ -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)
@@ -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]>}


        


More information about the flang-commits mailing list