Skip to content

Commit eb6ec17

Browse files
authored
[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.
1 parent 3d89c08 commit eb6ec17

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,10 @@ Symbol *AccAttributeVisitor::ResolveFctName(const parser::Name &name) {
913913
Symbol *prev{currScope().FindSymbol(name.source)};
914914
if (!prev || (prev && prev->IsFuncResult())) {
915915
prev = currScope().parent().FindSymbol(name.source);
916+
if (!prev) {
917+
prev = &context_.globalScope().MakeSymbol(
918+
name.source, Attrs{}, ProcEntityDetails{});
919+
}
916920
}
917921
if (prev != name.symbol) {
918922
name.symbol = prev;
@@ -965,7 +969,7 @@ void AccAttributeVisitor::AddRoutineInfoToSymbol(
965969
std::get_if<Fortran::parser::AccClause::Bind>(&clause.u)) {
966970
if (const auto *name =
967971
std::get_if<Fortran::parser::Name>(&bindClause->v.u)) {
968-
if (Symbol *sym = ResolveName(*name, true)) {
972+
if (Symbol *sym = ResolveFctName(*name)) {
969973
info.set_bindName(sym->name().ToString());
970974
} else {
971975
context_.Say((*name).source,
@@ -1008,7 +1012,7 @@ bool AccAttributeVisitor::Pre(const parser::OpenACCRoutineConstruct &x) {
10081012

10091013
bool AccAttributeVisitor::Pre(const parser::AccBindClause &x) {
10101014
if (const auto *name{std::get_if<parser::Name>(&x.u)}) {
1011-
if (!ResolveName(*name, true)) {
1015+
if (!ResolveFctName(*name)) {
10121016
context_.Say(name->source,
10131017
"No function or subroutine declared for '%s'"_err_en_US,
10141018
name->source);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,14 @@ subroutine acc_routine11(a)
9696
end interface
9797

9898
end subroutine
99+
100+
subroutine acc_routine13()
101+
!$acc routine bind(acc_routine14)
102+
end subroutine
103+
104+
subroutine acc_routine14()
105+
end subroutine
106+
107+
subroutine acc_routine15()
108+
!$acc routine bind(acc_routine16)
109+
end subroutine

flang/test/Semantics/OpenACC/acc-routine-validity.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module openacc_routine_validity
1515
!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
1616
!$acc routine seq
1717

18-
!ERROR: No function or subroutine declared for 'dummy'
1918
!$acc routine(dummy) seq
2019

2120
contains
@@ -70,7 +69,6 @@ end function fct4
7069

7170
subroutine sub6(a)
7271
real :: a(:)
73-
!ERROR: No function or subroutine declared for 'dummy_sub'
7472
!$acc routine seq bind(dummy_sub)
7573
end subroutine sub6
7674

0 commit comments

Comments
 (0)