Skip to content

[flang] Catch non-constant targets for procedure pointer initialization #86338

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
Mar 26, 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
10 changes: 7 additions & 3 deletions flang/lib/Evaluate/check-expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,14 @@ bool IsInitialProcedureTarget(const semantics::Symbol &symbol) {
const auto &ultimate{symbol.GetUltimate()};
return common::visit(
common::visitors{
[](const semantics::SubprogramDetails &subp) {
return !subp.isDummy();
[&](const semantics::SubprogramDetails &subp) {
return !subp.isDummy() && !subp.stmtFunction() &&
symbol.owner().kind() != semantics::Scope::Kind::MainProgram &&
symbol.owner().kind() != semantics::Scope::Kind::Subprogram;
},
[](const semantics::SubprogramNameDetails &x) {
return x.kind() != semantics::SubprogramKind::Internal;
},
[](const semantics::SubprogramNameDetails &) { return true; },
[&](const semantics::ProcEntityDetails &proc) {
return !semantics::IsPointer(ultimate) && !proc.isDummy();
},
Expand Down
37 changes: 37 additions & 0 deletions flang/test/Semantics/structconst09.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
! Structure constructors with bad pointer targets
module m
real, target, save :: x
type t
real, pointer :: rp => x
procedure(f), pointer, nopass :: pp => f
end type
contains
real function f()
f = 0.
end
subroutine test(da, dp)
real, target :: y, da
procedure(f) dp
procedure(f), pointer :: lpp
external ext
type(t) :: a1 = t() ! ok
type(t) :: a2 = t(rp=x) ! ok
type(t) :: a3 = t(pp=f) ! ok
type(t) :: a4 = t(pp=ext) ! ok
!ERROR: Must be a constant value
type(t) :: a5 = t(rp=y)
!ERROR: Must be a constant value
type(t) :: a6 = t(rp=da)
!ERROR: Must be a constant value
type(t) :: a7 = t(pp=lpp)
!ERROR: Must be a constant value
type(t) :: a8 = t(pp=internal)
!ERROR: Must be a constant value
type(t) :: a9 = t(pp=dp)
contains
real function internal()
internal = 666.
end
end
end