Commit b5a3b87
Jerry DeLisle
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.1 parent 81a0bec commit b5a3b87
2 files changed
Lines changed: 44 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9069 | 9069 | | |
9070 | 9070 | | |
9071 | 9071 | | |
9072 | | - | |
9073 | | - | |
9074 | 9072 | | |
9075 | | - | |
9076 | | - | |
9077 | | - | |
| 9073 | + | |
| 9074 | + | |
| 9075 | + | |
9078 | 9076 | | |
9079 | 9077 | | |
9080 | 9078 | | |
| |||
9102 | 9100 | | |
9103 | 9101 | | |
9104 | 9102 | | |
| 9103 | + | |
| 9104 | + | |
9105 | 9105 | | |
9106 | 9106 | | |
9107 | 9107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
0 commit comments