Created attachment 23374 [details] This code fails Reading a namelist that contains two variable that are an array of structures fails. It is not even the assignment that fails, but the parsing already gives problems. Attached the code that illustrates the problem. This may be a follow-up of Bug 42901 (at least it is for me).
At line 27 of file test.f90 (unit = 10, file = '/tmp/gfortrantmp2WKkUW') Fortran runtime error: Cannot match namelist object name 2 I get the same error with gfortran 4.1.2 20080704 (Red Hat 4.1.2-48) Thus, it does not seem to be a regression. It works with ifort 11.1, pgf90 10.1-0 and pathscale 3.2.99. * * * type field_descr integer number end type type fsetup type (field_descr) :: vel(1) type (field_descr) :: scal(1) end type &nl_setup" field_setup%vel(1)%number= 3, field_setup%scal(1)%number= 2 / For this variant, the error message for the second line of the namelist is some uninitialized garbage: At line 23 of file foobar.f90 (unit = 10, file = '/tmp/gfortrantmpMxI6TY') Fortran runtime error: L�7� The namelist reading works, if "scal" is a scalar instead of an array. However, if "vel" is a scalar and "scal" an array, it fails - unless one swaps the "vel" and "scal" lines in the input file.
I will try to look at this one this weekend.
A reduced test case: program test_nml type field_descr integer number end type type fsetup type (field_descr), dimension(3) :: vel type (field_descr), dimension(3) :: scal end type type (fsetup) field_setup namelist /nl_setup/ field_setup field_setup%vel%number = 0 field_setup%scal%number = 0 open(10, status="scratch") write(10,'(a)') "&nl_setup" write(10,'(a)') " field_setup%scal(1)%number= 2," write(10,'(a)') " field_setup%scal(2)%number= 6," write(10,'(a)') "/" rewind(10) read(10,nml=nl_setup) write(*,nml=nl_setup) end program test_nml
Status update. I have more or less isolated the problem in list-read.c. I do not have an exact solution yet, but I am able to get the test case to work. I just need now to find the right place to make the tweak.
Probable Patch, Regression testing: Index: list_read.c =================================================================== --- list_read.c (revision 170492) +++ list_read.c (working copy) @@ -3058,6 +3058,8 @@ find_nml_name: goto nml_err_ret; generate_error (&dtp->common, LIBERROR_READ_VALUE, nml_err_msg); } + if (prev_nl && prev_nl->var_rank == 0) + prev_nl = NULL; } free_saved (dtp);
Author: jvdelisle Date: Sun Feb 27 20:06:10 2011 New Revision: 170548 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170548 Log: 2011-02-27 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libgfortran/47778 * io/list_read.c (namelist_read): Intialize the error string buffere. If pprev_nl was used during the previous namelist read and the rank was zero, reset the pointer to NULL for the next namelist read. Modified: trunk/libgfortran/ChangeLog trunk/libgfortran/io/list_read.c
Author: jvdelisle Date: Sun Feb 27 20:08:44 2011 New Revision: 170549 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170549 Log: 2011-02-27 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libgfortran/47778 * gfortran.dg/namelist_71.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/namelist_71.f90 Modified: trunk/gcc/testsuite/ChangeLog
Fixed on trunk. I will leave this PR open until I get the back ports done. I want to give this change a few days on trunk first.
Author: jvdelisle Date: Mon Mar 7 02:06:27 2011 New Revision: 170726 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170726 Log: 2011-03-06 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libgfortran/47778 * io/list_read.c (namelist_read): Intialize the error string buffere. If pprev_nl was used during the previous namelist read and the rank was zero, reset the pointer to NULL for the next namelist read. Modified: branches/gcc-4_5-branch/libgfortran/ChangeLog branches/gcc-4_5-branch/libgfortran/io/list_read.c
Author: jvdelisle Date: Mon Mar 7 02:11:56 2011 New Revision: 170727 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170727 Log: 2011-03-06 Jerry DeLisle <jvdelisle@gcc.gnu.org> Backport from mainline PR libgfortran/47778 * gfortran.dg/namelist_71.f90: New test. Added: branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/namelist_71.f90 Modified: branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
Fixed on 4.5 and 4.6. Closing