Skip to content

Commit

Permalink
[flang] Silence a bogus warning (#69799)
Browse files Browse the repository at this point in the history
A recent fix (#66232) to
interpret a hitherto unknown name whose first appearance is as the
target of a procedure pointer initializer as an external procedure has
led to some inapproprite warning messages if the name is later defined
as an external subroutine ("X was already declared as an external").

Ensure that the EXTERNAL attribute is correctly noted as being implicit,
and that it's okay that neither the Subroutine nor Function flag has yet
been set for the implicit external.
  • Loading branch information
klausler committed Oct 31, 2023
1 parent 1c34450 commit f87af71
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4191,18 +4191,23 @@ bool SubprogramVisitor::HandlePreviousCalls(
// ENTRY's name. We have to replace that symbol in situ to avoid the
// obligation to rewrite symbol pointers in the parse tree.
if (!symbol.test(subpFlag)) {
auto other{subpFlag == Symbol::Flag::Subroutine
? Symbol::Flag::Function
: Symbol::Flag::Subroutine};
// External statements issue an explicit EXTERNAL attribute.
if (symbol.attrs().test(Attr::EXTERNAL) &&
!symbol.implicitAttrs().test(Attr::EXTERNAL)) {
// Warn if external statement previously declared.
Say(name,
"EXTERNAL attribute was already specified on '%s'"_warn_en_US);
} else {
} else if (symbol.test(other)) {
Say2(name,
subpFlag == Symbol::Flag::Function
? "'%s' was previously called as a subroutine"_err_en_US
: "'%s' was previously called as a function"_err_en_US,
symbol, "Previous call of '%s'"_en_US);
} else {
symbol.set(subpFlag);
}
}
EntityDetails entity;
Expand Down Expand Up @@ -8163,6 +8168,7 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
// Unknown target of procedure pointer must be an external procedure
Symbol &symbol{MakeSymbol(
context().globalScope(), name->source, Attrs{Attr::EXTERNAL})};
symbol.implicitAttrs().set(Attr::EXTERNAL);
Resolve(*name, symbol);
ConvertToProcEntity(symbol);
return false;
Expand Down

0 comments on commit f87af71

Please sign in to comment.