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

--- Comment #24 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:d93190f056f9725a614c731519aef5bbe4afd53c

commit r17-6422-gd93190f056f9725a614c731519aef5bbe4afd53c
Author: Jerry DeLisle <[email protected]>
Date:   Wed Nov 18 09:54:41 2026 -0800

    fortran: [PR82173] Free PDT LEN storage only on deallocation

    Since r17-6306 the finalization wrapper of a PDT frees its LEN-dependent
    components.  The wrapper also finalizes objects that continue to exist,
    such as an INTENT(OUT) actual argument (F2023 7.5.6.3), so the procedure
    then accessed freed storage.  Free these components only when the
    wrapper's fini_coarray argument is true, as is already done for coarray
    components, and pass true wherever the finalized object is deallocated.
    An allocatable object cannot have coarray ultimate components, so this
    does not change the handling of coarrays.

    Assisted-by: Claude Opus 5.5

            PR fortran/82173

    2026-11-18  Jerry Delisle  <[email protected]>

    gcc/fortran/ChangeLog:

            * class.cc (finalize_component): Deallocate LEN-dependent PDT
            components only if fini_coarray is true.
            (generate_finalization_wrapper): Document fini_coarray.
            * trans.cc (gfc_add_comp_finalizer_call): Pass true for
            fini_coarray if the component is allocatable.
            (gfc_add_finalizer_call): Add argument FINI_COARRAY and pass it to
            the finalizer.
            (gfc_deallocate_with_status): Pass true for fini_coarray.
            (gfc_deallocate_scalar_with_status): Likewise.
            * trans.h (gfc_add_finalizer_call): Add a bool argument.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/finalize_18.f90: Update the count of finalizer calls
            with fini_coarray true.
            * gfortran.dg/pdt_bug9b.f90: New test.

Reply via email to