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

--- Comment #8 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:11be877aea73b0b26638078908a42dd0f97d81d7

commit r17-2268-g11be877aea73b0b26638078908a42dd0f97d81d7
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.

Reply via email to