Bug 24459 - [4.1 Only] gfortran namelist problem
Summary: [4.1 Only] gfortran namelist problem
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.0.2
: P2 enhancement
Target Milestone: 4.1.2
Assignee: Jerry DeLisle
: 30193 (view as bug list)
Depends on:
Blocks: 19292
  Show dependency treegraph
Reported: 2005-10-20 18:23 UTC by Ed Hill
Modified: 2007-01-10 19:01 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2006-04-22 23:23:31


Note You need to log in before you can comment on or make changes to this bug.
Description Ed Hill 2005-10-20 18:23:37 UTC
I don't know if this is an actual regression but using gcc-4.0.2 
built with:

$ ../gcc-4.0.2/configure --prefix=/opt/gcc-4.0.2 \
  --enable-languages=c,c++,f95 --program-suffix=-4.0.2

the program:

$ cat diag.f
      program diag
      INTEGER nd
      PARAMETER ( nd = 5 )
      CHARACTER*(8) names(nd,nd)
      NAMELIST / diags /  names

will work with:

$ cat diag.nml
 '' '' '' '' '' '' ''
 '' '' '' '' '' '' ''
 '' '' '' ''/

but fails with the message:

$ ./diag
At line 7 of file diag.f
Fortran runtime error: Cannot match namelist object name 'etansq

when reading:

$ cat diag.nml
   names(1,1) = 'ETAN    ','ETANSQ  ','DETADT2 ','PHIBOT  ','PHIBOTSQ',

The reason that it appears to be a regression is that both namelist 
files work nicely with basically all g77 versions shipped in recent 
years and with a large number of both past and present commercial 
Fortran compilers including Intel v5--v9, PGI, IBM xlf, and Sun.

In my (humble!) opinion, it would be a shame if the namelist indexing 
("implicit" indexing?) is lost since large namelist files are more 
legible using it.  And, existing namelist files will require a fairly substantial amount of editing to convert between the two types of 
Comment 1 Ed Hill 2005-10-20 19:53:06 UTC
The same error happens using gcc from cvs today (2005-10-20).
Comment 2 Andrew Pinski 2005-10-21 22:27:30 UTC
Comment 3 Jerry DeLisle 2005-10-26 02:44:43 UTC
With the first case given, I get a segfault on i686-pc-linux-gnu.
gcc version 4.1.0 20051025 (experimental)

$ cat diag.nml
 '' '' '' '' '' '' ''
 '' '' '' '' '' '' ''
 '' '' '' ''/

(gdb) bt
#0  0x0073d86c in memcpy () from /lib/libc.so.6
#1  0x0021584e in nml_read_obj (nl=0x96293d0, offset=0)
    at ../../../gccdev/libgfortran/io/list_read.c:2008
#2  0x00216312 in *_gfortrani_namelist_read ()
    at ../../../gccdev/libgfortran/io/list_read.c:2297
#3  0x00219b6d in finalize_transfer ()
    at ../../../gccdev/libgfortran/io/transfer.c:1813
#4  0x00219c9b in *_gfortran_st_read_done ()
    at ../../../gccdev/libgfortran/io/transfer.c:1962
#5  0x08048864 in MAIN__ ()
#6  0x08048953 in main (argc=1, argv=0xbfa29604)
    at ../../../gccdev/libgfortran/fmain.c:18

