Bug 20661 - [4.0 only] End of record not detected
Summary: [4.0 only] End of record not detected
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.1
Assignee: Not yet assigned to anyone
URL:
Keywords: patch
Depends on: 19568
Blocks: 19595
  Show dependency treegraph
 
Reported: 2005-03-27 21:59 UTC by kargl
Modified: 2005-06-05 07:45 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.0
Known to fail:
Last reconfirmed: 2005-03-27 22:02:41


Attachments
Walt's program (325 bytes, text/plain)
2005-03-27 22:00 UTC, kargl
Details
Updated patch (1.24 KB, patch)
2005-04-04 10:13 UTC, Thomas Koenig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description kargl 2005-03-27 21:59:56 UTC
This fc002.f95 from Walt Brainerd.

! End of record is not detected
!    on second READ
! iostats should be 0, 0, -2, -1
Comment 1 kargl 2005-03-27 22:00:38 UTC
Created attachment 8464 [details]
Walt's program
Comment 2 Andrew Pinski 2005-03-27 22:02:41 UTC
Confirmed.
Comment 3 Tobias Schlüter 2005-03-28 17:48:20 UTC
To clarify this:
! End of record is not detected
!    on second READ
! iostats should be 0, 0, -2, -1

The standard says:
"Execution of an input/output statement containing the IOSTAT= specifier causes
the variable specified in the IOSTAT= specifier to become defined
(1) With a zero value if neither an error condition, and end-of-file condition,
nor an end-of-record condition occurs,
(2) With a processor-dependent positive integer value if an error condition occurs,
(3) With a processor-dependent negative integer value if an end-of-ile condition
occurs and no error condition occurs, or
(4) With a processor-dependent negative integer value different from the
end-of-file value if and end-of-record condition occurs and no error condition
or end-of-file condition occurs.

Current output from gfortran:
 iostat           0
 iostat           0 x
 iostat           0
 iostat          -1
Comment 4 Thomas Koenig 2005-03-29 15:11:32 UTC
I'll try and have a look.

Hopefully, my copyright papers that I sent off on 2005-03-19 will
come through sometime soon, because the end-of-record patch
at http://gcc.gnu.org/ml/gcc-patches/2005-03/msg00729.html (or
something that does the same job) needs to be applied before
going into this one.

Thomas
Comment 5 Thomas Koenig 2005-04-01 13:34:20 UTC
This patch fixes the test case.  It also includes my
EOR patch for advancing I/O.

This is regression-tested on mainline.  I'll submit a proper
patch when I have finished regression-testing it on 4.0.

--- transfer.c.orig     2005-03-25 14:35:29.000000000 +0100
+++ transfer.c  2005-04-01 15:34:19.000000000 +0200
@@ -150,7 +150,12 @@ read_sf (int *length)
   else
     p = base = data;

-  memset(base,'\0',*length);
+  memset(base,' ',*length);
+
+  /* If we have seen an eor previously, return blanks.  */
+
+  if (sf_seen_eor)
+    return base;

   current_unit->bytes_left = options.default_recl;
   readlen = 1;
@@ -179,12 +184,6 @@ read_sf (int *length)

       if (readlen < 1 || *q == '\n' || *q == '\r')
        {
-         /* ??? What is this for?  */
-          if (current_unit->unit_number == options.stdin_unit)
-            {
-              if (n <= 0)
-                continue;
-            }
          /* Unexpected end of line.  */
          if (current_unit->flags.pad == PAD_NO)
            {
@@ -193,8 +192,13 @@ read_sf (int *length)
            }

          current_unit->bytes_left = 0;
-         *length = n;
           sf_seen_eor = 1;
+
+         if (advance_status == ADVANCE_NO)
+           ioparm.library_return = LIBRARY_EOR;
+         else
+           *length = n;
+
          break;
        }

@@ -748,6 +752,9 @@ formatted_transfer (bt type, void *p, in
          internal_error ("Bad format node");
        }

+      if (ioparm.library_return == LIBRARY_EOR)
+       generate_error (ERROR_EOR, NULL);
+
       /* Free a buffer that we had to allocate during a sequential
         formatted read of a block that was larger than the static
         buffer.  */
@@ -1223,7 +1230,10 @@ next_record_r (int done)
       length = 1;
       /* sf_read has already terminated input because of an '\n'  */
       if (sf_seen_eor)
