https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124235

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jerry DeLisle <[email protected]>:

https://gcc.gnu.org/g:e0b70284cfac5b7a96f42e340b4c287fba7f8734

commit r16-7700-ge0b70284cfac5b7a96f42e340b4c287fba7f8734
Author: Christopher Albert <[email protected]>
Date:   Wed Feb 25 09:41:27 2026 +0100

    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 <[email protected]>

Reply via email to