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

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

https://gcc.gnu.org/g:303400bda9e33622ab24ff3c1f82866577fc7351

commit r17-6306-g303400bda9e33622ab24ff3c1f82866577fc7351
Author: Jerry DeLisle <[email protected]>
Date:   Tue Nov 3 09:09:33 2026 -0800

    fortran: [PR82173] Free LEN components of PDTs in CLASS(*) objects

    Deallocating an unlimited polymorphic object that holds a PDT freed the
    object but not its LEN-dependent array and string components, because
    the PDT's vtab had no finalization wrapper.  Polymorphic assignment from
    a structure constructor also leaked the constructor temporary's
    components after their deep copy, for PDTs and for types with
    allocatable components alike.

    Treat LEN-dependent PDT components as finalizable so that the wrapper
    is generated and frees them, and free the components of a structure
    constructor temporary after a polymorphic assignment.  pdt_bug9.f90
    leaked; its REAL(16) cases move to pdt_bug9a.f90.

    Assisted-by: Claude Opus 5.5

    2026-11-16  Jerry DeLisle <[email protected]>

            PR fortran/82173

    gcc/fortran/ChangeLog:

            * class.cc (pdt_len_component, pdt_len_storage_comp): New
            functions.
            (comp_is_finalizable): Treat LEN-dependent PDT components as
            finalizable.
            (finalize_component): Deallocate them.
            (generate_finalization_wrapper): Generate the wrapper for a PDT
            with LEN-dependent components.
            * trans-expr.cc (gfc_trans_assignment_1): Free the components of
            a structure constructor temporary after a polymorphic
            assignment.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/allocate_with_source_14.f03: Update __builtin_free
            count.
            * gfortran.dg/class_19.f03: Likewise.
            * gfortran.dg/class_allocate_16.f90: Likewise.
            * gfortran.dg/finalize_33.f90: Likewise.
            * gfortran.dg/pdt_15.f03: Update __builtin_free and .n.data
            counts.
            * gfortran.dg/pdt_26.f03: Update __builtin_free and
            __builtin_malloc counts.
            * gfortran.dg/pdt_46.f03: Likewise.
            * gfortran.dg/pdt_50.f03: Likewise.
            * gfortran.dg/pdt_bug9.f90: Move the REAL(16) cases to
            pdt_bug9a.f90.  Check that LEN components are freed.
            * gfortran.dg/class_assign_5.f90: New test.
            * gfortran.dg/pdt_bug9a.f90: New test.

Reply via email to