[flang-commits] [flang] eb6ec17 - [flang][openacc] Do not error when bind symbol is defined later or external (#69657)

via flang-commits flang-commits at lists.llvm.org
Thu Oct 19 17:25:10 PDT 2023


Author: Valentin Clement (バレンタイン クレメン)
Date: 2023-10-19T17:25:05-07:00
New Revision: eb6ec1720628cb55677dd0db8d4ee75c43f37514

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

LOG: [flang][openacc] Do not error when bind symbol is defined later or external (#69657)

The symbol in bind clause on acc routine refers to a function or a
subroutine. This patch avoids to raise error when the function or
subroutine is declared later in the code or is external. This is in line
with normal procedure name resolution in Fortran code.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index e8448a36a7b273c..f7720fcf43e5768 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -913,6 +913,10 @@ 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) {
+      prev = &context_.globalScope().MakeSymbol(
+          name.source, Attrs{}, ProcEntityDetails{});
+    }
   }
   if (prev != name.symbol) {
     name.symbol = prev;
@@ -965,7 +969,7 @@ void AccAttributeVisitor::AddRoutineInfoToSymbol(
                      std::get_if<Fortran::parser::AccClause::Bind>(&clause.u)) {
         if (const auto *name =
                 std::get_if<Fortran::parser::Name>(&bindClause->v.u)) {
-          if (Symbol *sym = ResolveName(*name, true)) {
+          if (Symbol *sym = ResolveFctName(*name)) {
             info.set_bindName(sym->name().ToString());
           } else {
             context_.Say((*name).source,
@@ -1008,7 +1012,7 @@ bool AccAttributeVisitor::Pre(const parser::OpenACCRoutineConstruct &x) {
 
 bool AccAttributeVisitor::Pre(const parser::AccBindClause &x) {
   if (const auto *name{std::get_if<parser::Name>(&x.u)}) {
-    if (!ResolveName(*name, true)) {
+    if (!ResolveFctName(*name)) {
       context_.Say(name->source,
           "No function or subroutine declared for '%s'"_err_en_US,
           name->source);

diff  --git a/flang/test/Lower/OpenACC/acc-routine.f90 b/flang/test/Lower/OpenACC/acc-routine.f90
index 7514e0a8819fae9..ffa889730918f9c 100644
--- a/flang/test/Lower/OpenACC/acc-routine.f90
+++ b/flang/test/Lower/OpenACC/acc-routine.f90
@@ -96,3 +96,14 @@ subroutine acc_routine11(a)
   end interface
 
 end subroutine
+
+subroutine acc_routine13()
+  !$acc routine bind(acc_routine14)
+end subroutine
+
+subroutine acc_routine14()
+end subroutine
+
+subroutine acc_routine15()
+  !$acc routine bind(acc_routine16)
+end subroutine

diff  --git a/flang/test/Semantics/OpenACC/acc-routine-validity.f90 b/flang/test/Semantics/OpenACC/acc-routine-validity.f90
index 5b8ecdec4f5267f..c135c2b86aac12c 100644
--- a/flang/test/Semantics/OpenACC/acc-routine-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-routine-validity.f90
@@ -15,7 +15,6 @@ module openacc_routine_validity
   !ERROR: ROUTINE directive without name must appear within the specification part of a subroutine or function definition, or within an interface body for a subroutine or function in an interface block
   !$acc routine seq
 
-  !ERROR: No function or subroutine declared for 'dummy'
   !$acc routine(dummy) seq
 
 contains
@@ -70,7 +69,6 @@ end function fct4
 
   subroutine sub6(a)
     real :: a(:)
-    !ERROR: No function or subroutine declared for 'dummy_sub'
     !$acc routine seq bind(dummy_sub)
   end subroutine sub6
 


        


More information about the flang-commits mailing list