-         break;
+       {
+         sf_seen_eor=0;
+         break;
+       }

       do
         {
Comment 6 Thomas Koenig 2005-04-04 10:13:34 UTC
Created attachment 8525 [details]
Updated patch

Updated patch.

I *think* I have the corner cases of non-advancing I/O
covered correctly with this.
Comment 7 CVS Commits 2005-04-10 08:36:11 UTC
Subject: Bug 20661

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tkoenig@gcc.gnu.org	2005-04-10 08:35:40

Modified files:
	libgfortran    : ChangeLog 
	libgfortran/io : transfer.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: eor_handling_1.f90 eor_handling_2.f90 
	                           eor_handling_3.f90 eor_handling_4.f90 
	                           eor_handling_5.f90 noadv_size.f90 
	                           pad_no.f90 

Log message:
	2005-04-10  Thomas Koenig <Thomas.Koenig@online.de>
	
	PR libfortran/17992
	PR libfortran/19568
	PR libfortran/19595
	PR libfortran/20005
	PR libfortran/20092
	PR libfortran/20131
	PR libfortran/20138
	PR libfortran/20661
	PR libfortran/20744
	* io/transfer.c (top level): eor_condition: New static variable.
	(read_sf): Remove unnecessary zeroing of buffer (there is enough
	information in its length).
	Return a string of length 0 (to be padded by caller) if EOR was
	seen previously.
	Remove erroneous special casing of EOR for standard input.
	Set eor_condition for non-advancing I/O if an end of line was
	detected.
	Increment ioparm.size if necessary.
	(formatted_transfer):  Skip the function if there is an EOR condition.
	(data_transfer_init):  Initialize eor_condition to zero (false).
	(next_record_r):  Clear sf_seen_eor if a \n has been seen already.
	(finalize_transfer):  If there is an EOR condition, raise the error.
	
	2005-04-10   Thomas Koenig  <Thomas.Koenig@online.de>
	
	* eor_handling_1.f90: New test case.
	* eor_handling_2.f90: New test case.
	* eor_handling_3.f90: New test case.
	* eor_handling_4.f90: New test case.
	* eor_handling_5.f90: New test case.
	* noadv_size.f90: New test case.
	* pad_no.f90: New test case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.188&r2=1.189
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/io/transfer.c.diff?cvsroot=gcc&r1=1.35&r2=1.36
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5320&r2=1.5321
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/eor_handling_1.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/eor_handling_2.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/eor_handling_3.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/eor_handling_4.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/eor_handling_5.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/noadv_size.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/pad_no.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 Thomas Koenig 2005-04-10 08:44:45 UTC
Fixed in 4.1.0, waiting for 4.0 to reopen.
Comment 9 CVS Commits 2005-05-03 19:40:09 UTC
Subject: Bug 20661

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	tkoenig@gcc.gnu.org	2005-05-03 19:39:36

Modified files:
	libgfortran    : ChangeLog 
	libgfortran/io : transfer.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: eor_handling_1.f90 eor_handling_2.f90 
	                           eor_handling_3.f90 eor_handling_4.f90 
	                           eor_handling_5.f90 noadv_size.f90 
	                           pad_no.f90 

Log message:
	2005-05-03  Thomas Koenig <Thomas.Koenig@online.de>
	
	Backport from mainline:
	PR libfortran/17992
	PR libfortran/19568
	PR libfortran/19595
	PR libfortran/20005
	PR libfortran/20092
	PR libfortran/20131
	PR libfortran/20661
	PR libfortran/20744
	* io/transfer.c (top level): eor_condition: New static variable.
	(read_sf): Remove unnecessary zeroing of buffer (there is enough
	information in its length).
	Return a string of length 0 (to be padded by caller) if EOR was
	seen previously.
	Remove erroneous special casing of EOR for standard input.
	Set eor_condition for non-advancing I/O if an end of line was
	detected.
	Increment ioparm.size if necessary.
	(formatted_transfer):  Skip the function if there is an EOR condition.
	(data_transfer_init):  Initialize eor_condition to zero (false).
	(next_record_r):  Clear sf_seen_eor if a \n has been seen already.
	(finalize_transfer):  If there is an EOR condition, raise the error.
	
	2005-05-03  Thomas Koenig  <Thomas.Koenig@online.de>
	
	Backport from mainline:
	* eor_handling_1.f90: New test case.
	* eor_handling_2.f90: New test case.
	* eor_handling_3.f90: New test case.
	* eor_handling_4.f90: New test case.
	* eor_handling_5.f90: New test case.
	* noadv_size.f90: New test case.
	* pad_no.f90: New test case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.163.2.22&r2=1.163.2.23
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/io/transfer.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.32.2.2&r2=1.32.2.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.156&r2=1.5084.2.157
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/eor_handling_1.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/eor_handling_2.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/eor_handling_3.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/eor_handling_4.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/eor_handling_5.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/noadv_size.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/pad_no.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.6.1

Comment 10 Thomas Koenig 2005-05-03 19:48:01 UTC
Patch committed to 4.0.1.  Fixed.
Comment 11 Thomas Koenig 2005-05-03 19:51:22 UTC
Patch committed to 4.0.1.  Fixed.