[Patch, fortran] PR29744 - [Regression] Type renaming crashes gfortran with excessive memory usage

Paul Richard Thomas paul.richard.thomas@gmail.com
Wed Nov 8 17:57:00 GMT 2006


:ADDPATCH fortran:

For once, I do not feel embarrassed by this type of PR: on Cygwin_NT, which I
used to develop the August round of patches, the compilation does not crash; it
just stops.  Since no errors are produced,  I proceeded on my merry
little way blissfully ignorant of the fact that there had been a
failure!

The reason that the testsuite does not pick it up on other systems is
that the test of the fix for PR19362 was moved to a subroutine, so
that other, connected aspects of association could be tested.  This
error only afflicts namespaces without a parent; eg. the main
programme.

The infinite loop comes about because, for other than derived types in
interfaces, the namespace of a proc_name is one and the same as the
namespace that owns the proc_name; ie. ns == ns->proc_name->ns.  This
being so, the namespace of the derived type is used to search for an
identical derived type. It rejects the same derived type in the search
but locks onto its renamed partner. Since this has no backend_decl, it
goes off and repeats the search... ad infinitum, or nearly so.  Why
compiler, running under Cygwin_NT stops silently, I do not know.

The ChangeLog comments adequately on the fix and the testcase is that
of PR19362, with nothing added.  Note that rather than identifying the
interface source, I have enforced ns != ns->proc_name->ns to directly
prevent the loop.

Regtests on Suse10.1/amd64 - OK for trunk, 4.2 and 4.1?

Thanks, Harald!

Paul

2006-11-08 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29744
	* trans-types.c (gfc_get_derived_type): Ensure that the
	proc_name namespace is not the same as the owner namespace and
	that identical derived types in the same namespace share the
	same backend_decl.

2006-11-08 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29744
	* gfortran.dg/used_types_12.f90: New test.
-------------- next part --------------
Index: gcc/fortran/trans-types.c
===================================================================
*** gcc/fortran/trans-types.c	(r?vision 118551)
--- gcc/fortran/trans-types.c	(copie de travail)
*************** gfc_get_derived_type (gfc_symbol * deriv
*** 1484,1490 ****
  	 build the parent version and use it in the current namespace.  */
        if (derived->ns->parent)
  	ns = derived->ns->parent;
!       else if (derived->ns->proc_name)
  	/* Derived types in an interface body obtain their parent reference
  	   through the proc_name symbol.  */
  	ns = derived->ns->proc_name->ns;
--- 1484,1491 ----
  	 build the parent version and use it in the current namespace.  */
        if (derived->ns->parent)
  	ns = derived->ns->parent;
!       else if (derived->ns->proc_name
! 		 && derived->ns->proc_name->ns != derived->ns)
  	/* Derived types in an interface body obtain their parent reference
  	   through the proc_name symbol.  */
  	ns = derived->ns->proc_name->ns;
*************** gfc_get_derived_type (gfc_symbol * deriv
*** 1591,1596 ****
--- 1592,1600 ----
  other_equal_dts:
    /* Add this backend_decl to all the other, equal derived types and
       their components in this and sibling namespaces.  */
+ 
+   for (dt = derived->ns->derived_types; dt; dt = dt->next)
+     copy_dt_decls_ifequal (derived, dt->derived);
  
    for (ns = derived->ns->sibling; ns; ns = ns->sibling)
      for (dt = ns->derived_types; dt; dt = dt->next)
Index: gcc/testsuite/gfortran.dg/used_types_12.f90
===================================================================
*** gcc/testsuite/gfortran.dg/used_types_12.f90	(r?vision 0)
--- gcc/testsuite/gfortran.dg/used_types_12.f90	(r?vision 0)
***************
*** 0 ****
--- 1,30 ----
+ ! { dg-do compile }
+ ! Tests the fix PR29744, which is really a repeat of PR19362.
+ ! The problem came about because the test for PR19362 shifted
+ ! the fix to a subroutine, rather than the main program that
+ ! it originally occurred in.  Fixes for subsequent PRs introduced
+ ! a difference between the main program and a contained procedure
+ ! that resulted in the compiler going into an infinite loop.
+ !
+ ! Contributed by Harald Anlauf  <anlauf@gmx.de>
+ ! and originally by Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org> 
+ !
+ MODULE M
+   TYPE T0
+     SEQUENCE
+     INTEGER I
+   END TYPE
+ END
+ 
+ PROGRAM MAIN
+   USE M, T1 => T0
+   TYPE T0
+     SEQUENCE
+     INTEGER I
+   END TYPE
+   TYPE(T0) :: BAR
+   TYPE(T1) :: BAZ
+   BAZ = BAR
+ END
+ ! { dg-final { cleanup-modules "M" } }
+ 
-------------- next part --------------
2006-11-08 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29744
	* trans-types.c (gfc_get_derived_type): Ensure that the
	proc_name namespace is not the same as the owner namespace and
	that identical derived types in the same namespace share the
	same backend_decl.

2006-11-08 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29744
	* gfortran.dg/used_types_12.f90: New test.


More information about the Gcc-patches mailing list