https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122936
Bug ID: 122936
Summary: Read for user defined data types in Fortran fails if
there is additional information in the row
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libfortran
Assignee: unassigned at gcc dot gnu.org
Reporter: martin.pleissa at web dot de
Target Milestone: ---
Created attachment 62951
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62951&action=edit
minimal working example
I'm currently porting codes to gfortran 15, which read old "BLAS / LAPACK"
style files to configure our code (like:
https://github.com/Reference-LAPACK/lapack/blob/master/BLAS/TESTING/cblat2.in
). The main thing in these files is, once the read list is over, the rest of
line is seen as a comment and ignored. In this way these file could be
documented.
Now we have a user defined datatype, overloading the read(formatted) function,
which is mixed in between the read of standard fortran datatypes. Since commit
3aeb697a2158d359d9f951f6c6c6bcd9c53c8c2f (Fortran: Suppress wrong End Of File
error with user defined IO, PR libfortran/105361) this no longer works, if a
user defined type is involved. For this, we have to remove the "comments" from
the files, which makes them unreadable.
Attached is a minimal working examples, which works well before
3aeb697a2158d359d9f951f6c6c6bcd9c53c8c2f and is now damaged. The first input
file, for stdin, is
2.5 9 1.5 Value for V1
15 2.4 17 Value for V2
which emulates the problem and is in basic like our files with comments ( or
the onece from BLAS and LAPACK). This triggers the error in gfortran built post
3aeb697a2158d359d9f951f6c6c6bcd9c53c8c2f. If I change the element in the read
list from the user defined type to a direct real, it works as well and the
remaining part of the line is ignored. The triggered error reads
./test_io < test_io.in
At line 40 of file test_io.f90 (unit = 5, file = 'stdin')
Fortran runtime error: Bad integer for item 1 in list input
Error termination. Backtrace:
#0 0x41bb37 in read_integer
at ../../../libgfortran/io/list_read.c:1133
#1 0x41eafa in list_formatted_read_scalar
at ../../../libgfortran/io/list_read.c:2227
#2 0x401b9b in ???
#3 0x401d83 in ???
#4 0x43f457 in ???
#5 0x44161f in ???
#6 0x401874 in ???
The second input file does not have the comments
2.5 9 1.5
15 2.4 17
which is without the comments. This works well after the commit in both cases,
with a real and a user defined type.
Obivously, the second condition of
2434 if (likely (dtp->u.p.child_saved_iostat == LIBERROR_OK)
2435 && ((dtp->common.flags & IOPARM_DT_HAS_UDTIO) == 0))
in libgfortran/io/list_read.c is responsible for this behavior.