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

--- Comment #6 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:8de88fb84e77dcbc0e93b55f1f86564e35e47783

commit r17-6999-g8de88fb84e77dcbc0e93b55f1f86564e35e47783
Author: Jerry DeLisle <[email protected]>
Date:   Mon Nov 30 16:51:42 2026 -0800

    fortran: [PR128771] PDT initializer ICE and missing module default init

    gfc_get_pdt_instance commits a new PDT instance even when it is built
    during a statement match that is later rejected.  Since r17-3155 the
    charlens made while reducing the instance's component initializers
    stay on the undo list, so reject_statement freed them while the
    initializers still referenced them.  Take those charlens off the undo
    list once the instance is committed.

    The test case then failed at run time because module variables of PDT
    type got no default initialization: gfc_get_symbol_decl omits the
    static initializer of a PDT variable, which is instead initialized on
    entry to its scope, and a module has no such entry.  Keep the static
    initializer for module variables, unless the type has storage that
    depends on LEN parameters, which a static initializer cannot hold.

    Assisted-by: Claude Opus 5.5

            PR fortran/128771

    gcc/fortran/ChangeLog:

            * class.cc (pdt_len_component): Rename to...
            (gfc_pdt_len_component): ...this and make it extern.
            (comp_is_finalizable, generate_finalization_wrapper): Adjust
            calls.
            * decl.cc (gfc_get_pdt_instance): Remove the charlens created
            while building the instance from the undo list once it is
            committed.
            * gfortran.h (gfc_pdt_len_component): Declare.
            * trans-decl.cc (gfc_get_symbol_decl): Give module variables of
            PDT type a static initializer unless the type has storage that
            depends on LEN parameters.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/pr128771.f90: New test.
            * gfortran.dg/pr128771_2.f90: New test.
            * gfortran.dg/pr128771_3.f90: New test.

Reply via email to