https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53298
--- Comment #14 from markeggleston at gcc dot gnu.org --- The test case in comment 7 proved trickier to track down. The ICE occurs in this code: /* Components can correspond to fields of different containing types, as components are created without context, whereas a concrete use of a component has the type of decl as context. So, if the type doesn't match, we search the corresponding FIELD_DECL in the parent type. To not waste too much time we cache this result in norestrict_decl. On the other hand, if the context is a UNION or a MAP (a RECORD_TYPE within a UNION_TYPE) always use the given FIELD_DECL. */ if (context != TREE_TYPE (decl) && !( TREE_CODE (TREE_TYPE (field)) == UNION_TYPE /* Field is union */ || TREE_CODE (context) == UNION_TYPE)) /* Field is map */ { tree f2 = c->norestrict_decl; if (!f2 || DECL_FIELD_CONTEXT (f2) != TREE_TYPE (decl)) ==> for (f2 = TYPE_FIELDS (TREE_TYPE (decl)); f2; f2 = DECL_CHAIN (f2)) if (TREE_CODE (f2) == FIELD_DECL && DECL_NAME (f2) == DECL_NAME (field)) break; gcc_assert (f2); c->norestrict_decl = f2; field = f2; } The ICE occurs at the line marked with ==>, the assignment f2 = TYPE_FIELDS (TREE_TYPE (decl)) hides a call to a routine that returns a null pointer which is then used causing the ICE. I speculated that the code dealing with f2 should not have been executed. I noted that in the comments "On the other hand, if the context is a UNION or a MAP (a RECORD_TYPE within a UNION_TYPE) always use the given FIELD_DECL." This does not match the code that follows. The following change: trans-expr.c @@ -2474,8 +2474,8 @@ gfc_conv_component_ref (gfc_se * se, gfc_ref * ref) RECORD_TYPE within a UNION_TYPE) always use the given FIELD_DECL. */ if (context != TREE_TYPE (decl) - && !( TREE_CODE (TREE_TYPE (field)) == UNION_TYPE /* Field is union */ - || TREE_CODE (context) == UNION_TYPE)) /* Field is map */ + && ( TREE_CODE (context) == UNION_TYPE /* Field is union */ + || TREE_CODE (context) == MAP_TYPE)) /* Field is map */ { tree f2 = c->norestrict_decl; if (!f2 || DECL_FIELD_CONTEXT (f2) != TREE_TYPE (decl)) matches the comment and also fixes the ICE for the test case in comment 7. make -j 8 check-fortran was looking good until test case failures were reported for: gfortran.dg/finalize_35.f90 gfortran.dg/finalize_36.f90