goto failure;
}
+ if (!code->expr3)
+ {
+ /* Set up default initializer if needed. */
+ gfc_typespec ts;
+
+ if (code->ext.alloc.ts.type == BT_DERIVED)
+ ts = code->ext.alloc.ts;
+ else
+ ts = e->ts;
+
+ if (ts.type == BT_CLASS)
+ ts = ts.u.derived->components->ts;
+
+ if (ts.type == BT_DERIVED)
+ {
+ code->expr3 = gfc_default_initializer (&ts);
+ gfc_resolve_expr (code->expr3);
+ }
+ }
+ else if (code->expr3->mold && code->expr3->ts.type == BT_DERIVED)
+ {
+ /* Default initialization via MOLD (non-polymorphic). */
+ gfc_expr *rhs = gfc_default_initializer (&code->expr3->ts);
+ gfc_resolve_expr (rhs);
+ gfc_free_expr (code->expr3);
+ code->expr3 = rhs;
+ }
+
if (e->ts.type == BT_CLASS)
{
/* Make sure the vtab symbol is present when
tmp = gfc_finish_block (&se.pre);
gfc_add_expr_to_block (&block, tmp);
- /* Initialization via SOURCE block. */
if (code->expr3 && !code->expr3->mold)
{
+ /* Initialization via SOURCE block
+ (or static default initializer). */
gfc_expr *rhs = gfc_copy_expr (code->expr3);
if (al->expr->ts.type == BT_CLASS)
{
gfc_free_expr (rhs);
gfc_add_expr_to_block (&block, tmp);
}
- else
+ else if (code->expr3 && code->expr3->mold
+ && code->expr3->ts.type == BT_CLASS)
{
- /* Add default initializer for those derived types that need them. */
- gfc_expr *rhs = NULL;
- gfc_typespec ts;
-
- if (code->ext.alloc.ts.type == BT_DERIVED)
- ts = code->ext.alloc.ts;
- else if (code->expr3)
- ts = code->expr3->ts;
- else
- ts = expr->ts;
-
- if (ts.type == BT_DERIVED)
- {
- rhs = gfc_default_initializer (&ts);
- gfc_resolve_expr (rhs);
- }
- else if (ts.type == BT_CLASS)
- {
- rhs = gfc_copy_expr (code->expr3);
- gfc_add_component_ref (rhs, "$vptr");
- gfc_add_component_ref (rhs, "$def_init");
- }
-
- if (rhs)
- {
- gfc_expr *lhs = gfc_expr_to_initialize (expr);
- if (al->expr->ts.type == BT_DERIVED)
- {
- tmp = gfc_trans_assignment (lhs, rhs, true, false);
- gfc_add_expr_to_block (&block, tmp);
- }
- else if (al->expr->ts.type == BT_CLASS)
- {
- gfc_se dst,src;
- gfc_init_se (&dst, NULL);
- gfc_init_se (&src, NULL);
- gfc_conv_expr (&dst, lhs);
- gfc_conv_expr (&src, rhs);
- gfc_add_block_to_block (&block, &src.pre);
- tmp = gfc_build_memcpy_call (dst.expr, src.expr, memsz);
- gfc_add_expr_to_block (&block, tmp);
- }
- gfc_free_expr (lhs);
- gfc_free_expr (rhs);
- }
+ /* Default-initialization via MOLD (polymorphic). */
+ gfc_expr *rhs = gfc_copy_expr (code->expr3);
+ gfc_se dst,src;
+ gfc_add_component_ref (rhs, "$vptr");
+ gfc_add_component_ref (rhs, "$def_init");
+ gfc_init_se (&dst, NULL);
+ gfc_init_se (&src, NULL);
+ gfc_conv_expr (&dst, expr);
+ gfc_conv_expr (&src, rhs);
+ gfc_add_block_to_block (&block, &src.pre);
+ tmp = gfc_build_memcpy_call (dst.expr, src.expr, memsz);
+ gfc_add_expr_to_block (&block, tmp);
+ gfc_free_expr (rhs);
}
/* Allocation of CLASS entities. */