Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions flang/test/Lower/OpenACC/acc-routine.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions flang/test/Semantics/OpenACC/acc-routine-validity.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down