Reported by Satish.BD at http://gcc.gnu.org/ml/fortran/2010-07/msg00059.html The shown (cf. URL) program compiles without any errors, but segfaults when at run time. Two of my other compiles diagnosed the following failure (gfortran not): - In line 220, the access to tst_case => self%list requires a TARGET attribute for "self" (which is not diagnosed in gfortran). Ditto for lines 231 and 245. One compiler additionally complained that for - call suite%add("first_test", test_a) and call self%assert(1,2, 1233 , "generic_tbp.f90", "purposely failed") no specific subprogram could be found (I have not checked this) The other compiler, compiles and the resulting program does not segfault but prints: FFFF We have 4 failure(s). 1) first_test: generic_tbp.f90:1233 purposely failed: expected < 1> but was < 2> 2) second_test: generic_tbp.f90: 324 purposely passed: expected < 3.50000000E+00> but was < 2.67499995E+00> 3) third_test: generic_tbp.f90:1233 purposely failed: expected < 1> but was < 2> 4) last_test: generic_tbp.f90: 324 purposely passed: expected < 3.50000000E+00> but was < 2.67499995E+00> !!! FAILURES !!! Runs: 4 Passes: 0 Fails: 4
Created attachment 21139 [details] Test case (without TARGET; corrected line breaks from the mail paste) For the error recovery (first mail in the thread), see PR 44868
If one removes the comment from the line marked with "Uncomment this for the crash to occur" gfortran gives an ICE: call tst%init() !! Uncomment this for the crash to occur 1 Error: Found no matching specific binding for the call to the GENERIC 'init' at (1) bd.f90:68:0: internal compiler error: Segmentation fault
Reduced test case: type :: test_case end type type :: test_suite type(test_case) :: list end type contains subroutine sub(self) class(test_suite), intent(inout) :: self type(test_case), pointer :: tst_case tst_case => self%list end subroutine end If one changes the CLASS into a TYPE, the correct error message appears: tst_case => self%list 1 Error: Pointer assignment target is neither TARGET nor POINTER at (1)
Here is a fix for the target problem: Index: gcc/fortran/primary.c =================================================================== --- gcc/fortran/primary.c (revision 162010) +++ gcc/fortran/primary.c (working copy) @@ -1999,7 +1999,7 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *t if (sym->ts.type == BT_CLASS) { dimension = CLASS_DATA (sym)->attr.dimension; - pointer = CLASS_DATA (sym)->attr.pointer; + pointer = CLASS_DATA (sym)->attr.class_pointer; allocatable = CLASS_DATA (sym)->attr.allocatable; } else @@ -2059,7 +2059,7 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *t if (comp->ts.type == BT_CLASS) { - pointer = CLASS_DATA (comp)->attr.pointer; + pointer = CLASS_DATA (comp)->attr.class_pointer; allocatable = CLASS_DATA (comp)->attr.allocatable; } else @@ -2109,7 +2109,7 @@ gfc_expr_attr (gfc_expr *e) if (sym->ts.type == BT_CLASS) { attr.dimension = CLASS_DATA (sym)->attr.dimension; - attr.pointer = CLASS_DATA (sym)->attr.pointer; + attr.pointer = CLASS_DATA (sym)->attr.class_pointer; attr.allocatable = CLASS_DATA (sym)->attr.allocatable; } }
The patch in comment #4 regresses on select_type_4.f90 in the test suite.
The TARGET check is fixed by r162052: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162052 The runtime segfault persist.
(In reply to comment #6) > The runtime segfault persist. It seems this segfault comes from the call to 'self%assert' in 'test_a'. The dump shows self->$vptr->assert->assert_int ((struct class$test_case *) self, &C.1978, &C.1979, &C.1980, &"generic_tbp.f90"[1]{lb: 1 sz: 1}, &"purposely failed"[1]{lb: 1 sz: 1}, 15, 16); which looks ok. The problem seems to be that the generic TBPs in the vtab are not initialized properly. The dump contains the correct initialization code for the specific TBPs, but the init for the generics seems to be missing.
Subject: Bug 44869 Author: janus Date: Tue Jul 13 06:57:17 2010 New Revision: 162125 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162125 Log: 2010-07-13 Janus Weil <janus@gcc.gnu.org> PR fortran/44434 PR fortran/44565 PR fortran/43945 PR fortran/44869 * gfortran.h (gfc_find_derived_vtab): Modified prototype. * class.c (gfc_build_class_symbol): Modified call to 'gfc_find_derived_vtab'. (add_proc_component): Removed, moved code into 'add_proc_comp'. (add_proc_comps): Renamed to 'add_proc_comp', removed treatment of generics. (add_procs_to_declared_vtab1): Removed unnecessary argument 'resolved'. Removed treatment of generics. (copy_vtab_proc_comps): Removed unnecessary argument 'resolved'. Call 'add_proc_comp' instead of duplicating code. (add_procs_to_declared_vtab): Removed unnecessary arguments 'resolved' and 'declared'. (add_generic_specifics,add_generics_to_declared_vtab): Removed. (gfc_find_derived_vtab): Removed unnecessary argument 'resolved'. Removed treatment of generics. * iresolve.c (gfc_resolve_extends_type_of): Modified call to 'gfc_find_derived_vtab'. * resolve.c (resolve_typebound_function,resolve_typebound_subroutine): Removed treatment of generics. (resolve_select_type,resolve_fl_derived): Modified call to 'gfc_find_derived_vtab'. * trans-decl.c (gfc_get_symbol_decl): Ditto. * trans-expr.c (gfc_conv_derived_to_class,gfc_trans_class_assign): Ditto. * trans-stmt.c (gfc_trans_allocate): Ditto. 2010-07-13 Janus Weil <janus@gcc.gnu.org> PR fortran/44434 PR fortran/44565 PR fortran/43945 PR fortran/44869 * gfortran.dg/dynamic_dispatch_1.f03: Fixed invalid test case. * gfortran.dg/dynamic_dispatch_2.f03: Ditto. * gfortran.dg/dynamic_dispatch_3.f03: Ditto. * gfortran.dh/typebound_call_16.f03: New. * gfortran.dg/typebound_generic_6.f03: New. * gfortran.dg/typebound_generic_7.f03: New. * gfortran.dg/typebound_generic_8.f03: New. Added: trunk/gcc/testsuite/gfortran.dg/typebound_call_16.f03 trunk/gcc/testsuite/gfortran.dg/typebound_generic_6.f03 trunk/gcc/testsuite/gfortran.dg/typebound_generic_7.f03 trunk/gcc/testsuite/gfortran.dg/typebound_generic_8.f03 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/class.c trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/iresolve.c trunk/gcc/fortran/resolve.c trunk/gcc/fortran/trans-decl.c trunk/gcc/fortran/trans-expr.c trunk/gcc/fortran/trans-stmt.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/dynamic_dispatch_1.f03 trunk/gcc/testsuite/gfortran.dg/dynamic_dispatch_2.f03 trunk/gcc/testsuite/gfortran.dg/dynamic_dispatch_3.f03
Close as FIXED. Thanks Janus for the fix and thanks to Satish.BD for the bug report.