Bug 35617 - [4.3 Regression] read namelist error
Summary: [4.3 Regression] read namelist error
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P4 normal
Target Milestone: 4.3.1
Assignee: Jerry DeLisle
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-03-17 17:33 UTC by Alexander Pletzer
Modified: 2008-03-21 03:10 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.3 4.2.2
Known to fail: 4.3.0
Last reconfirmed: 2008-03-18 02:29:45


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Pletzer 2008-03-17 17:33:16 UTC
Hi: It seems that gfortran can get confused about namelists that include 2 ! on the same line. The following code fails to execute properly with gfortran 4.3.0:

cat > t.nml <<EOF
&nbdrive_naml
!nstep_stop = 2  ! uncomment to save restart data and halt after 1st step
!nstep_start = 2 ! uncomment to restart on 2nd step using saved restart data
mhdpath = 'EFIT:efit_d3d_99411_195.dat'
EOF
cat > t.f90 <<EOF
program test
character(len=128) :: mhdpath
namelist /nbdrive_naml/ mhdpath
open(10, file='t.nml')
read(10, nbdrive_naml)
close(10)
write(*, nbdrive_naml)
end program test
EOF
gfortran t.f90
./a.out 
At line 5 of file t.f90 (unit = 10, file = 't.nml')
Fortran runtime error: End of file
Comment 1 Alexander Pletzer 2008-03-17 18:32:17 UTC
(In reply to comment #0)

Oops, the failing namelist was:

&nbdrive_naml

!nstep_stop = 2  ! uncomment to save restart data and halt after 1st step
!nstep_start = 2 ! uncomment to restart on 2nd step using saved restart data
mhdpath = 'EFIT:efit_d3d_99411_195.dat'
/

and the erro message is 

Fortran runtime error: Cannot match namelist object name !nstep_start

Note: the initial blank line is essential in order to reproduce the problem. 

Thanks for your help.

--Alex

> Hi: It seems that gfortran can get confused about namelists that include 2 ! on
> the same line. The following code fails to execute properly with gfortran
> 4.3.0:
> 
> cat > t.nml <<EOF
> &nbdrive_naml
> !nstep_stop = 2  ! uncomment to save restart data and halt after 1st step
> !nstep_start = 2 ! uncomment to restart on 2nd step using saved restart data
> mhdpath = 'EFIT:efit_d3d_99411_195.dat'
> EOF
> cat > t.f90 <<EOF
> program test
> character(len=128) :: mhdpath
> namelist /nbdrive_naml/ mhdpath
> open(10, file='t.nml')
> read(10, nbdrive_naml)
> close(10)
> write(*, nbdrive_naml)
> end program test
> EOF
> gfortran t.f90
> ./a.out 
> At line 5 of file t.f90 (unit = 10, file = 't.nml')
> Fortran runtime error: End of file
> 

Comment 2 Tobias Burnus 2008-03-17 23:20:56 UTC
Confirmed. This is a regression. Personal candidate for this is PR 34530. I think the following patch is correct. Jerry what do you think? (I currently have no time to submit the patch.)

Index: libgfortran/io/list_read.c
===================================================================
--- libgfortran/io/list_read.c  (Revision 133293)
+++ libgfortran/io/list_read.c  (Arbeitskopie)
@@ -353,10 +353,7 @@ eat_separator (st_parameter_dt *dtp)
            {
              c = next_char (dtp);
              if (c == '!')
-               {
-                 eat_line (dtp);
-                 c = next_char (dtp);
-               }
+               eat_line (dtp);
            }
          while (c == '\n' || c == '\r' || c == ' ');
          unget_char (dtp, c);
Comment 3 Jerry DeLisle 2008-03-18 02:29:45 UTC
I will test and fix.
Comment 4 Jerry DeLisle 2008-03-18 04:25:35 UTC
Naturally, the patch in comment #2 breaks namelist_44.f90  (I say that because, after all, we are up to 44 namelist test cases, and about to go to 45 :) )

Nevertheless, this fixes it and passes regression.

Index: list_read.c
===================================================================
--- list_read.c (revision 133275)
+++ list_read.c (working copy)
@@ -356,6 +356,11 @@ eat_separator (st_parameter_dt *dtp)
                {
                  eat_line (dtp);
                  c = next_char (dtp);
+                 if (c == '!')
+                   {
+                     eat_line (dtp);
+                     c = next_char (dtp);
+                   }
                }
            }
          while (c == '\n' || c == '\r' || c == ' ');

eatline leaves us pointing to the first character of the next line, which we then get, which causes the while loop to exit, followed by an unget.  So the next get char will get a '!' which is nonsense and can not be matched.  The patch circumvents this special case.

I will commit as obvious to trunk and then to 4.3 in a few days.
Comment 5 Jerry DeLisle 2008-03-18 04:28:41 UTC
Subject: Bug 35617

Author: jvdelisle
Date: Tue Mar 18 04:27:56 2008
New Revision: 133302

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133302
Log:
2008-03-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/35617
	* io/list_read.c (eat_separator): If next character after eatline is '!'
	then eatline again.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/list_read.c

Comment 6 Jerry DeLisle 2008-03-18 04:31:26 UTC
Subject: Bug 35617

Author: jvdelisle
Date: Tue Mar 18 04:30:37 2008
New Revision: 133303

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133303
Log:
2008-03-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/35617
	* gfortran.dg/namelist_45.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/namelist_45.f90
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 7 Jerry DeLisle 2008-03-18 04:35:53 UTC
Fixed in trunk, will back port to 4.3
Comment 8 Jerry DeLisle 2008-03-21 01:30:17 UTC
Subject: Bug 35617

Author: jvdelisle
Date: Fri Mar 21 01:29:30 2008
New Revision: 133411

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133411
Log:
2008-03-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/35627
	Backport from trunk.
	* io/list_read.c (free_line): Clear the line buffer enable flag and
	reset the index into line_buffer, aka item_count.
	(next_char): Cleanup whitespace.
	(read_logical): Use unget_char to assure that the first character of the
	bad logical is saved in case it is part of an object name. Remove the
	clearing of index and flag that is now in free_line.
	(read_real): Likewise.

	PR libfortran/35617
	Backport from trunk.
	* io/list_read.c (eat_separator): If next character after eatline is '!'
	then eatline again. 

Modified:
    branches/gcc-4_3-branch/libgfortran/ChangeLog
    branches/gcc-4_3-branch/libgfortran/io/list_read.c

Comment 9 Jerry DeLisle 2008-03-21 01:38:23 UTC
Subject: Bug 35617

Author: jvdelisle
Date: Fri Mar 21 01:37:38 2008
New Revision: 133413

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133413
Log:
2008-03-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	Backport from trunk:
	PR libfortran/35627
	* gfortran.dg/namelist_46.f90: New test.

	PR libfortran/35617
	* gfortran.dg/namelist_45.f90: New test.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/namelist_45.f90
Modified:
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 10 Jerry DeLisle 2008-03-21 03:10:26 UTC
Fixed on 4.3