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

--- Comment #3 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:1f03545576b68402efda98a963a0195d9467ca63

commit r17-6329-g1f03545576b68402efda98a963a0195d9467ca63
Author: Jerry DeLisle <[email protected]>
Date:   Sat Nov 14 19:40:04 2026 -0800

    fortran: [PR52774] Double free when a function call redefines the lhs

    For lhs = f(...) with an lhs that has allocatable components, gfortran
    saved the lhs components before calling f and freed them after the
    assignment.  When f redefined the lhs through an actual argument that
    overlaps it, f had already freed the saved components, so they were
    freed twice, and the ones f left in the lhs leaked.  Evaluate such a
    call before the lhs components are saved.  The assignment violates
    F2023 10.1.4 p2, which is not a constraint, so no diagnostic is added.

    Assisted-by: Claude Opus 5.5

            PR fortran/52774

    gcc/fortran/ChangeLog:

            * trans-expr.cc (rhs_may_redefine_lhs): New function.
            (gfc_trans_assignment_1): Evaluate an rhs that may redefine the lhs
            before the lhs components are saved for deallocation.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/asan/pr52774.f90: New test.
  • [Bug fortran/52774] Derived-typ... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to