https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125532
Bug ID: 125532
Summary: Wrong-code in DO CONCURRENT when ASSOCIATE body
references inline type-spec iterator
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: jvdelisle at gcc dot gnu.org
Target Milestone: ---
When a DO CONCURRENT loop uses inline type-spec iterators (e.g. integer :: k =
1:n) and the loop body contains an ASSOCIATE construct that references the
iterator, the program segfaults at runtime.
The iterator variable is represented internally with a leading underscore (_k).
After lowering, the shadow name must be replaced by the user-visible name
throughout the loop body, but the replacement walk skipped ASSOCIATE constructs
entirely, leaving stale shadow references in the generated code.
program test
implicit none
integer, parameter :: n = 5
integer :: a(n), b(n), k
a = [(k, k = 1, n)]
b = 0
do concurrent (integer :: k = 1:n)
associate (val => a(k))
b(k) = val * 2
end associate
end do
if (any (b /= [2, 4, 6, 8, 10])) stop 1
end program
$ gfortran -std=f2018 do_concurrent_assoc_shadow.f90 && ./a.out
The program segfaults because the iterator k in the
ASSOCIATE selector and body is not correctly substituted,
leaving dangling shadow references in the generated code.
The program should run and exit cleanly.