===================================================================
@@ -912,7 +912,8 @@ gfc_trans_class_array_init_assign (gfc_expr *rhs,
gfc_actual_arglist *actual;
gfc_expr *ppc;
gfc_code *ppc_code;
- tree res;
+ tree res, cond;
+ gfc_se src;
actual = gfc_get_actual_arglist ();
actual->expr = gfc_copy_expr (rhs);
@@ -932,6 +933,16 @@ gfc_trans_class_array_init_assign (gfc_expr *rhs,
of arrays in gfc_trans_call. */
res = gfc_trans_call (ppc_code, false, NULL, NULL, false);
gfc_free_statements (ppc_code);
+
+ gfc_init_se (&src, NULL);
+ gfc_conv_expr (&src, rhs);
+ src.expr = gfc_build_addr_expr (NULL_TREE, src.expr);
+ cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
+ src.expr, fold_convert (TREE_TYPE (src.expr),
+ null_pointer_node));
+ res = build3_loc (input_location, COND_EXPR, TREE_TYPE (res), cond, res,
+ build_empty_stmt (input_location));
+
return res;
}
@@ -943,7 +954,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 +991,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