Hi Mikael, > > diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c > > index cf607d0..402d9b9 100644 > > --- a/gcc/fortran/trans-expr.c > > +++ b/gcc/fortran/trans-expr.c > > @@ -6881,6 +6881,30 @@ alloc_scalar_allocatable_for_subcomponent_assignment > > (stmtblock_t *block, TREE_TYPE (tmp), tmp, > > fold_convert (TREE_TYPE (tmp), > > size)); } > > + else if (cm->ts.type == BT_CLASS) > > + { > > + gcc_assert (expr2->ts.type == BT_CLASS || expr2->ts.type == > > BT_DERIVED); > > + if (expr2->ts.type == BT_DERIVED) > > + { > > + tmp = gfc_get_symbol_decl (gfc_find_vtab (&expr2->ts)); > > + tmp = gfc_build_addr_expr (NULL_TREE, tmp); > > + size = fold_convert (size_type_node, gfc_vptr_size_get (tmp)); > > + } > Use TYPE_SIZE_UNIT of the rhs in this case, in the same way as in the > else branch further below.
Er, but when I get TYPE_SIZE_UNIT () correctly, then it will grab the size needed to store the %_vptr%size component. Do you really intent that? I need to alloc the size of the polymorphic type of expr2 here. <snipp> > > @@ -7008,7 +7032,9 @@ gfc_trans_subcomponent_assign (tree dest, > > gfc_component * cm, gfc_expr * expr, gfc_add_expr_to_block (&block, tmp); > > } > > else if (init && (cm->attr.allocatable > > - || (cm->ts.type == BT_CLASS && CLASS_DATA > > (cm)->attr.allocatable))) > > + || (cm->ts.type == BT_CLASS && CLASS_DATA (cm)->attr.allocatable > > + && (expr->ts.type != BT_CLASS > > + || CLASS_DATA (expr)->attr.allocatable)))) > maybe: || !CLASS_DATA (expr)->attr.allocatable > (with a '!')? No, I only want to copy the rhs to new memory, when it is allocatable. For all other cases, one should not do this, to prevent a memory leak. Furthermore, is the data copied to freshly allocated memory anyway. Have a look at the pseudo code generated for the testcase in the patch. Regards, Andre -- Andre Vehreschild * Email: vehre ad gmx dot de