Skip to content

Commit f87af71

Browse files
authored
[flang] Silence a bogus warning (#69799)
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.
1 parent 1c34450 commit f87af71

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4191,18 +4191,23 @@ bool SubprogramVisitor::HandlePreviousCalls(
41914191
// ENTRY's name. We have to replace that symbol in situ to avoid the
41924192
// obligation to rewrite symbol pointers in the parse tree.
41934193
if (!symbol.test(subpFlag)) {
4194+
auto other{subpFlag == Symbol::Flag::Subroutine
4195+
? Symbol::Flag::Function
4196+
: Symbol::Flag::Subroutine};
41944197
// External statements issue an explicit EXTERNAL attribute.
41954198
if (symbol.attrs().test(Attr::EXTERNAL) &&
41964199
!symbol.implicitAttrs().test(Attr::EXTERNAL)) {
41974200
// Warn if external statement previously declared.
41984201
Say(name,
41994202
"EXTERNAL attribute was already specified on '%s'"_warn_en_US);
4200-
} else {
4203+
} else if (symbol.test(other)) {
42014204
Say2(name,
42024205
subpFlag == Symbol::Flag::Function
42034206
? "'%s' was previously called as a subroutine"_err_en_US
42044207
: "'%s' was previously called as a function"_err_en_US,
42054208
symbol, "Previous call of '%s'"_en_US);
4209+
} else {
4210+
symbol.set(subpFlag);
42064211
}
42074212
}
42084213
EntityDetails entity;
@@ -8163,6 +8168,7 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
81638168
// Unknown target of procedure pointer must be an external procedure
81648169
Symbol &symbol{MakeSymbol(
81658170
context().globalScope(), name->source, Attrs{Attr::EXTERNAL})};
8171+
symbol.implicitAttrs().set(Attr::EXTERNAL);
81668172
Resolve(*name, symbol);
81678173
ConvertToProcEntity(symbol);
81688174
return false;

0 commit comments

Comments
 (0)