Fixes a regression.

The master branch has been updated by Jerry DeLisle <[email protected]>:

https://gcc.gnu.org/g:0d0fbb0a01e4e77e274e0ff9b54506a495a7bdef

commit r16-8021-g0d0fbb0a01e4e77e274e0ff9b54506a495a7bdef
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]>

Reply via email to