fortran: Fix ICE in ALLOCATE of sub-objects with recursive types
The deep-copy wrapper generation for recursive allocatable array
components (PR121628) calls cgraph_node::add_new_function to register
the wrapper. During PARSING state, add_new_function calls
finalize_function which triggers ggc_collect(). This garbage
collection frees locally-computed tree nodes (COMPONENT_REFs etc.)
in caller stack frames of structure_alloc_comps that are not yet
attached to any GC-rooted structure, causing a segfault when those
nodes are subsequently accessed.
Use finalize_function with no_collect=true to skip the collection.
The GC will run at a safe point later.
PR fortran/124235
gcc/fortran/ChangeLog:
* trans-array.cc (generate_element_copy_wrapper): Use
cgraph_node::finalize_function with no_collect=true instead
of cgraph_node::add_new_function to avoid garbage collection
while caller frames hold unrooted tree nodes.
gcc/testsuite/ChangeLog:
* gfortran.dg/pr124235.f90: New test.
Signed-off-by: Christopher Albert <albert@tugraz.at>
2 files changed