User account creation filtered due to spam.

Bug 49296 - [4.6/4.7 Regression] Wrong END OF FILE error for list-directed I/O with strings
Summary: [4.6/4.7 Regression] Wrong END OF FILE error for list-directed I/O with strings
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.7.0
: P4 normal
Target Milestone: 4.6.2
Assignee: Janne Blomqvist
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-06-06 06:15 UTC by Tobias Burnus
Modified: 2011-07-13 18:54 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.0
Known to fail: 4.6.0, 4.7.0
Last reconfirmed: 2011-06-06 10:28:12


Attachments
Updated testcase (440 bytes, text/x-fortran)
2011-07-03 17:40 UTC, Janne Blomqvist
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-06-06 06:15:19 UTC
Reported by Reinhold Bader (LRZ). The following program prints with gfortran 4.5 (and ifort 11, NAG 5.1, g95, pathf95):
 OK

With gfortran 4.6/4.7, it prints:

At line 11 of file read_listdir_01_pos.f90 (unit = 20, file = 'read.dat')
Fortran runtime error: End of file


--------- C part of the test program -----------

#include <stdio.h>

void genfil() {
    FILE *fp;

    fp = fopen("read.dat", "w+");
    fprintf(fp, "abcd efgh");
    fclose(fp);
}


--------- Fortran part of the test program -----------

program read_listdir_01_pos
  implicit none
  integer, parameter :: strmx = 255
  character(len=strmx) :: s1, s2
  interface
     subroutine genfil() bind(c)
     end subroutine genfil
  end interface
  call genfil()
  open(unit=20, file='read.dat', form='FORMATTED', action='READ', status='OLD')
  read(20, fmt=*) s1, s2
  if (trim(s1) == "abcd" .and. trim(s2) == "efgh") then
     write(*, *) 'OK'
  else
     write(*, *) 'FAIL'
  end if
  close(20)
end program read_listdir_01_pos
Comment 1 Tobias Burnus 2011-06-06 09:42:36 UTC
The issue already occurs for
  read(20, fmt=*) s1
i.e. the list-directed read of a single character variable. In this case, read_character should only read "abcd" - and eat the white space, before the whole line is eaten.

It works with GCC 4.6.0 (trunk) 2010-09-28-r164677. While it fails with 4.7 2011-05-10 and 2011-06-06 -- and "4.6.0 20110523 [gcc-4_6-branch revision 174058] (SUSE Linux)".

(For testing: Ensure that the correct libgfortran version is used.)

I could not find anything very promising in the changelog, maybe Rev. 170239 (2011-02-16) for bug 47567 comment 15, or Rev. 168502 (2011-01-04) for PR 47154 look very vaguely related.
Comment 2 Dominique d'Humieres 2011-06-06 10:28:12 UTC
Reduced range:
gcc4.6 r166102 is OK
gcc4.6 r166367 gives the error.
Comment 3 Dominique d'Humieres 2011-06-06 10:36:33 UTC
Revision 166252 is within the range, but I fail to see the connection:

2010-11-03  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/43899
	* runtime/error.c (generate_warning): New function to generate a run
	time warning message. Fix some whitespace.
	* libgfortran.h: Add prototype for new function.
	* io/list_read.c (nml_read_obj): Use new function to warn when a
	character namelist object is truncated.  Only warn if compiled
	with -fbounds-check.
Comment 4 Tobias Burnus 2011-06-06 10:42:32 UTC
(In reply to comment #3)
> Revision 166252 is within the range, but I fail to see the connection:

My impression - looking at the diff - is that it is a different patch.

(Janne: Could you please use the normal ChangeLog format in commits? It helps tremendously to find commits.)

http://gcc.gnu.org/viewcvs?view=revision&revision=166180

r166180 | jb | 2010-11-02 13:56:38 +0100 (Tue, 02 Nov 2010) | 1 line
Changed paths:
   M /trunk/libgfortran/ChangeLog
   M /trunk/libgfortran/io/io.h
   M /trunk/libgfortran/io/list_read.c
   M /trunk/libgfortran/io/transfer.c

PR 45629 Remove usage of setjmp/longjmp
Comment 5 Dominique d'Humieres 2011-06-06 12:10:14 UTC
> > Revision 166252 is within the range, but I fail to see the connection:
>
> My impression - looking at the diff - is that it is a different patch.

You are right!-) Revision 166179 is OK, 166180 is not.
Comment 6 Dominique d'Humieres 2011-06-06 12:11:43 UTC
Changing component to libfortran.
Comment 7 Jerry DeLisle 2011-06-06 12:20:48 UTC
I will leave this to Janne. (I am very short on time.) If the fix is not obvious, I will be happy to review the patch. It took a while for this to surface.
Comment 8 Janne Blomqvist 2011-06-11 08:41:40 UTC
Assigning to myself. I'm pretty busy at the moment, though.. :(

