Bug 24092

Summary: ICE in trans-types.c for nested derived types
Product: gcc Reporter: Paul Thomas <pault>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs
Priority: P2    
Version: 4.1.0   
Target Milestone: 4.0.3   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2005-09-28 09:21:56

Description Paul Thomas 2005-09-27 21:29:38 UTC
This module is taken from one of the Meissner tests and is the last to crash
with gfortran:

!  copyright 1996 Loren P. Meissner -- May be distributed if this line is included.
!  Linked List operations with Pointer to Pointer
   module llo
      type :: it
         character*10  :: k
         integer :: c(2)
      end type it
      type :: bt
         type (nt), pointer :: p
      end type bt
      type :: nt
         type (it) :: i
         type (bt) :: b
      end type nt
      type (bt), pointer :: ptr
   end module llo

produces

[prt@localhost meissner]# /gcc-4.1/bin/gfortran -c meissner21_mod.f90
meissner21_mod.f90:0: internal compiler error: in gfc_get_derived_type, at
fortran/trans-types.c:1459
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

A tentative fix is:

Index: gcc/gcc/fortran/trans-types.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-types.c,v
retrieving revision 1.50
diff -c -p -r1.50 trans-types.c
*** gcc/gcc/fortran/trans-types.c	29 Jul 2005 00:02:37 -0000	1.50
--- gcc/gcc/fortran/trans-types.c	27 Sep 2005 21:11:53 -0000
*************** gfc_get_derived_type (gfc_symbol * deriv
*** 1456,1463 ****
  
        DECL_PACKED (field) |= TYPE_PACKED (typenode);
  
!       gcc_assert (!c->backend_decl);
!       c->backend_decl = field;
      }
  
    /* Now we have the final fieldlist.  Record it, then lay out the
--- 1456,1465 ----
  
        DECL_PACKED (field) |= TYPE_PACKED (typenode);
  
!       /* It can happen that in partially built, nested derived
! 	 types that the component backend_decl already exists.  */
!       if (!c->backend_decl)
! 	c->backend_decl = field;
      }
  
    /* Now we have the final fieldlist.  Record it, then lay out the
Comment 1 GCC Commits 2005-10-12 20:41:34 UTC
Subject: Bug 24092

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pault@gcc.gnu.org	2005-10-12 20:41:29

Modified files:
	gcc/fortran    : trans-types.c ChangeLog 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: derived_pointer_recursion.f90 

Log message:
	2005-10-12  Paul Thomas  <pault@gcc.gnu.org>
	
	PR fortran/24092
	* trans-types.c (gfc_get_derived_type): Insert code to obtain backend
	declaration for derived types, building if necessary.  Return the
	derived type if the fields have been built by this process.  Otherwise,
	continue as before but using the already obtained backend_decls for the
	derived type components.  Change the gcc_assert to act on the field.
	
	2005-10-10  Paul Thomas  <pault@gcc.gnu.org>
	
	PR fortran/24092
	* gfortran.dg/derived_pointer_recursion.f90: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/trans-types.c.diff?cvsroot=gcc&r1=1.52&r2=1.53
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&r1=1.584&r2=1.585
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/derived_pointer_recursion.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6182&r2=1.6183

Comment 2 GCC Commits 2005-10-14 04:53:36 UTC
Subject: Bug 24092

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	pault@gcc.gnu.org	2005-10-14 04:53:30

Modified files:
	gcc/fortran    : symbol.c trans-types.c decl.c ChangeLog 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: automatic_char_len_1.f90 
	                           save_common.f90 save_result.f90 
	                           derived_pointer_recursion.f90 

Log message:
	2005-10-14  Paul Thomas  <pault@gcc.gnu.org>
	
	PR fortran/20847
	PR fortran/20856
	* symbol.c (check_conflict): Prevent common variables and
	function results from having the SAVE attribute,as required
	by the standard.
	
	PR fortran/24092
	* trans-types.c (gfc_get_derived_type): Insert code to obtain backend
	declaration for derived types, building if necessary.  Return the
	derived type if the fields have been built by this process.  Otherwise,
	continue as before but using the already obtained backend_decls for the
	derived type components.  Change the gcc_assert to act on the field.
	
	PR fortran/18082
	* decl.c (variable_decl): Make a new copy of the character
	length for each variable, when the expression is not a
	constant.
	
	2005-10-14  Paul Thomas  <pault@gcc.gnu.org>
	
	PR fortran/18082
	* gfortran.dg/automatic_char_len_1.f90: New test.
	
	PR fortran/20847
	* gfortran.dg/save_common.f90: New test.
	
	PR fortran/20856
	* gfortran.dg/save_result.f90: New test.
	
	PR fortran/24092
	* gfortran.dg/derived_pointer_recursion.f90: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/symbol.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.26.2.5&r2=1.26.2.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/trans-types.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.37.10.7&r2=1.37.10.8
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.31.2.4&r2=1.31.2.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.335.2.128&r2=1.335.2.129
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/automatic_char_len_1.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.4.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/save_common.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.2.4.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/save_result.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.2.4.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/derived_pointer_recursion.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.4.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.453&r2=1.5084.2.454

Comment 3 Andrew Pinski 2005-10-14 13:09:38 UTC
Fixed.
Comment 4 Paul Thomas 2005-10-14 16:38:02 UTC
Subject: Re:  ICE in trans-types.c for nested derived types

pinskia at gcc dot gnu dot org wrote:

>------- Comment #3 from pinskia at gcc dot gnu dot org  2005-10-14 13:09 -------
>Fixed.
>
>
>  
>
Andrew,

You keep hitting the PR's before I have a chance to do the honours - I 
had not forgotten but wait until I have done both the head and 4.0.  The 
recent stuff on PRIVATE etc. got delayed because it caused a secondary 
PR and I wanted to be sure that it was fixwed before shutting down the 
original.

Thanks, anyway!

Paul