From: Eric Botcazou Date: Sat, 9 Sep 2017 10:36:40 +0000 (+0000) Subject: utils.c (convert): When converting to a padding type... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=66c9b3f50f70b1503629b94cc2e33f7e5df64b08;p=gcc.git utils.c (convert): When converting to a padding type... * gcc-interface/utils.c (convert): When converting to a padding type, reuse an existing CONSTRUCTOR if it has got the right size. From-SVN: r251924 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 7b3ab766f00..65b68334929 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2017-09-09 Eric Botcazou + + * 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 * gcc-interface/Make-lang.in, gcc-interface/Makefile.in: Find runtime diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 89dbc8deb92..04199769ea3 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -4219,8 +4219,6 @@ convert (tree type, tree expr) constructor to build the record, unless a variable size is involved. */ else if (code == RECORD_TYPE && TYPE_PADDING_P (type)) { - vec *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 @@ -4272,9 +4270,21 @@ convert (tree type, tree expr) 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 *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); }