diff options
author | Thomas Koenig <tkoenig@gcc.gnu.org> | 2019-11-24 19:16:23 +0000 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2019-11-24 19:16:23 +0000 |
commit | 859174c82493971bd1e408231e24a7724953042f (patch) | |
tree | 21b49de0efcc442137d20845c6e5444df0a575a1 /libgfortran/io | |
parent | af4e8d4d5aa3a13bc9e2a8aa50341043e8ad6c61 (diff) | |
download | gcc-859174c82493971bd1e408231e24a7724953042f.tar.gz |
Fix EOF handling for arrays.
2019-11-23 Thomas Koenig <tkoenig@gcc.gnu.org>
Harald Anlauf <anlauf@gmx.de>
PR fortran/92569
* io/transfer.c (transfer_array_inner): If position is
at AFTER_ENDFILE in current unit, return from data loop.
2019-11-23 Thomas Koenig <tkoenig@gcc.gnu.org>
Harald Anlauf <anlauf@gmx.de>
PR fortran/92569
* gfortran.dg/eof_6.f90: New test.
Co-Authored-By: Harald Anlauf <anlauf@gmx.de>
From-SVN: r278659
Diffstat (limited to 'libgfortran/io')
-rw-r--r-- | libgfortran/io/transfer.c | 66 |
1 files changed, 51 insertions, 15 deletions
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 6382d0dad09..89f0abe9938 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -2542,26 +2542,62 @@ transfer_array_inner (st_parameter_dt *dtp, gfc_array_char *desc, int kind, data = GFC_DESCRIPTOR_DATA (desc); - while (data) + /* When reading, we need to check endfile conditions so we do not miss + an END=label. Make this separate so we do not have an extra test + in a tight loop when it is not needed. */ + + if (dtp->u.p.current_unit && dtp->u.p.mode == READING) { - dtp->u.p.transfer (dtp, iotype, data, kind, size, tsize); - data += stride0 * tsize; - count[0] += tsize; - n = 0; - while (count[n] == extent[n]) + while (data) { - count[n] = 0; - data -= stride[n] * extent[n]; - n++; - if (n == rank) + if (unlikely (dtp->u.p.current_unit->endfile == AFTER_ENDFILE)) + return; + + dtp->u.p.transfer (dtp, iotype, data, kind, size, tsize); + data += stride0 * tsize; + count[0] += tsize; + n = 0; + while (count[n] == extent[n]) { - data = NULL; - break; + count[n] = 0; + data -= stride[n] * extent[n]; + n++; + if (n == rank) + { + data = NULL; + break; + } + else + { + count[n]++; + data += stride[n]; + } } - else + } + } + else + { + while (data) + { + dtp->u.p.transfer (dtp, iotype, data, kind, size, tsize); + data += stride0 * tsize; + count[0] += tsize; + n = 0; + while (count[n] == extent[n]) { - count[n]++; - data += stride[n]; + count[n] = 0; + data -= stride[n] * extent[n]; + n++; + if (n == rank) + { + data = NULL; + break; + } + else + { + count[n]++; + data += stride[n]; + } } } } |