Re: [PATCH] [PR126116] Internal file I/O corrupts NEWUNIT state
Harald Anlauf <[email protected]> Wed, 8 Jul 2026 22:17:43 +0200
| Newsgroups | gmane.comp.gcc.patches,gmane.comp.gcc.fortran |
|---|---|
| Message-ID | <[email protected]> |
On 7/8/26 19:55, Jerry D wrote: > See attached patch. > > Regression tested on x86_64. > > OK for mainline. Yes, this is OK. Thanks for the patch! Harald > Regards, > > Jerry > --- > 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.