[Bug libfortran/92569] [8/9/10 Regression] gfortran read with end directive does not trigger with -ffrontend-optimize

2019-11-24 Thread tkoenig at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92569

--- Comment #10 from Thomas Koenig  ---
Author: tkoenig
Date: Sun Nov 24 19:16:23 2019
New Revision: 278659

URL: https://gcc.gnu.org/viewcvs?rev=278659&root=gcc&view=rev
Log:
Fix EOF handling for arrays.

2019-11-23  Thomas Koenig  
Harald Anlauf 

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  
Harald Anlauf 

PR fortran/92569
* gfortran.dg/eof_6.f90: New test.


Added:
trunk/gcc/testsuite/gfortran.dg/eof_6.f90
Modified:
trunk/gcc/testsuite/ChangeLog
trunk/libgfortran/ChangeLog
trunk/libgfortran/io/transfer.c

[Bug libfortran/92569] [8/9/10 Regression] gfortran read with end directive does not trigger with -ffrontend-optimize

2019-11-23 Thread jvdelisle at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92569

--- Comment #9 from Jerry DeLisle  ---
(In reply to Thomas Koenig from comment #8)
> Hope you don't mind if I take this.

Hi Thomas, just noticed this one. I can review for you when you are ready.

[Bug libfortran/92569] [8/9/10 Regression] gfortran read with end directive does not trigger with -ffrontend-optimize

2019-11-23 Thread tkoenig at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92569

Thomas Koenig  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |tkoenig at gcc dot 
gnu.org

--- Comment #8 from Thomas Koenig  ---
Hope you don't mind if I take this.

[Bug libfortran/92569] [8/9/10 Regression] gfortran read with end directive does not trigger with -ffrontend-optimize

2019-11-22 Thread tkoenig at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92569

--- Comment #7 from Thomas Koenig  ---
(In reply to anlauf from comment #6)
> Something like the following fixes the testcase, but leads to regressions
> elsewhere in the testsuite (e.g. direct_io_{9,10}.f):

You've found the right spot, I think.

Index: io/transfer.c
=== 
--- io/transfer.c   (Revision 278025)   
+++ io/transfer.c   (Arbeitskopie)  
@@ -2544,6 +2544,10 @@  

   while (data) 
 {  
+  if (unlikely (dtp->u.p.current_unit  
+   && 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;

seems to be better...

[Bug libfortran/92569] [8/9/10 Regression] gfortran read with end directive does not trigger with -ffrontend-optimize

2019-11-21 Thread anlauf at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92569

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

   Target Milestone|--- |10.0
  Known to fail||10.0, 8.3.1, 9.2.1

[Bug libfortran/92569] [8/9/10 Regression] gfortran read with end directive does not trigger with -ffrontend-optimize

2019-11-21 Thread anlauf at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92569

--- Comment #6 from anlauf at gcc dot gnu.org ---
Something like the following fixes the testcase, but leads to regressions
elsewhere in the testsuite (e.g. direct_io_{9,10}.f):

Index: libgfortran/io/transfer.c
===
--- libgfortran/io/transfer.c   (Revision 278593)
+++ libgfortran/io/transfer.c   (Arbeitskopie)
@@ -2544,6 +2544,8 @@

   while (data)
 {
+  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;

[Bug libfortran/92569] [8/9/10 Regression] gfortran read with end directive does not trigger with -ffrontend-optimize

2019-11-21 Thread anlauf at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92569

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

  Component|fortran |libfortran

--- Comment #5 from anlauf at gcc dot gnu.org ---
Running the failing testcase under the debugger, it appears that the
end-of-file condition is not properly dealt with in the library:

transfer.c:
2542
2543  data = GFC_DESCRIPTOR_DATA (desc);
2544
2545  while (data)
2546{
2547  dtp->u.p.transfer (dtp, iotype, data, kind, size, tsize);
2548  data += stride0 * tsize;
2549  count[0] += tsize;
2550  n = 0;
2551  while (count[n] == extent[n])

(gdb) p dtp->u.p.current_unit->endfile

one gets after the last valid read

$2 = NO_ENDFILE

and after the first attempt pase EOF:

(gdb) p dtp->u.p.current_unit->endfile

$5 = AFTER_ENDFILE

and after the next attempt:

At line 8 of file res.f (unit = 1, file = 'resultav4.dat')
Fortran runtime error: Read past ENDFILE record

So one needs to check and properly catch the ENDFILE condition.

Who knows the right way to deal with such conditions?