https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79072
Bug ID: 79072 Summary: ICE with class(*) pointer function result and character value Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: neil.n.carlson at gmail dot com Target Milestone: --- This example gives an ICE with the current 7.0 trunk and all 6.x releases: function foo() class(*), pointer :: foo character(3), target :: string = 'foo' foo => string select type (foo) type is (character(*)) !print *, foo end select end function The ICE disappears if either: 1) type is (character(*)) is replaced with integer, for example; 2) the return variable is specified in a result(...) clause. In the original code that exhibited the compiler bug, the function returns correct values except for character values, so I expect the underlying problem involves the unlimited polymorphic pointer assignment statement and character dynamic types. I introduced the select type (which produced the ICE) when debugging. Here's the output from the compiler: $ gfortran -c code.f90 code.f90:1:0: function foo() internal compiler error: tree check: expected record_type or union_type or qual_union_type, have function_type in gfc_class_len_get, at fortran/trans-expr.c:226 0xe75f1c tree_check_failed(tree_node const*, char const*, int, char const*, ...) ../../gcc/tree.c:9814 0x6f03c5 tree_check3(tree_node*, char const*, int, char const*, tree_code, tree_code, tree_code) ../../gcc/tree.h:3100 0x6f03c5 gfc_class_len_get(tree_node*) ../../gcc/fortran/trans-expr.c:226 0x745cbc trans_associate_var ../../gcc/fortran/trans-stmt.c:1757 0x745cbc gfc_trans_block_construct(gfc_code*) ../../gcc/fortran/trans-stmt.c:1810 0x6ba467 trans_code ../../gcc/fortran/trans.c:1913 0x747c1e gfc_trans_select_type_cases ../../gcc/fortran/trans-stmt.c:2401 0x747c1e gfc_trans_select_type(gfc_code*) ../../gcc/fortran/trans-stmt.c:3112 0x6ba3d7 trans_code ../../gcc/fortran/trans.c:1933 0x745638 gfc_trans_block_construct(gfc_code*) ../../gcc/fortran/trans-stmt.c:1803 0x6ba467 trans_code ../../gcc/fortran/trans.c:1913 0x6eb598 gfc_generate_function_code(gfc_namespace*) ../../gcc/fortran/trans-decl.c:6292 0x672f76 translate_all_program_units ../../gcc/fortran/parse.c:6008 0x672f76 gfc_parse_file() ../../gcc/fortran/parse.c:6208 0x6b6512 gfc_be_parse_file ../../gcc/fortran/f95-lang.c:202 Please submit a full bug report,