As demonstrated below, having an "intent(out)" dummy argument with an unlimited polymorphic component generates an internal compiler error with a December 23 build of gfortran 4.8: $ cat ice_on_intent_out_with_unlimted.f90 type foo class(*), allocatable :: x end type contains subroutine bar(this) type(foo), intent(out) :: this end end $ gfortran ice_on_intent_out_with_unlimted.f90 ice_on_intent_out_with_unlimted.f90: In function 'bar': ice_on_intent_out_with_unlimted.f90:5:0: internal compiler error: Segmentation fault: 11 subroutine bar(this) ^ ice_on_intent_out_with_unlimted.f90:5:0: internal compiler error: Abort trap: 6 gfortran: internal compiler error: Abort trap: 6 (program f951) Abort trap: 6 $ gfortran --version GNU Fortran (MacPorts gcc48 4.8-20121223_0) 4.8.0 20121223 (experimental)
I think it's the same as PR55763 comment 10.
(In reply to comment #1) > I think it's the same as PR55763 comment 10. Seemingly not - at least with the patch from PR55763 comment 12, this example crashes in: #0 build_function_decl (sym=0x1658420, global=<optimized out>) at ../../gcc/fortran/trans-decl.c:1852 #1 0x0000000000613e37 in gfc_get_symbol_decl (sym=0x1658420) at ../../gcc/fortran/trans-decl.c:1370 The following assert fails for sym == "__copy_CLASS_0_": 1848 /* Allow only one nesting level. Allow public declarations. */ 1849 gcc_assert (current_function_decl == NULL_TREE 1850 || DECL_FILE_SCOPE_P (current_function_decl) 1851 || (TREE_CODE (DECL_CONTEXT (current_function_decl)) 1852 == NAMESPACE_DECL)); Here, "current_function_decl" is "function_decl bar.
The problem seems to be the "gfc_class_null_initializer", where "ts" is unlimited polymorphic and "init_expr" is of type "__class__$tar_a" (and EXPR_NULL). The latter leads to the generation of __vtab_CLASS_0_ with the associated _copy function. Besides the wrong type, the generation _copy is triggered very late, namely in gfc_trans_deferred_vars-> gfc_trans_structure_assign. That's the reason for using the wrong scope and - hence - for the ICE. Patch: --- a/gcc/fortran/class.c +++ b/gcc/fortran/class.c @@ -414,7 +414,7 @@ gfc_class_null_initializer (gfc_typespec *ts, gfc_expr *init_expr) && ts->u.derived->components->ts.u.derived->attr.unlimited_polymorphic; if (is_unlimited_polymorphic && init_expr) - vtab = gfc_find_intrinsic_vtab (&(init_expr->ts)); + vtab = gfc_find_intrinsic_vtab (&ts->u.derived->components->ts); else vtab = gfc_find_derived_vtab (ts->u.derived);
Apparently an ICE also occurs if the argument intent is removed but "type" is replaced by "class." See below. Is this fixed by the patch in comment 3? Damian $ cat ice_on_class_dummy_with_unlimited.f90 implicit none type foo class(*), allocatable :: bar end type contains integer function foobar(this) class(foo) :: this end function end $ gfortran ice_on_class_dummy_with_unlimited.f90 ice_on_class_dummy_with_unlimited.f90: In function 'MAIN__': ice_on_class_dummy_with_unlimited.f90:8:0: internal compiler error: Segmentation fault: 11 end function ^ ice_on_class_dummy_with_unlimited.f90:8:0: internal compiler error: Abort trap: 6 gfortran: internal compiler error: Abort trap: 6 (program f951) Abort trap: 6 $ gfortran --version GNU Fortran (MacPorts gcc48 4.8-20121223_0) 4.8.0 20121223 (experimental)
(In reply to comment #4) > Apparently an ICE also occurs if the argument intent is removed but "type" is > replaced by "class." See below. Is this fixed by the patch in comment 3? Seems to be fixed by the patch, which has been submitted at http://gcc.gnu.org/ml/fortran/2013-01/msg00017.html
Awesome -- thanks! Please let me know once this hits the trunk so I can request an update of the macports build and try it out. Damian (In reply to comment #5) > (In reply to comment #4) > > Apparently an ICE also occurs if the argument intent is removed but "type" is > > replaced by "class." See below. Is this fixed by the patch in comment 3? > > Seems to be fixed by the patch, which has been submitted at > http://gcc.gnu.org/ml/fortran/2013-01/msg00017.html
Author: burnus Date: Fri Jan 4 08:57:58 2013 New Revision: 194885 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194885 Log: 2013-01-03 Tobias Burnus <burnus@net-b.de> PR fortran/55854 PR fortran/55763 * class.c (gfc_class_null_initializer): Fix finding the vtab. (gfc_find_intrinsic_vtab): Use BT_VOID for some components. 2013-01-03 Tobias Burnus <burnus@net-b.de> PR fortran/55854 PR fortran/55763 * gfortran.dg/unlimited_polymorphic_3.f03: Remove invalid code. * gfortran.dg/unlimited_polymorphic_7.f90: New. * gfortran.dg/unlimited_polymorphic_8.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/unlimited_polymorphic_7.f90 trunk/gcc/testsuite/gfortran.dg/unlimited_polymorphic_8.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/class.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/unlimited_polymorphic_3.f03
FIXED on 4.8 trunk. Thanks for the report!