I also found this while debugging the list_read.c on PR24416.  I am not sure these are related.  I am working on the segfault now.
Comment 4 Jerry DeLisle 2005-10-30 02:59:06 UTC
OK I have a patch for the segfault I was seeing and now I see the error the OP discusses.  I will continue on that as soon as I get the other bug fix submitted for review.  (I will have to create a new PR for the segfault)
Comment 5 Jerry DeLisle 2005-11-02 06:41:00 UTC
I will be looking at this sometime soon.  If this is high priority I will shift from DATE and TIME intrinsics to this.
Comment 6 Ed Hill 2005-11-02 13:12:34 UTC
Hi jvdelisle, I'm not sure if it qualifies as "high priority" but it is one 
of the few (only?) gfortran bugs that we've encountered with the MITgcm fluid 
flow and transport model (http://mitgcm.org).  If it helps, I'll be happy to 
test your fixes, do weekly testing with new versions of gfortran and our 
model, etc.
Comment 7 Jerry DeLisle 2005-11-24 07:21:06 UTC
This is not a bug.  Gfortran is complying with F95 namelist read requirements.  This would be an enhancement or extension. The work around is to use correct array triplets in the array qualifiers for namelist reads.

Will report later if we are going to add this feature.
Comment 8 Ed Hill 2005-11-24 16:26:31 UTC
Hi Jerry, thank you for looking into this issue and clarifing it!

The use of correct array triplets is a very quick and easy thing for us to 
do.  And its certainly a good idea to follow the Fortran standard.
Comment 9 Jerry DeLisle 2005-11-24 17:25:08 UTC
After going to comp.lang.fortran I determined this is not a bug and gfortran is correctly handling the given namelist.  To get desired behavior use array qualifiers with array triplet notation.
Comment 10 Jerry DeLisle 2005-11-25 19:44:13 UTC
I am reopening this PR because I recieved information that the behavior is a pre F90 feature commonly used before array triplet notation was introduced.  I also found that it is supported in g77.  So we treatthis as an extension.
Comment 11 Ed Hill 2005-12-04 19:54:00 UTC
Thank you for re-opening this bug!  In an attempt to make our model
(http://mitgcm.org) as portable as possible, we tried switching the 
namelist syntax from the older Fortran77 to F90 "triplets" and 
discovered the following:

"old style" Fortran77:
  eg.:  astring(1,1) = 'name1  ', 'name2  ', 'name3  '
  This syntax works with basically *EVERY* Fortran77 compiler that
  we can get our hands on including g77, Sun, IBM xlf, PGI (pgif77), 
  and Intel.  But it fails with gfortran.

"new-style F90 triplets":
  eg.:  astring(1:3,1) = 'name1  ', 'name2  ', 'name3  '
  This works with some Fortran77 compilers including g77 and Intel 
  but it fails with others including PGI (pgf77).

So I would again like to humbly request (or is it beg?!) that this 
long-standing g77 feature be included with gfortran.
Comment 12 Jerry DeLisle 2005-12-04 23:11:32 UTC
We just had a discussion regarding another similar problem.  The maintainers need to come to some concensus on the behavior of some compiler flags such as -std=f95 and -pedantic.  Once that is settled then we can address this problem.

The reason triplets fail with some f77 compilers is because that notation was not introduced until f90.  I think rather than seek compatibility across all compilers, you should seek standard conformance and encourage users to get standard conforming compilers.  BTW Gfortran is pretty affordable. :)
Comment 13 Jerry DeLisle 2006-05-02 00:02:32 UTC
Patch here:


Waiting for approval
Comment 14 Ed Hill 2006-05-02 16:20:55 UTC
Hi Jerry, I just re-ran the test case in this bug report and some other 
examples from our oceanic/atmospheric model (mitgcm.org) using gfortran 
which was checked out at about 12:30am (May 2) with:

  svn -q checkout svn://gcc.gnu.org/svn/gcc/trunk gcc

and with your patch as described at:


applied.  The good news (for me!) is that gfortran now works nicely 
(for every test that I've run so far) with this "old" (pre-F90) namelist 
syntax.  I'll continue to test it.

Thank you so much for chasing after this feature request and getting it 
implemented.  Your time/effort is very much appreciated!
Comment 15 patchapp@dberlin.org 2006-05-15 19:30:34 UTC
Subject: Bug number PR24459

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-05/msg00000.html
Comment 16 Jerry DeLisle 2006-05-20 07:15:01 UTC
Subject: Bug 24459

Author: jvdelisle
Date: Sat May 20 07:14:50 2006
New Revision: 113924

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113924
2006-05-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/24459
	* io/list_read.c (nml_parse_qualifier): Leave loop spec end value
	at default value unless -std=f95 or if an array section
	is specified in namelist input.  Warn if -pedantic.
	* io/io.h (st_parameter_dt): Add expanded_read flag.


Comment 17 Jerry DeLisle 2006-05-20 07:20:04 UTC
Fixed on 4.2
Comment 18 Jerry DeLisle 2006-05-21 01:56:15 UTC
Subject: Bug 24459

Author: jvdelisle
Date: Sun May 21 01:56:04 2006
New Revision: 113948

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113948
2006-05-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/24459
	* gfortran.dg/namelist_24.f90: New test.
	* gfortran.dg/namelist_12.f: Fix typo in comment.


Comment 19 Jerry DeLisle 2006-05-29 05:19:06 UTC
Subject: Bug 24459

Author: jvdelisle
Date: Mon May 29 05:18:58 2006
New Revision: 114182

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114182
2006-05-28  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/24459
	* io/list_read.c (nml_parse_qualifier): Leave loop spec end value
	at default value unless -std=f95 or if an array section
	is specified in namelist input.  Warn if -pedantic.
	* io/io.h (st_parameter_dt): Add expanded_read flag.


Comment 20 Jerry DeLisle 2006-05-29 05:22:12 UTC
Subject: Bug 24459

Author: jvdelisle
Date: Mon May 29 05:22:05 2006
New Revision: 114184

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114184
2006-05-28  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/24459
	* gfortran.dg/namelist_24.f90: New test.


Comment 21 Jerry DeLisle 2006-05-29 05:23:34 UTC
Fixed now on 4.1
Comment 22 Jerry DeLisle 2007-01-02 04:35:50 UTC
*** Bug 30193 has been marked as a duplicate of this bug. ***