Skip to content

[flang] Check for ultimate ALLOCATABLE component in LOCAL_INIT() #145800

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 9 commits into from
Jun 30, 2025
8 changes: 8 additions & 0 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7278,6 +7278,14 @@ bool DeclarationVisitor::PassesLocalityChecks(
specName);
return false;
}
if (const DerivedTypeSpec *derived{type->AsDerived()}) { // F'2023 C1130
if (auto bad{FindAllocatableUltimateComponent(*derived)}) {
SayWithDecl(name, symbol,
"Derived type variable '%s' with ultimate ALLOCATABLE component '%s' not allowed in a %s locality-spec"_err_en_US,
bad.BuildResultDesignatorName(), specName);
return false;
}
}
}
if (symbol.attrs().test(Attr::ASYNCHRONOUS) && isReduce) { // F'2023 C1131
SayWithDecl(name, symbol,
Expand Down
20 changes: 20 additions & 0 deletions flang/test/Semantics/resolve55.f90
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,23 @@ subroutine s8(arg)
do concurrent(i=1:5) local(arg)
end do
end subroutine s8

subroutine s9()
type l3
integer, allocatable :: a
end type
type l2
type(l3) :: l2_3
end type
type l1
type(l2) :: l1_2
end type
type(l1) :: v
integer sum

sum = 0
!ERROR: Derived type variable 'v' with ultimate ALLOCATABLE component '%l1_2%l2_3%a' not allowed in a LOCAL_INIT locality-spec
do concurrent (i = 1:10) local_init(v)
sum = sum + i
end do
end subroutine s9