The following testcase segfaults in 4.6: module module_myclass implicit none type :: inner contains procedure :: set end type inner type :: myclass type(inner) :: slice end type myclass contains subroutine set(this) class(inner), intent(inout) :: this end subroutine set end module module_myclass module module_mysubclass use module_myclass, only : myclass implicit none type, extends(myclass) :: mysubclass contains procedure :: init end type mysubclass contains subroutine init(this) class(mysubclass), intent(inout) :: this call this%slice%set() ! XXX PROBLEM HERE this%slice not resolved end subroutine init end module module_mysubclass program test use module_mysubclass, only : mysubclass implicit none class(mysubclass), allocatable :: obs end program test
On x86_64-apple-darwin10 at revision 159234 (+ a few patches) I get: [macbook] f90/bug% gfc pr44064.f90 Undefined symbols: "_vtab$inner.1583", referenced from: ___module_mysubclass_MOD_init in cc4CUNex.o ___module_mysubclass_MOD_init in cc4CUNex.o ___module_mysubclass_MOD_init in cc4CUNex.o ld: symbol(s) not found collect2: ld returned 1 exit status
On powerpc-apple-darwin9 at revision 159191 (without gfortran patch) I get: [karma] f90/bug% gfc pr44064.f90 /var/tmp//ccpUV3i0.s:65:non-relocatable subtraction expression, "_vtab$inner.1183" minus "L00000000001$pb" /var/tmp//ccpUV3i0.s:65:symbol: "_vtab$inner.1183" can't be undefined in a subtraction expression /var/tmp//ccpUV3i0.s:63:non-relocatable subtraction expression, "_vtab$inner.1183" minus "L00000000001$pb" /var/tmp//ccpUV3i0.s:63:symbol: "_vtab$inner.1183" can't be undefined in a subtraction expression /var/tmp//ccpUV3i0.s:57:non-relocatable subtraction expression, "_vtab$inner.1183" minus "L00000000001$pb" /var/tmp//ccpUV3i0.s:57:symbol: "_vtab$inner.1183" can't be undefined in a subtraction expression /var/tmp//ccpUV3i0.s:55:non-relocatable subtraction expression, "_vtab$inner.1183" minus "L00000000001$pb" /var/tmp//ccpUV3i0.s:55:symbol: "_vtab$inner.1183" can't be undefined in a subtraction expression /var/tmp//ccpUV3i0.s:50:non-relocatable subtraction expression, "_vtab$inner.1183" minus "L00000000001$pb" /var/tmp//ccpUV3i0.s:50:symbol: "_vtab$inner.1183" can't be undefined in a subtraction expression /var/tmp//ccpUV3i0.s:48:non-relocatable subtraction expression, "_vtab$inner.1183" minus "L00000000001$pb" /var/tmp//ccpUV3i0.s:48:symbol: "_vtab$inner.1183" can't be undefined in a subtraction expression
For me, compiling the code in comment #0 in a single file seems to get stuck in an endless loop (trunk rev. 159217 on x86_64-unknown-linux-gnu).
(Cross reference: PR 44065 is the same, except using two files, which leads to a linking error instead of an ICE.) I get - as written at http://gcc.gnu.org/ml/fortran/2010-05/msg00099.html: hjf.f90:37:0: internal compiler error: Segmentation fault (37 is the XXX line.) valgrind shows: ==17205== Invalid read of size 8 ==17205== at 0x53F166: gfc_delete_symtree (symbol.c:2374) ==17205== by 0x540176: gfc_undo_symbols (symbol.c:2845) ==17205== by 0x510786: decode_statement (parse.c:271) ==17205== by 0x511C8C: next_statement (parse.c:722) ==17205== by 0x5155DB: gfc_parse_file (parse.c:4220) ==17205== by 0x54CB27: gfc_be_parse_file (f95-lang.c:239) ==17205== by 0x8383A2: toplev_main (toplev.c:1053) ==17205== by 0x5EA1B7C: (below main) (in /lib64/libc-2.11.1.so)
Here is a slightly reduced test case: module module_myclass implicit none type :: inner contains procedure :: set end type type :: myclass type(inner) :: slice end type contains subroutine set(this) class(inner), intent(inout) :: this end subroutine set end module module_myclass module module_mysubclass use module_myclass, only : myclass implicit none contains subroutine init(this) class(myclass), intent(inout) :: this call this%slice%set() ! XXX PROBLEM HERE end subroutine init end module module_mysubclass program test use module_mysubclass implicit none end program For this I get a segfault with the following backtrace: Program received signal SIGSEGV, Segmentation fault. 0x0000000000550bb7 in gfc_find_symtree (st=0x1711, name=0x7ffff7f2aec0 "vtype$inner") at /home/jweil/gcc46/trunk/gcc/fortran/symbol.c:2393 2393 c = strcmp (name, st->name); (gdb) bt #0 0x0000000000550bb7 in gfc_find_symtree (st=0x1711, name=0x7ffff7f2aec0 "vtype$inner") at /home/jweil/gcc46/trunk/gcc/fortran/symbol.c:2393 #1 0x0000000000550b62 in gfc_delete_symtree (root=0x17af7e0, name=0x7ffff7f2aec0 "vtype$inner") at /home/jweil/gcc46/trunk/gcc/fortran/symbol.c:2374 #2 0x00000000005517bd in gfc_undo_symbols () at /home/jweil/gcc46/trunk/gcc/fortran/symbol.c:2845 #3 0x00000000005139fd in decode_statement () at /home/jweil/gcc46/trunk/gcc/fortran/parse.c:271 #4 0x000000000051522c in next_free () at /home/jweil/gcc46/trunk/gcc/fortran/parse.c:722 #5 0x00000000005155fc in next_statement () at /home/jweil/gcc46/trunk/gcc/fortran/parse.c:907 #6 0x000000000051999d in gfc_parse_file () at /home/jweil/gcc46/trunk/gcc/fortran/parse.c:4220 #7 0x000000000055a36b in gfc_be_parse_file (set_yydebug=0) at /home/jweil/gcc46/trunk/gcc/fortran/f95-lang.c:239 #8 0x0000000000a1539f in compile_file () at /home/jweil/gcc46/trunk/gcc/toplev.c:1049 #9 0x0000000000a1769d in do_compile () at /home/jweil/gcc46/trunk/gcc/toplev.c:2393 #10 0x0000000000a17773 in toplev_main (argc=2, argv=0x7fffffffe2f8) at /home/jweil/gcc46/trunk/gcc/toplev.c:2435 #11 0x00000000005e262c in main (argc=2, argv=0x7fffffffe2f8) at /home/jweil/gcc46/trunk/gcc/main.c:35
Another slight variation: module module_myclass implicit none type :: inner contains procedure :: set end type type :: myclass type(inner) :: slice end type contains subroutine set(this) class(inner) :: this end subroutine end module module module_mysubclass use module_myclass, only : myclass implicit none contains subroutine init() type(myclass) :: this call this%slice%set() ! XXX PROBLEM HERE end subroutine end module program test end For this I get: /tmp/ccsEnCku.o: In function `__module_mysubclass_MOD_init': c5.f90:(.text+0x15): undefined reference to `vtab$inner.1570' c5.f90:(.text+0x21): undefined reference to `vtab$inner.1570' c5.f90:(.text+0x2a): undefined reference to `vtab$inner.1570' I have no clue about the origin of this PR's failures yet, though I suspect they're somehow related to the "use, only" clause. Removing the "only" kills the errors.
Subject: Bug 44064 Author: mikael Date: Thu Jul 29 11:22:40 2010 New Revision: 162674 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162674 Log: 2010-07-29 Mikael Morin <mikael@gcc.gnu.org> PR fortran/42051 PR fortran/44064 * class.c (gfc_find_derived_vtab): Accept or discard newly created symbols before returning. 2010-07-29 Mikael Morin <mikael@gcc.gnu.org> PR fortran/42051 PR fortran/44064 * gfortran.dg/pr42051.f03: New testcase. Added: trunk/gcc/testsuite/gfortran.dg/pr42051.f03 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/class.c trunk/gcc/testsuite/ChangeLog
With the link error being tracked as PR44065, I'm tempted to say that this is a duplicate of PR42051.
Subject: Bug 44064 Author: mikael Date: Sat Jul 31 10:27:36 2010 New Revision: 162776 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162776 Log: 2010-07-31 Mikael Morin <mikael@gcc.gnu.org> PR fortran/42051 PR fortran/44064 * symbol.c (changed_syms): Made non-static. * parse.c (changed_syms): Declare new external. (next_statement): Assert changed_syms is NULL at the beginning. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/parse.c trunk/gcc/fortran/symbol.c
Subject: Bug 44064 Author: mikael Date: Mon Aug 2 15:30:47 2010 New Revision: 162821 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162821 Log: 2010-08-02 Mikael Morin <mikael@gcc.gnu.org> Janus Weil <janus@gcc.gnu.org> PR fortran/42051 PR fortran/44064 PR fortran/45151 * intrinsic.c (gfc_get_intrinsic_sub_symbol): Commit changed symbol. * symbol.c (gen_cptr_param, gen_fptr_param, gen_shape_param, gfc_copy_formal_args, gfc_copy_formal_args_intr, gfc_copy_formal_args_ppc, generate_isocbinding_symbol): Ditto. * parse.c (parse_derived_contains, parse_spec, parse_progunit): Call reject_statement in case of error. (match_deferred_characteritics): Call gfc_undo_symbols in case match fails. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/intrinsic.c trunk/gcc/fortran/parse.c trunk/gcc/fortran/symbol.c
At r162860, I see only one problem left: A linker error (undefined reference to `vtab$inner.1582') on the following variation of comment #5/#6: module module_myclass implicit none type :: inner contains procedure :: set end type type :: myclass type(inner) :: slice end type contains subroutine set(this) class(inner) :: this end subroutine end module module module_mysubclass implicit none integer :: shit = 5 contains subroutine init() use module_myclass, only : myclass type(myclass) :: this call this%slice%set() ! XXX PROBLEM HERE shit = shit + 1 end subroutine end module program test end
Subject: Bug 44064 Author: mikael Date: Wed Aug 4 14:17:31 2010 New Revision: 162865 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162865 Log: 2010-08-04 Mikael Morin <mikael@gcc.gnu.org> PR fortran/42051 PR fortran/44064 * symbol.c (changed_syms): Made static again. (gfc_symbol_state): Don't conditionalize on GFC_DEBUG. Changed conditional internal error into assert. Rename function to ... (gfc_enforce_clean_symbol_state): ... this. * gfortran.h (gfc_symbol_state, gfc_enforce_clean_symbol_state): Rename the former to the latter. * parse.c (decode_statement, decode_omp_directive, decode_gcc_attribute): Update callers accordingly. Don't conditionalize on GFC_DEBUG. (changed_syms): Remove declaration. (next_statement): Use gfc_enforce_clean_symbol_state. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/parse.c trunk/gcc/fortran/symbol.c
Subject: Bug 44064 Author: janus Date: Wed Aug 4 19:49:19 2010 New Revision: 162879 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162879 Log: 2010-08-04 Janus Weil <janus@gcc.gnu.org> PR fortran/42207 PR fortran/44064 PR fortran/44065 * class.c (gfc_find_derived_vtab): Do not generate vtabs for class container types. Do not artificially increase refs. Commit symbols one by one. * interface.c (compare_parameter): Make sure vtabs are present before generating module variables. * resolve.c (resolve_allocate_expr): Ditto. 2010-08-04 Janus Weil <janus@gcc.gnu.org> PR fortran/42207 PR fortran/44064 PR fortran/44065 * gfortran.dg/class_25.f03: New. * gfortran.dg/class_26.f03: New. Added: trunk/gcc/testsuite/gfortran.dg/class_25.f03 trunk/gcc/testsuite/gfortran.dg/class_26.f03 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/class.c trunk/gcc/fortran/interface.c trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog
Comment #11 is fixed with r162879. I think we can finally close this one.
Subject: Bug 44064 Author: mikael Date: Thu Aug 5 21:08:36 2010 New Revision: 162921 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162921 Log: 2010-08-05 Mikael Morin <mikael@gcc.gnu.org> Janus Weil <janus@gcc.gnu.org> PR fortran/42051 PR fortran/44064 PR fortran/45151 * intrinsic.c (gfc_get_intrinsic_sub_symbol): Commit changed symbol. * symbol.c (gen_cptr_param, gen_fptr_param, gen_shape_param, gfc_copy_formal_args, gfc_copy_formal_args_intr, gfc_copy_formal_args_ppc, generate_isocbinding_symbol): Ditto. (gfc_find_derived_vtab): Commit newly created symbols. * parse.c (parse_derived_contains, parse_spec, parse_progunit): Call reject_statement in case of error. (match_deferred_characteritics): Call gfc_undo_symbols in case match fails. Modified: branches/gcc-4_5-branch/gcc/fortran/ChangeLog branches/gcc-4_5-branch/gcc/fortran/intrinsic.c branches/gcc-4_5-branch/gcc/fortran/parse.c branches/gcc-4_5-branch/gcc/fortran/symbol.c