Bug 44064 - [OOP] ICE with file containing two modules and one program
[OOP] ICE with file containing two modules and one program
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.6.0
: P3 normal
: ---
Assigned To: janus
: ice-on-valid-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-05-10 17:11 UTC by PierreC
Modified: 2010-08-04 19:57 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.0
Known to fail:
Last reconfirmed: 2010-08-04 12:17:08


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description PierreC 2010-05-10 17:11:54 UTC
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
Comment 1 Dominique d'Humieres 2010-05-10 17:19:30 UTC
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
Comment 2 Dominique d'Humieres 2010-05-10 17:21:58 UTC
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
Comment 3 janus 2010-05-10 21:59:53 UTC
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).
Comment 4 Tobias Burnus 2010-05-11 07:23:45 UTC
(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)
Comment 5 janus 2010-05-15 20:02:24 UTC
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
Comment 6 janus 2010-05-17 21:02:54 UTC
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.
Comment 7 Mikael Morin 2010-07-29 11:23:02 UTC
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

Comment 8 Mikael Morin 2010-07-29 11:55:15 UTC
With the link error being tracked as PR44065, I'm tempted to say that this is a duplicate of PR42051.
Comment 9 Mikael Morin 2010-07-31 10:27:53 UTC
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

Comment 10 Mikael Morin 2010-08-02 15:31:08 UTC
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

Comment 11 janus 2010-08-04 12:17:08 UTC
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
Comment 12 Mikael Morin 2010-08-04 14:17:59 UTC
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

Comment 13 janus 2010-08-04 19:49:39 UTC
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 14 janus 2010-08-04 19:57:43 UTC
Comment #11 is fixed with r162879. I think we can finally close this one.
Comment 15 Mikael Morin 2010-08-05 21:08:53 UTC
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