Skip to content

Commit

Permalink
[flang] Allow forward reference to ENTRY from generic interface
Browse files Browse the repository at this point in the history
The CreateEntry() function in name resolution needs to allow for the name
of an alternate entry point already having been declared in the outer scope
as the homonymous specific procedure of a generic interface; e.g.,

  interface foo
    module procedure foo
  end interface
  subroutine bar
    entry foo
  end subroutine

Differential Revision: https://reviews.llvm.org/D126436
  • Loading branch information
klausler committed May 26, 2022
1 parent 949c39e commit ddd692e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions flang/lib/Semantics/resolve-names.cpp
Expand Up @@ -3411,10 +3411,21 @@ void SubprogramVisitor::CreateEntry(
if (outer.IsModule() && !attrs.test(Attr::PRIVATE)) {
attrs.set(Attr::PUBLIC);
}
Symbol &entrySymbol{MakeSymbol(outer, entryName.source, attrs)};
Symbol *entrySymbol{FindInScope(outer, entryName.source)};
if (entrySymbol) {
if (auto *generic{entrySymbol->detailsIf<GenericDetails>()}) {
if (auto *specific{generic->specific()}) {
// Forward reference to ENTRY from a generic interface
entrySymbol = specific;
entrySymbol->attrs() |= attrs;
}
}
} else {
entrySymbol = &MakeSymbol(outer, entryName.source, attrs);
}
SubprogramDetails entryDetails;
entryDetails.set_entryScope(currScope());
entrySymbol.set(subpFlag);
entrySymbol->set(subpFlag);
if (subpFlag == Symbol::Flag::Function) {
Symbol *result{nullptr};
EntityDetails resultDetails;
Expand Down Expand Up @@ -3443,11 +3454,12 @@ void SubprogramVisitor::CreateEntry(
if (subpFlag == Symbol::Flag::Subroutine ||
(distinctResultName && !badResultName)) {
Symbol &assoc{MakeSymbol(entryName.source)};
assoc.set_details(HostAssocDetails{entrySymbol});
assoc.set_details(HostAssocDetails{*entrySymbol});
assoc.set(Symbol::Flag::Subroutine);
}
Resolve(entryName, entrySymbol);
entrySymbol.set_details(std::move(entryDetails));
Resolve(entryName, *entrySymbol);
Details details{std::move(entryDetails)};
entrySymbol->set_details(std::move(entryDetails));
}

void SubprogramVisitor::PostEntryStmt(const parser::EntryStmt &stmt) {
Expand Down

0 comments on commit ddd692e

Please sign in to comment.