https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64209
--- Comment #5 from janus at gcc dot gnu.org --- (In reply to janus from comment #4) > The following patch is sufficient to make the reduced test case in comment 2 > work: ... but unfortunately it caused a number of testsuite regressions. The following variant is clean: Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (Revision 218874) +++ gcc/fortran/trans-expr.c (Arbeitskopie) @@ -943,7 +943,7 @@ tree gfc_trans_class_init_assign (gfc_code *code) { stmtblock_t block; - tree tmp; + tree tmp, cond; gfc_se dst,src,memsz; gfc_expr *lhs, *rhs, *sz; @@ -980,6 +980,12 @@ gfc_trans_class_init_assign (gfc_code *code) src.expr = gfc_build_addr_expr (NULL_TREE, src.expr); tmp = gfc_build_memcpy_call (dst.expr, src.expr, memsz.expr); + + cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node, + src.expr, fold_convert (TREE_TYPE (src.expr), + null_pointer_node)); + tmp = build3_loc (input_location, COND_EXPR, TREE_TYPE (tmp), cond, tmp, + build_empty_stmt (input_location)); } if (code->expr1->symtree->n.sym->attr.optional Still, it does not cure the segfault in comment 0.