Bug 47154 - [4.6 Regression] END= does not work in namelist read
Summary: [4.6 Regression] END= does not work in namelist read
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.6.0
: P4 normal
Target Milestone: 4.6.0
Assignee: Jerry DeLisle
Keywords: wrong-code
Depends on:
Blocks: 32834
  Show dependency treegraph
Reported: 2011-01-02 21:48 UTC by Thomas Koenig
Modified: 2011-01-05 04:24 UTC (History)
3 users (show)

See Also:
Known to work: 4.5.3
Known to fail: 4.6.0
Last reconfirmed:

A proposed patch (544 bytes, patch)
2011-01-04 05:17 UTC, Jerry DeLisle
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2011-01-02 21:48:57 UTC
Original test case by Lawrence Doctors, from


Reduced test case:

ig25@linux-fd1f:~/Krempel/Lawr/TST> cat tst.f
      program foo
      real :: a
      namelist /b/a
      read (10,nml=b,end=100)
 100  continue
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:


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
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.

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
2011-01-04  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

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

Comment 9 Jerry DeLisle 2011-01-05 04:24:48 UTC