public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, libfortran] PR51825 - Fortran runtime error: Cannot match namelist object name
@ 2013-03-07 20:37 Tilo Schwarz
  2013-03-20  8:05 ` Tobias Burnus
  0 siblings, 1 reply; 2+ messages in thread
From: Tilo Schwarz @ 2013-03-07 20:37 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 277 bytes --]

Hi,

this patch fixes PR 51825.

Built and regtested on Linux 3.2.0-4-686-pae.

(Dear Jerry, this is my patch you wanted to look at, but improved with  
test cases and Changelog. Please consider looking at this version instead  
of the old version. Thank you!)

Regards,

	Tilo

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: namelist.diff --]
[-- Type: text/diff; name=namelist.diff, Size: 4097 bytes --]

2013-03-07  Tilo Schwarz  <tilo@tilo-schwarz.de>

	PR libfortran/51825
	* io/list_read.c (nml_read_obj): Don't end the component loop on a
	nested derived type, but continue with the next loop iteration.
	(nml_get_obj_data): Don't move the first_nl pointer further in the
	list if a qualifier was found.
	* gcc/testsuite/gfortran.dg/namelist_77.f90: New.
	* gcc/testsuite/gfortran.dg/namelist_78.f90: New.

diff --git a/gcc/testsuite/gfortran.dg/namelist_77.f90 b/gcc/testsuite/gfortran.dg/namelist_77.f90
new file mode 100644
index 0000000..3ce2ee7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/namelist_77.f90
@@ -0,0 +1,48 @@
+! { dg-do run }
+! PR 51825 - Fortran runtime error: Cannot match namelist object name
+! Test case derived from PR.
+
+module local_mod
+
+    type mytype1
+        integer :: int1
+    end type
+
+    type mytype2
+        integer :: n_x       
+        integer :: n_px        
+    end type
+
+    type beam_init_struct
+        character(16) :: chars(1) = ''                                  
+        type (mytype1) dummy
+        type (mytype2) grid(1)      
+    end type
+
+end module
+
+program error_namelist
+
+    use local_mod
+
+    implicit none
+
+    type (beam_init_struct) beam_init
+
+    namelist / error_params / beam_init
+
+    open (10, status='scratch')
+    write (10, '(a)') "&error_params"
+    write (10, '(a)') "  beam_init%chars(1)='JUNK'"
+    write (10, '(a)') "  beam_init%grid(1)%n_x=3"
+    write (10, '(a)') "  beam_init%grid(1)%n_px=2"
+    write (10, '(a)') "/"
+    rewind(10)
+    read(10, nml=error_params)
+    close (10)
+
+    if (beam_init%chars(1) /= 'JUNK') call abort
+    if (beam_init%grid(1)%n_x /= 3) call abort
+    if (beam_init%grid(1)%n_px /= 2) call abort
+
+end program
diff --git a/gcc/testsuite/gfortran.dg/namelist_78.f90 b/gcc/testsuite/gfortran.dg/namelist_78.f90
new file mode 100644
index 0000000..2ed41ce
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/namelist_78.f90
@@ -0,0 +1,32 @@
+! { dg-do run }
+! Test case regarding namelist problems with derived types
+
+program namelist
+
+    type d1
+        integer :: j = 0
+    end type d1
+
+    type d2
+        type(d1) k
+    end type d2
+
+    type d3
+        type(d2) d(2)
+    end type d3
+
+    type(d3) der
+    namelist /nmlst/ der
+
+    open (10, status='scratch')
+    write (10, '(a)') "&NMLST"
+    write (10, '(a)') " DER%D(1)%K%J = 1,"
+    write (10, '(a)') " DER%D(2)%K%J = 2,"
+    write (10, '(a)') "/"
+    rewind(10)
+    read(10, nml=nmlst)
+    close (10)
+
+    if (der%d(1)%k%j /= 1) call abort
+    if (der%d(2)%k%j /= 2) call abort
+end program namelist
diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index fb8a841..6f2f7b9 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -2578,17 +2578,17 @@ nml_read_obj (st_parameter_dt *dtp, namelist_info * nl, index_type offset,
 	       since a single object can have multiple reads.  */
 	    dtp->u.p.expanded_read = 0;
 
-	    /* Now loop over the components. Update the component pointer
-	       with the return value from nml_write_obj.  This loop jumps
-	       past nested derived types by testing if the potential
-	       component name contains '%'.  */
+	    /* Now loop over the components.  */
 
 	    for (cmp = nl->next;
 		 cmp &&
-		   !strncmp (cmp->var_name, obj_name, obj_name_len) &&
-		   !strchr (cmp->var_name + obj_name_len, '%');
+		   !strncmp (cmp->var_name, obj_name, obj_name_len);
 		 cmp = cmp->next)
 	      {
+		/* Jump over nested derived type by testing if the potential
+		   component name contains '%'.  */
+		if (strchr (cmp->var_name + obj_name_len, '%'))
+		    continue;
 
 		if (nml_read_obj (dtp, cmp, (index_type)(pdata - nl->mem_pos),
 				  pprev_nl, nml_err_msg, nml_err_msg_size,
@@ -2901,7 +2901,8 @@ get_name:
 	  goto nml_err_ret;
 	}
 
-      if (*pprev_nl == NULL || !component_flag)
+      /* Don't move first_nl further in the list if a qualifier was found.  */
+      if ((*pprev_nl == NULL && !qualifier_flag) || !component_flag)
 	first_nl = nl;
 
       root_nl = nl;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch, libfortran] PR51825 - Fortran runtime error: Cannot match namelist object name
  2013-03-07 20:37 [Patch, libfortran] PR51825 - Fortran runtime error: Cannot match namelist object name Tilo Schwarz
@ 2013-03-20  8:05 ` Tobias Burnus
  0 siblings, 0 replies; 2+ messages in thread
