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

--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Paul Thomas <[email protected]>:

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

commit r13-10233-gdcfd6d0e59b95b81498c28eae419b805fa8b3da8
Author: Christopher Albert <[email protected]>
Date:   Tue Mar 10 17:32:32 2026 +0100

    Fortran: Fix ICE on invalid CLASS component in derived type [PR106946]

    When a CLASS component declaration inside a derived type has a syntax
    error (for example, a missing comma), gfc_build_class_symbol creates a
    CLASS container symbol outside the undo mechanism.  Error recovery then
    frees the referenced type but leaves the CLASS container orphaned with
    dangling pointers, leading to an ICE during later resolution.

    Fix this by removing CLASS components created during a failed data
    declaration from the derived type component chain, deleting their
    namespace symtree entries only when they are still present, releasing
    the CLASS container symbol, and freeing the component itself.  Also
    expand the regression coverage to exercise allocatable and pointer CLASS
    declarations, including a valid component followed by a bad one.

    gcc/fortran/ChangeLog:

            PR fortran/106946
            * decl.cc (gfc_match_data_decl): Remove CLASS components added by a
            failed declaration in a derived type, and guard symtree deletion.
            * gfortran.h (gfc_free_component, gfc_delete_symtree): Declare.
            * symbol.cc (gfc_free_component): New function.
            (free_components): Use it.
            (gfc_delete_symtree): Make non-static.

    gcc/testsuite/ChangeLog:

            PR fortran/106946
            * gfortran.dg/pr106946.f90: Cover allocatable and pointer CLASS
            declarations, including a valid component followed by a bad one.

    Signed-off-by: Christopher Albert <[email protected]>
    (cherry picked from commit 0d0fbb0a01e4e77e274e0ff9b54506a495a7bdef)

Reply via email to