Bug 40853 - I/O: Namelist read error
Summary: I/O: Namelist read error
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.1
: P3 normal
Target Milestone: ---
Assignee: Jerry DeLisle
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2009-07-24 21:02 UTC by David Sagan
Modified: 2009-08-05 03:19 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.1.3 4.2.1 4.3.3 4.4.1 4.5.0
Last reconfirmed: 2009-07-28 02:00:12


Attachments
test.s file generated by the compile (573 bytes, text/plain)
2009-07-24 21:05 UTC, David Sagan
Details
A simple patch to resolve the problem (443 bytes, patch)
2009-07-29 04:40 UTC, Jerry DeLisle
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Sagan 2009-07-24 21:02:33 UTC
In brief: A namelist read of a structure component that is a vector when that structure has another component that is a structure results in a runtime error. 

Test file:

  program test

  implicit none

  type tao_title_struct
    character(2) justify   
  end type

  type tao_plot_page_struct
    real shape_height_max 
    type (tao_title_struct) title ! Comment this line out and the bug goes away.
    real size(2)
  end type

  type (tao_plot_page_struct) plot_page

  namelist / params / plot_page

  open (1, file = 'test.in')
  read (1, nml = params)
  close (1)

  end program

The file test.in is:

  &params
    plot_page%size = 1, 2
  /


Compiling and running gives:

[atf2code@lnx209 test]$ gfortran -v -save-temps test.f90
Driving: gfortran -v -save-temps test.f90 -lgfortranbegin -lgfortran -lm -shared-libgcc
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.4.1/configure --prefix=/home/atf2code/atf2/usr_local --with-gmp=/home/atf2code/atf2/usr_local --with-mpfr=/home/atf2code/atf2/usr_local
Thread model: posix
gcc version 4.4.1 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
 /a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../libexec/gcc/i686-pc-linux-gnu/4.4.1/f951 test.f90 -quiet -dumpbase test.f90 -mtune=generic -auxbase test -version -fintrinsic-modules-path /a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../lib/gcc/i686-pc-linux-gnu/4.4.1/finclude -o test.s
GNU Fortran (GCC) version 4.4.1 (i686-pc-linux-gnu)
        compiled by GNU C version 4.4.1, GMP version 4.3.1, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
 as -V -Qy -o test.o test.s
GNU assembler version 2.15.92.0.2 (i386-redhat-linux) using BFD version 2.15.92.0.2 20040927
COMPILER_PATH=/a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../libexec/gcc/i686-pc-linux-gnu/4.4.1/:/a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../libexec/gcc/
LIBRARY_PATH=/a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../lib/gcc/i686-pc-linux-gnu/4.4.1/:/a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../lib/gcc/:/a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../lib/gcc/i686-pc-linux-gnu/4.4.1/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
 /a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../libexec/gcc/i686-pc-linux-gnu/4.4.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../lib/gcc/i686-pc-linux-gnu/4.4.1/crtbegin.o -L/a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../lib/gcc/i686-pc-linux-gnu/4.4.1 -L/a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../lib/gcc -L/a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../lib/gcc/i686-pc-linux-gnu/4.4.1/../../.. test.o -lgfortranbegin -lgfortran -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /a/lnx113/nfs/acc/temp/atf2/usr_local/bin/../lib/gcc/i686-pc-linux-gnu/4.4.1/crtend.o /usr/lib/crtn.o

[atf2code@lnx209 test]$ ./a.out 
At line 20 of file test.f90 (unit = 1, file = 'test.in')
Fortran runtime error: Cannot match namelist object name 1


Note: If the "title" component of tao_plot_page_struct is commented out or moved below the "size" component then the program runs without fail.
Comment 1 David Sagan 2009-07-24 21:05:20 UTC
Created attachment 18250 [details]
test.s file generated by the compile
Comment 2 Tobias Burnus 2009-07-27 09:40:04 UTC
Confirmed. Fails with gfortran 4.1 to 4.5 and is thus no regression, but it works with ifort, g95, openf95, and NAG f95.
Comment 3 Jerry DeLisle 2009-07-28 02:00:12 UTC
I will get started on this.
Comment 4 Jerry DeLisle 2009-07-28 03:09:23 UTC
As a work-around, re-arranging the derived type like this:

  type tao_plot_page_struct
    real size(2)
    real shape_height_max 
    type (tao_title_struct) title
  end type

May help, until I get this sorted out.
Comment 5 Jerry DeLisle 2009-07-29 04:40:22 UTC
Created attachment 18265 [details]
A simple patch to resolve the problem

This patch solves the original test case.  It does require modification of test suite cases namelist_40.f90 and namelist_47.f90.  With the patch, those two test cases have a slightly modified error output.

Additional testing is always appreciated.  I will prepare a submittal for approval tomorrow.
Comment 6 Jerry DeLisle 2009-08-01 15:42:58 UTC
Patch submitted for approval:

http://gcc.gnu.org/ml/fortran/2009-08/msg00001.html

Comment 7 Jerry DeLisle 2009-08-02 18:31:26 UTC
Subject: Bug 40853

Author: jvdelisle
Date: Sun Aug  2 18:31:07 2009
New Revision: 150356

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=150356
Log:
2009-08-02  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/40853
	* io/list_read.c (nml_get_obj_data): Do not set nl
	pointer to first_nl if nl->next is NULL.

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

Comment 8 Jerry DeLisle 2009-08-02 18:48:10 UTC
Subject: Bug 40853

Author: jvdelisle
Date: Sun Aug  2 18:47:46 2009
New Revision: 150357

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=150357
Log:
2009-08-02  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/40853
	* gfortran.dg/namelist_40.f90: Update error output.
	* gfortran.dg/namelist_47.f90: Update error output.
	* gfortran.dg/namelist_58.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/namelist_58.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/namelist_40.f90
    trunk/gcc/testsuite/gfortran.dg/namelist_47.f90

Comment 9 Jerry DeLisle 2009-08-05 03:15:39 UTC
Subject: Bug 40853

Author: jvdelisle
Date: Wed Aug  5 03:15:18 2009
New Revision: 150476

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

	PR libfortran/40853
	* io/list_read.c (nml_get_obj_data): Do not set nl
	pointer to first_nl if nl->next is NULL.

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

Comment 10 Jerry DeLisle 2009-08-05 03:18:05 UTC
Subject: Bug 40853

Author: jvdelisle
Date: Wed Aug  5 03:17:52 2009
New Revision: 150477

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

	PR libfortran/40853
	* gfortran.dg/namelist_40.f90: Update error output.
	* gfortran.dg/namelist_47.f90: Update error output.
	* gfortran.dg/namelist_58.f90: New test.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/namelist_58.f90
Modified:
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/namelist_40.f90
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/namelist_47.f90

Comment 11 Jerry DeLisle 2009-08-05 03:19:27 UTC
Fixed on 4.4 and 4.5, closing