[Patch, Fortran, 66035, v1] [5/6 Regression] gfortran ICE segfault
Mikael Morin
mikael.morin@sfr.fr
Sun May 10 13:04:00 GMT 2015
Le 08/05/2015 15:29, Andre Vehreschild a écrit :
> Hi all,
>
> please find attached a patch for 66035. An ICE occurred when in a structure
> constructor an allocatable component of type class was initialized with an
> existing class object. This was caused by
>
> - the size of the memory to allocate for the component was miscalculated,
> - the vptr was not set correctly, and
> - when the class object to be used for init was allocatable already, it was
> copied wasting some memory instead of a view_convert inserted.
>
> All of the above are fixed by the attached patch.
>
> Bootstraps and regtests ok on x86_64-linux-gnu/f21 for trunk and gcc-5-trunk.
>
> Ok for trunk and gcc-5-trunk?
>
> Regards,
> Andre
>
>
> pr66035_1.patch
>
> 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.
> + else
> + {
> + gfc_expr *e2vtab;
> + gfc_se se;
> + e2vtab = gfc_find_and_cut_at_last_class_ref (expr2);
> + gfc_add_vptr_component (e2vtab);
> + gfc_add_size_component (e2vtab);
> + gfc_init_se (&se, NULL);
> + gfc_conv_expr (&se, e2vtab);
> + gfc_add_block_to_block (block, &se.pre);
> + size = fold_convert (size_type_node, se.expr);
> + gfc_free_expr (e2vtab);
> + }
> + size_in_bytes = size;
> + }
> else
> {
> /* Otherwise use the length in bytes of the rhs. */
> @@ -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 '!')?
Mikael
More information about the Gcc-patches
mailing list