gnu/gcc/b5a3b874b8df2ea2ca82bd97fcd5906f7ebe82d8 fortran: [PR125535] wrong-code for implied-do with allocatable-component
When a nested implied-do array constructor called a transformational
intrinsic (e.g. RESHAPE) whose result type has allocatable components, the
argument temporaries were freed before the result's allocatable components
were deep-copied, causing a heap-use-after-free and wrong runtime values.
Transformational library functions such as RESHAPE do a shallow byte-copy
of the source array into the result, so the result's component pointers
alias those of the argument temporaries. Freeing the temporaries first
and then copying yielded use-after-free.
Move gfc_add_block_to_block (&se->pre, &post) to after the deep-copy
loop, so that the result's allocatable components are copied while the
source storage is still live.
Assisted by: Claude Sonnet 4.6
PR fortran/125535
gcc/fortran/ChangeLog:
* trans-expr.cc (gfc_conv_procedure_call): Move post block append
to after the deep copy of allocatable components for transformational
intrinsics, so that argument temporaries are not freed before the
result components are copied.
gcc/testsuite/ChangeLog:
* gfortran.dg/implied_do_alloc_comp_1.f90: New test.
2 files changed