Skip to content

[flang] Silence bogus error on local proc pointer initializer #116663

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
Nov 20, 2024
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
12 changes: 7 additions & 5 deletions flang/lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,8 @@ void CheckHelper::CheckPointerInitialization(const Symbol &symbol) {
if (proc->init() && *proc->init()) {
// C1519 - must be nonelemental external or module procedure,
// or an unrestricted specific intrinsic function.
const Symbol &ultimate{(*proc->init())->GetUltimate()};
const Symbol &local{DEREF(*proc->init())};
const Symbol &ultimate{local.GetUltimate()};
bool checkTarget{true};
if (ultimate.attrs().test(Attr::INTRINSIC)) {
if (auto intrinsic{context_.intrinsics().IsSpecificIntrinsicFunction(
Expand All @@ -1123,11 +1124,12 @@ void CheckHelper::CheckPointerInitialization(const Symbol &symbol) {
ultimate.name(), symbol.name());
checkTarget = false;
}
} else if ((!ultimate.attrs().test(Attr::EXTERNAL) &&
ultimate.owner().kind() != Scope::Kind::Module) ||
} else if (!(ultimate.attrs().test(Attr::EXTERNAL) ||
ultimate.owner().kind() == Scope::Kind::Module ||
ultimate.owner().IsTopLevel()) ||
IsDummy(ultimate) || IsPointer(ultimate)) {
context_.Say("Procedure pointer '%s' initializer '%s' is neither "
"an external nor a module procedure"_err_en_US,
context_.Say(
"Procedure pointer '%s' initializer '%s' is neither an external nor a module procedure"_err_en_US,
symbol.name(), ultimate.name());
checkTarget = false;
} else if (IsElementalProcedure(ultimate)) {
Expand Down
53 changes: 53 additions & 0 deletions flang/test/Semantics/pointer02.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
recursive subroutine sub(dp, dpp)
procedure(inner) dp
procedure(inner), pointer :: dpp
procedure(inner) ext
procedure(sub), pointer :: p1 => sub ! ok
procedure(inner), pointer :: p2 => ext ! ok
!ERROR: Procedure pointer 'p3' initializer 'inner' is neither an external nor a module procedure
procedure(inner), pointer :: p3 => inner
!ERROR: Procedure pointer 'p4' initializer 'dp' is neither an external nor a module procedure
procedure(inner), pointer :: p4 => dp
!ERROR: Procedure pointer 'p5' initializer 'dpp' is neither an external nor a module procedure
procedure(inner), pointer :: p5 => dpp
generic :: generic => ext
!ERROR: 'generic' must be an abstract interface or a procedure with an explicit interface
procedure(generic), pointer :: p6 ! => generic
contains
subroutine inner
end
end
recursive function fun() result(res)
procedure(fun), pointer :: p1 => fun ! ok
!ERROR: Procedure pointer 'p2' initializer 'inner' is neither an external nor a module procedure
procedure(inner), pointer :: p2 => inner
res = 0.
contains
function inner()
inner = 0.
end
end
module m
procedure(msub), pointer :: ps1 => msub ! ok
procedure(mfun), pointer :: pf1 => mfun ! ok
contains
recursive subroutine msub
procedure(msub), pointer :: ps2 => msub ! ok
!ERROR: Procedure pointer 'ps3' initializer 'inner' is neither an external nor a module procedure
procedure(inner), pointer :: ps3 => inner
contains
subroutine inner
end
end
recursive function mfun() result(res)
procedure(mfun), pointer :: pf2 => mfun ! ok
!ERROR: Procedure pointer 'pf3' initializer 'inner' is neither an external nor a module procedure
procedure(inner), pointer :: pf3 => inner
res = 0.
contains
function inner()
inner = 0.
end
end
end
Loading