[flang-commits] [flang] 45c97af - [flang][openacc] Fix name resolution for fct name in acc routine

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Thu Jun 29 09:05:56 PDT 2023


Author: Valentin Clement
Date: 2023-06-29T09:05:50-07:00
New Revision: 45c97af55ed62189a43508abf86137eb64b302d3

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

LOG: [flang][openacc] Fix name resolution for fct name in acc routine

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

Added: 
    flang/test/Semantics/OpenACC/acc-routine.f90

Modified: 
    flang/lib/Semantics/resolve-directives.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 169e7099aae9b9..4b0892a5760cac 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -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);
@@ -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;
   }
@@ -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);

diff  --git a/flang/test/Semantics/OpenACC/acc-routine.f90 b/flang/test/Semantics/OpenACC/acc-routine.f90
new file mode 100644
index 00000000000000..f6176dd9c2f3e8
--- /dev/null
+++ b/flang/test/Semantics/OpenACC/acc-routine.f90
@@ -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


        


More information about the flang-commits mailing list