Bug 47154

Summary: [4.6 Regression] END= does not work in namelist read
Product: gcc Reporter: Thomas Koenig <tkoenig>
Component: libfortranAssignee: Jerry DeLisle <jvdelisle2>
Status: RESOLVED FIXED    
Severity: normal CC: jakub, jb, jvdelisle2
Priority: P4 Keywords: wrong-code
Version: 4.6.0   
Target Milestone: 4.6.0   
Host: Target:
Build: Known to work: 4.5.3
Known to fail: 4.6.0 Last reconfirmed:
Bug Depends on:    
Bug Blocks: 32834    
Attachments: A proposed patch

Description Thomas Koenig 2011-01-02 21:48:57 UTC
Original test case by Lawrence Doctors, from


http://gcc.gnu.org/ml/fortran/2011-01/msg00000.html

Reduced test case:

ig25@linux-fd1f:~/Krempel/Lawr/TST> cat tst.f
      program foo
      real :: a
      namelist /b/a
      open(10,status="scratch")
      read (10,nml=b,end=100)
 100  continue
      end
ig25@linux-fd1f:~/Krempel/Lawr/TST> gfortran tst.f
ig25@linux-fd1f:~/Krempel/Lawr/TST> ./a.out
At line 5 of file tst.f (unit = 10, file = '/tmp/gfortrantmpeSWNTR')
Fortran runtime error: `8,�

Works with 4.4.
Comment 1 Thomas Koenig 2011-01-03 07:34:54 UTC
Also works with 4.5.3.
Comment 2 Jerry DeLisle 2011-01-03 14:40:26 UTC
I will work on this one.
Comment 3 Jerry DeLisle 2011-01-04 05:17:18 UTC
Created attachment 22893 [details]
A proposed patch

The regression was caused by:

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

I have attached a patch that passes our current namelist tests.  The problem is that we were getting more than one call to generate_error, interfering with the END handler in error.c and even trashing some error messages.
Comment 4 Jerry DeLisle 2011-01-04 14:24:56 UTC
The patch passes regression testing.  I will commit tonight with ChangeLog and test case if someone can approve.
Comment 5 Janne Blomqvist 2011-01-04 14:53:40 UTC
Ok for trunk.

Thanks for the patch.

Per se, I suspect the problem was not multiple calls to generate_error(), as generate_error has some logic to return early in case an error has already been recorded. Rather I think the culprit is multiple calls to hit_eof(), I've been bitten by this myself. The first call tells us that we've hit EOF, and we're at the endfile record. The second one moves the position to after the endfile record, which is another type of error. Unfortunately I don't have any good idea how to solve this.
Comment 6 Jerry DeLisle 2011-01-04 18:24:19 UTC
Thanks Janne,

You are absolutely right, the multiple hit_eof's which call the generate_error.

So far I do not think we need to fix anything in hit_eof.  Thanks for review.
Comment 7 Jerry DeLisle 2011-01-05 03:53:23 UTC
Author: jvdelisle
Date: Wed Jan  5 03:53:15 2011
New Revision: 168502

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168502
Log:
2011-01-04  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/47154
	* io/list_read.c (namelist_read): Remove calls to hit_eof to avoid the
	duplicate calls via next_record.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/list_read.c
Comment 8 Jerry DeLisle 2011-01-05 04:18:43 UTC
Author: jvdelisle
Date: Wed Jan  5 04:18:39 2011
New Revision: 168503

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168503
Log:
2011-01-04  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/47154
	* gfortran.dg/namelist_68.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/namelist_68.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 9 Jerry DeLisle 2011-01-05 04:24:48 UTC
Fixed