Anyways, seems the problem is that we hit EOF before the end of the record; that is, read.dat doesn't contain a \n at the end of the line. Shouldn't be too hard to fix.
Comment 10 Janne Blomqvist 2011-06-18 07:53:12 UTC
Author: jb
Date: Sat Jun 18 07:53:09 2011
New Revision: 175166

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175166
Log:
PR 49296 List directed read of string ending in EOF.

libgfortran ChangeLog entry:

2011-06-18  Janne Blomqvist  <jb@gcc.gnu.org>

        PR libfortran/49296
        * io/list_read.c (read_character): Accept EOF as a separator when
        reading string.


testsuite ChangeLog entry:

2011-06-18  Janne Blomqvist  <jb@gcc.gnu.org>

        PR libfortran/48296
	* gfortran.dg/read_list_eof_1.f90: New test.



Added:
    trunk/gcc/testsuite/gfortran.dg/read_list_eof_1.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/list_read.c
Comment 11 Tobias Burnus 2011-06-20 14:32:27 UTC
Missed GCC 4.6.1 (RC was just posted), should thus be fixed for 4.6.2 when the branch opens again.
Cf. http://gcc.gnu.org/ml/gcc/2011-06/msg00274.html
Comment 12 Janne Blomqvist 2011-07-03 15:54:05 UTC
Author: jb
Date: Sun Jul  3 15:54:02 2011
New Revision: 175787

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175787
Log:
PR 48296 Accept EOF as separator when reading string with list format.

2011-07-03  Janne Blomqvist  <jb@gcc.gnu.org>

        Backport from mainline:
        PR libfortran/49296
	* io/list_read.c (read_character): Accept EOF as a separator when
        reading string.

2011-07-03  Janne Blomqvist  <jb@gcc.gnu.org>

        Backport from mainline:
        PR libfortran/48296
	* gfortran.dg/read_list_eof_1.f90: New test.


Added:
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/read_list_eof_1.f90
Modified:
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_6-branch/libgfortran/ChangeLog
    branches/gcc-4_6-branch/libgfortran/io/list_read.c
Comment 13 Janne Blomqvist 2011-07-03 16:00:34 UTC
Author: jb
Date: Sun Jul  3 16:00:32 2011
New Revision: 175788

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175788
Log:
PR 49296 Fix wrong PR number in ChangeLog entry

Modified:
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 14 Janne Blomqvist 2011-07-03 17:37:33 UTC
Author: jb
Date: Sun Jul  3 17:37:30 2011
New Revision: 175789

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175789
Log:
PR 49296 Fix wrong PR number in ChangeLog

Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 15 Janne Blomqvist 2011-07-03 17:40:11 UTC
Created attachment 24662 [details]
Updated testcase

Updated testcase that checks integer, real, and logical types in addition to character. Unfortunately, regressions still remain.
Comment 16 Janne Blomqvist 2011-07-13 18:46:48 UTC
Author: jb
Date: Wed Jul 13 18:46:44 2011
New Revision: 176245

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176245
Log:
PR 49296 List read, EOF without preceding separator

2011-07-13  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/49296
	* io/list_read.c (read_logical): Don't error out if a valid value
	is followed by EOF instead of a normal separator.
	(read_integer): Likewise.

testsuite:

2011-07-13  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/49296
	* gfortran.dg/read_list_eof_1.f90: Add tests for integer, real,
	and logical reads.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/read_list_eof_1.f90
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/list_read.c
Comment 17 Janne Blomqvist 2011-07-13 18:52:43 UTC
Author: jb
Date: Wed Jul 13 18:52:40 2011
New Revision: 176246

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176246
Log:
PR 49296 List read, EOF before separator, backport from trunk

2011-07-13  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/49296
	* io/list_read.c (read_logical): Don't error out if a valid value
	is followed by EOF instead of a normal separator.
	(read_integer): Likewise.

testsuite:

2011-07-13  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/49296
	* gfortran.dg/read_list_eof_1.f90: Add tests for integer, real,
	and logical reads.


Modified:
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/read_list_eof_1.f90
    branches/gcc-4_6-branch/libgfortran/ChangeLog
    branches/gcc-4_6-branch/libgfortran/io/list_read.c
Comment 18 Janne Blomqvist 2011-07-13 18:54:09 UTC
Fixed on trunk (4.7) and 4.6, closing.