Skip to content

Commit

Permalink
[flang] Support implicit global external as procedure pointer target
Browse files Browse the repository at this point in the history
A name that has been used to reference an undeclared global external
procedure should be accepted as the target of a procedure pointer
assignment statement.

Fixes llvm-test-suite/Fortran/gfortran/regression/proc_ptr_45.f90.

Differential Revision: https://reviews.llvm.org/D155963
  • Loading branch information
klausler committed Jul 21, 2023
1 parent f6026f6 commit ccd7895
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7519,8 +7519,9 @@ void ResolveNamesVisitor::HandleProcedureName(
currScope().context().GetPPCBuiltinsScope()) {
// Check if it is a builtin from the predefined module
symbol = FindSymbol(*ppcBuiltinScope, name);
if (!symbol)
if (!symbol) {
symbol = &MakeSymbol(context().globalScope(), name.source, Attrs{});
}
} else {
symbol = &MakeSymbol(context().globalScope(), name.source, Attrs{});
}
Expand Down Expand Up @@ -8030,6 +8031,15 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
}
return false;
}
// Can also reference a global external procedure here
if (auto it{context().globalScope().find(name->source)};
it != context().globalScope().end()) {
Symbol &global{*it->second};
if (IsProcedure(global)) {
Resolve(*name, global);
return false;
}
}
}
Walk(expr);
return false;
Expand Down
4 changes: 4 additions & 0 deletions flang/test/Semantics/assign09.f90
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ elemental real function userElemental(a)
!ERROR: Actual procedure argument has interface incompatible with dummy argument 'p=': incompatible dummy argument #1: incompatible dummy data object types: REAL(4) vs INTEGER(4)
call sub3(sqrt)

print *, implicitExtFunc()
call implicitExtSubr
noInterfaceProcPtr => implicitExtFunc ! ok
noInterfaceProcPtr => implicitExtSubr ! ok
noInterfaceProcPtr => noInterfaceExternal ! ok
realToRealProcPtr => noInterfaceExternal ! ok
intToRealProcPtr => noInterfaceExternal !ok
Expand Down

0 comments on commit ccd7895

Please sign in to comment.