https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65889
Bug ID: 65889 Summary: ICE on invalid(?) with sizeof polymorphic variable [OOP] Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: abensonca at gmail dot com The following testcase causes an ICE with gfortran 6.0 (r222432): module m type n end type n contains subroutine g(ns) class(n), intent(out), allocatable, dimension(:) :: ns write (0,*) sizeof(ns) end subroutine g end module m $ gfortran -v Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/nfs/17/cond0061/Galacticus/Tools/libexec/gcc/x86_64-unknown-linux-gnu/6.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-trunk/configure --prefix=/nfs/17/cond0061/Galacticus/Tools --enable-languages=c,c++,fortran --disable-multilib Thread model: posix gcc version 6.0.0 20150424 (experimental) (GCC) $ gfortran -c small.f90 -o small.o small.f90:7:0: write (0,*) sizeof(ns) 1 internal compiler error: tree check: expected tree that contains ‘decl common’ structure, have ‘indirect_ref’ in gfc_conv_intrinsic_sizeof, at fortran/trans-intrinsic.c:5928 0xdd8994 tree_contains_struct_check_failed(tree_node const*, tree_node_structure_enum, char const*, int, char const*) ../../gcc-trunk/gcc/tree.c:9471 0x706628 contains_struct_check(tree_node*, tree_node_structure_enum, char const*, int, char const*) ../../gcc-trunk/gcc/tree.h:2960 0x706628 gfc_conv_intrinsic_sizeof ../../gcc-trunk/gcc/fortran/trans-intrinsic.c:5928 0x70e24f gfc_conv_intrinsic_function(gfc_se*, gfc_expr*) ../../gcc-trunk/gcc/fortran/trans-intrinsic.c:8185 0x6ece32 gfc_conv_expr(gfc_se*, gfc_expr*) ../../gcc-trunk/gcc/fortran/trans-expr.c:7361 0x6f3685 gfc_conv_expr_reference(gfc_se*, gfc_expr*) ../../gcc-trunk/gcc/fortran/trans-expr.c:7496 0x7150c1 gfc_trans_transfer(gfc_code*) ../../gcc-trunk/gcc/fortran/trans-io.c:2394 0x6b18d7 trans_code ../../gcc-trunk/gcc/fortran/trans.c:1885 0x7121b0 build_dt ../../gcc-trunk/gcc/fortran/trans-io.c:1921 0x6b18f7 trans_code ../../gcc-trunk/gcc/fortran/trans.c:1857 0x6de1df gfc_generate_function_code(gfc_namespace*) ../../gcc-trunk/gcc/fortran/trans-decl.c:5896 0x6b6149 gfc_generate_module_code(gfc_namespace*) ../../gcc-trunk/gcc/fortran/trans.c:2053 0x66e3ad translate_all_program_units ../../gcc-trunk/gcc/fortran/parse.c:5328 0x66e3ad gfc_parse_file() ../../gcc-trunk/gcc/fortran/parse.c:5538 0x6ae745 gfc_be_parse_file ../../gcc-trunk/gcc/fortran/f95-lang.c:228 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions. It's not clear to me if this is invalid code - see the discussion for PR57305 on how SIZEOF() should work on variables without a declared type. I checked that the testcase for PR57305 still compiles successfully. Wrapping the call to SIZEOF() inside a "SELECT TYPE" block removes the ICE. Replacing SIZEOF() with STORAGE_SIZE() (as suggested in PR57305) results in a slightly different backtrace: $ gfortran -c small.f90 -o small.o small.f90:7:0: write (0,*) storage_size(ns) 1 internal compiler error: Segmentation fault 0xb7572f crash_signal ../../gcc-trunk/gcc/toplev.c:383 0x70689e gfc_conv_intrinsic_storage_size ../../gcc-trunk/gcc/fortran/trans-intrinsic.c:6067 0x70e8b9 gfc_conv_intrinsic_function(gfc_se*, gfc_expr*) ../../gcc-trunk/gcc/fortran/trans-intrinsic.c:8189 0x6ece32 gfc_conv_expr(gfc_se*, gfc_expr*) ../../gcc-trunk/gcc/fortran/trans-expr.c:7361 0x6f3685 gfc_conv_expr_reference(gfc_se*, gfc_expr*) ../../gcc-trunk/gcc/fortran/trans-expr.c:7496 0x7150c1 gfc_trans_transfer(gfc_code*) ../../gcc-trunk/gcc/fortran/trans-io.c:2394 0x6b18d7 trans_code ../../gcc-trunk/gcc/fortran/trans.c:1885 0x7121b0 build_dt ../../gcc-trunk/gcc/fortran/trans-io.c:1921 0x6b18f7 trans_code ../../gcc-trunk/gcc/fortran/trans.c:1857 0x6de1df gfc_generate_function_code(gfc_namespace*) ../../gcc-trunk/gcc/fortran/trans-decl.c:5896 0x6b6149 gfc_generate_module_code(gfc_namespace*) ../../gcc-trunk/gcc/fortran/trans.c:2053 0x66e3ad translate_all_program_units ../../gcc-trunk/gcc/fortran/parse.c:5328 0x66e3ad gfc_parse_file() ../../gcc-trunk/gcc/fortran/parse.c:5538 0x6ae745 gfc_be_parse_file ../../gcc-trunk/gcc/fortran/f95-lang.c:228 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions.