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

--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-15 branch has been updated by Jerry DeLisle
<[email protected]>:

https://gcc.gnu.org/g:2463358ca6a787216d3ef59cd2f0566cdbf59eb0

commit r15-11364-g2463358ca6a787216d3ef59cd2f0566cdbf59eb0
Author: Jerry DeLisle <[email protected]>
Date:   Wed Jul 8 10:22:04 2026 -0700

    fortran: [PR126116] Internal file I/O corrupts NEWUNIT state

    Before this fix, Performing an internal file I/O
    (such as WRITE to a character variable) incorrectly corrupts
    the internal unit management table in libgfortran.

    This patch adds a bool to the gfc_unit structure to allow
    tracking whether a gfc_unit was created for purposes of
    internal I/O to avoid the breakage.

            PR libfortran/126116

    libgfortran/ChangeLog:

            * io/io.h (struct gfc_unit): Add bool for tracking.
            Fix some white space problems.
            * io/unit.c (close_unit_1): Add a declaration for this
            function so it can be called before it has been defined.
            Use the new bool.
            (is_internal_reserved): New helper function. Returns true
            only if the unit is not null and the internal unit kind is zero
            meaning its not a character string.
            (find_unit): Use the new helper function
            (find_or_create_unit): Use the new helper.
            (get_unit): Set the new bool.
            (close_unit): Update the close_unit_1 argument list.
            (close_units): Likewise.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/pr126116.f90: New test.

    (cherry picked from commit 11be877aea73b0b26638078908a42dd0f97d81d7)

Reply via email to