+2017-09-09 Eric Botcazou <ebotcazou@adacore.com>
+
+ * gcc-interface/utils.c (convert): When converting to a padding type,
+ reuse an existing CONSTRUCTOR if it has got the right size.
+
2017-09-08 Nicolas Roche <roche@adacore.com>
* gcc-interface/Make-lang.in, gcc-interface/Makefile.in: Find runtime
constructor to build the record, unless a variable size is involved. */
else if (code == RECORD_TYPE && TYPE_PADDING_P (type))
{
- vec<constructor_elt, va_gc> *v;
-
/* If we previously converted from another type and our type is
of variable size, remove the conversion to avoid the need for
variable-sized temporaries. Likewise for a conversion between
expr),
false);
+ tree t = convert (TREE_TYPE (TYPE_FIELDS (type)), expr);
+
+ /* If converting to the inner type has already created a CONSTRUCTOR with
+ the right size, then reuse it instead of creating another one. This
+ can happen for the padding type built to overalign local variables. */
+ if (TREE_CODE (t) == VIEW_CONVERT_EXPR
+ && TREE_CODE (TREE_OPERAND (t, 0)) == CONSTRUCTOR
+ && TREE_CONSTANT (TYPE_SIZE (TREE_TYPE (TREE_OPERAND (t, 0))))
+ && tree_int_cst_equal (TYPE_SIZE (type),
+ TYPE_SIZE (TREE_TYPE (TREE_OPERAND (t, 0)))))
+ return build1 (VIEW_CONVERT_EXPR, type, TREE_OPERAND (t, 0));
+
+ vec<constructor_elt, va_gc> *v;
vec_alloc (v, 1);
- CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (type),
- convert (TREE_TYPE (TYPE_FIELDS (type)), expr));
+ CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (type), t);
return gnat_build_constructor (type, v);
}