From: Tobias Burnus @ 2013-03-20  8:05 UTC (permalink / raw)
  To: Tilo Schwarz; +Cc: fortran, gcc-patches

Hi Tilo,

I have now committed your two patches.
* PR 48618 - Negative unit number in OPEN(...) is sometimes allowed (as 
Rev. 196805)
which was approved here: 
http://thread.gmane.org/gmane.comp.gcc.fortran/40435/focus=40455 (It's 
not in the gcc.gnu.org/ml/fortran as the server didn't record the mails 
at that point)
* This patch (as Rev. 196806)

Congratulation to the committal of your first two patches - and thanks 
again for your work.


Two remarks:

Tilo Schwarz wrote:
> 2013-03-07  Tilo Schwarz<tilo@tilo-schwarz.de>
>
> 	PR libfortran/51825
> 	* io/list_read.c (nml_read_obj): Don't end the component loop on a
> 	nested derived type, but continue with the next loop iteration.
> 	(nml_get_obj_data): Don't move the first_nl pointer further in the
> 	list if a qualifier was found.
> 	* gcc/testsuite/gfortran.dg/namelist_77.f90: New.
> 	* gcc/testsuite/gfortran.dg/namelist_78.f90: New.

The change log ends up in two files: libgfortran/ChangeLog and 
gcc/testsuite/ChangeLog. File names are relative to those files. Hence, 
I removed "gcc/testsuite/" before committal.

> +++ b/gcc/testsuite/gfortran.dg/namelist_77.f90
> @@ -0,0 +1,48 @@
> +! { dg-do run }
> +! PR 51825 - Fortran runtime error: Cannot match namelist object name
> +! Test case derived from PR.
...
> +++ b/gcc/testsuite/gfortran.dg/namelist_78.f90
> @@ -0,0 +1,32 @@
> +! { dg-do run }
> +! Test case regarding namelist problems with derived types

It is useful to quickly see from which bug/problem report the test case 
came from. Thus, I added "PR libfortran/51825". (Using PR 51825 is also 
fine; btw. there is no need to add a full link to Bugzilla as the PR 
number is sufficient.)

Tobias

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-20  8:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-07 20:37 [Patch, libfortran] PR51825 - Fortran runtime error: Cannot match namelist object name Tilo Schwarz
2013-03-20  8:05 ` Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).