The following code (minus the IF condition) shows that _vptr is not set for the allocatable component: y.x._data = 0B; there should be - but isn't - additionally: y.x._vptr = &__vtab_m_T; Additionally, the test case as is (with IF condition), currently crashes with: internal compiler error: in gfc_conv_component_ref, at fortran/trans-expr.c:1654 if (.not. same_type_as(y%x, z)) call abort () ^ 0x632ce2 gfc_conv_component_ref ../../gcc/fortran/trans-expr.c:1654 0x63fc89 gfc_conv_variable ../../gcc/fortran/trans-expr.c:1921 module m type t end type t type t2 integer :: ii class(t), allocatable :: x end type t2 contains subroutine fini(x) type(t) :: x end subroutine fini end module m use m block type(t) :: z type(t2) :: y y%ii = 123 if (.not. same_type_as(y%x, z)) call abort () end block end
Confirmed.
(In reply to Tobias Burnus from comment #0) > The following code (minus the IF condition) shows that _vptr is not set for > the allocatable component: > y.x._data = 0B; > there should be - but isn't - additionally: y.x._vptr = &__vtab_m_T; Without the BLOCK, the dump shows: static struct t2 y = {.x={._vptr=&__vtab_m_T}}; y.x._data = 0B; y.ii = 123; while with the BLOCK one gets: struct t2 y; try { y.x._data = 0B; y.ii = 123; L.1:; } Can't we do a 'static' initialization (of _vptr *and* _data) in both cases? As in struct t2 y = {.x={._vptr=&__vtab_m_T,._data = 0B}} For this gfc_class_null_initializer (from class.c) could be used ...
(In reply to Tobias Burnus from comment #0) > Additionally, the test case as is (with IF condition), currently crashes > with: > > internal compiler error: in gfc_conv_component_ref, at > fortran/trans-expr.c:1654 Also the ICE occurs only with the BLOCK construct. Slightly reduced test case: module m type t end type type t2 class(t), allocatable :: x end type end module use m type(t) :: z block type(t2) :: y if (.not. same_type_as(y%x, z)) call abort () end block end
(In reply to janus from comment #2) > Can't we do a 'static' initialization (of _vptr *and* _data) in both cases? > As in > > struct t2 y = {.x={._vptr=&__vtab_m_T,._data = 0B}} > > For this gfc_class_null_initializer (from class.c) could be used ... ... we would just have to enable this for the BLOCK case in gfc_get_symbol decl. However, I'm not sure if this is really the way to go. Otherwise, one should do the (non-static) initialization of the _vptr via gfc_nullify_alloc_comp.
(In reply to janus from comment #2) > Can't we do a 'static' initialization (of _vptr *and* _data) in both cases? Well, you need to free and finalize the variable - hence, it cannot be static.
Fixed in r10-6801-g61c8d9e4e5f540501eaa98aae1d6c74bde7d4299 Thanks for the report. Paul