From: Martin Liska Date: Tue, 3 Jan 2017 10:54:40 +0000 (+0100) Subject: Fill bitregion_{start,end} in store_constructor (PR tree-optimization/78428). X-Git-Tag: releases/gcc-5.5.0~614 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d546e60673563c0fe0f4aa6490edaa16172190b8;p=thirdparty%2Fgcc.git Fill bitregion_{start,end} in store_constructor (PR tree-optimization/78428). Backport from mainline 2016-12-13 Martin Liska PR tree-optimization/78428 * expr.c (store_constructor_field): Add new arguments to the function. (store_constructor): Set up bitregion_end and add gcc_unreachable to fields that have either non-constant size or (and) offset. Backport from mainline 2016-12-13 Martin Liska PR tree-optimization/78428 * gcc.dg/tree-ssa/pr78428.c: New test. From-SVN: r244016 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fa387f87aa23..e918175c46b2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2017-01-03 Martin Liska + + Backport from mainline + 2016-12-13 Martin Liska + + PR tree-optimization/78428 + * expr.c (store_constructor_field): Add new arguments to the + function. + (store_constructor): Set up bitregion_end and add + gcc_unreachable to fields that have either non-constant size + or (and) offset. + 2016-12-27 Jakub Jelinek PR translation/78922 diff --git a/gcc/expr.c b/gcc/expr.c index d72c05375a73..0e301f8a7a9c 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -165,7 +165,8 @@ static tree clear_storage_libcall_fn (int); static rtx_insn *compress_float_constant (rtx, rtx); static rtx get_subtarget (rtx); static void store_constructor_field (rtx, unsigned HOST_WIDE_INT, - HOST_WIDE_INT, machine_mode, + HOST_WIDE_INT, unsigned HOST_WIDE_INT, + unsigned HOST_WIDE_INT, machine_mode, tree, int, alias_set_type); static void store_constructor (tree, rtx, int, HOST_WIDE_INT); static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT, @@ -5899,7 +5900,10 @@ all_zeros_p (const_tree exp) static void store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize, - HOST_WIDE_INT bitpos, machine_mode mode, + HOST_WIDE_INT bitpos, + unsigned HOST_WIDE_INT bitregion_start, + unsigned HOST_WIDE_INT bitregion_end, + machine_mode mode, tree exp, int cleared, alias_set_type alias_set) { if (TREE_CODE (exp) == CONSTRUCTOR @@ -5932,7 +5936,8 @@ store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize, store_constructor (exp, target, cleared, bitsize / BITS_PER_UNIT); } else - store_field (target, bitsize, bitpos, 0, 0, mode, exp, alias_set, false); + store_field (target, bitsize, bitpos, bitregion_start, bitregion_end, mode, + exp, alias_set, false); } @@ -5967,6 +5972,7 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size) #ifdef WORD_REGISTER_OPERATIONS HOST_WIDE_INT exp_size = int_size_in_bytes (type); #endif + HOST_WIDE_INT bitregion_end = size > 0 ? size * BITS_PER_UNIT - 1 : 0; switch (TREE_CODE (type)) { @@ -6042,7 +6048,7 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size) if (tree_fits_uhwi_p (DECL_SIZE (field))) bitsize = tree_to_uhwi (DECL_SIZE (field)); else - bitsize = -1; + gcc_unreachable (); mode = DECL_MODE (field); if (DECL_BIT_FIELD (field)) @@ -6056,28 +6062,7 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size) offset = 0; } else - bitpos = tree_to_shwi (DECL_FIELD_BIT_OFFSET (field)); - - if (offset) - { - machine_mode address_mode; - rtx offset_rtx; - - offset - = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset, - make_tree (TREE_TYPE (exp), - target)); - - offset_rtx = expand_normal (offset); - gcc_assert (MEM_P (to_rtx)); - - address_mode = get_address_mode (to_rtx); - if (GET_MODE (offset_rtx) != address_mode) - offset_rtx = convert_to_mode (address_mode, offset_rtx, 0); - - to_rtx = offset_address (to_rtx, offset_rtx, - highest_pow2_factor (offset)); - } + gcc_unreachable (); #ifdef WORD_REGISTER_OPERATIONS /* If this initializes a field that is smaller than a @@ -6126,7 +6111,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size) MEM_KEEP_ALIAS_SET_P (to_rtx) = 1; } - store_constructor_field (to_rtx, bitsize, bitpos, mode, + store_constructor_field (to_rtx, bitsize, bitpos, + 0, bitregion_end, mode, value, cleared, get_alias_set (TREE_TYPE (field))); } @@ -6282,7 +6268,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size) } store_constructor_field - (target, bitsize, bitpos, mode, value, cleared, + (target, bitsize, bitpos, 0, bitregion_end, + mode, value, cleared, get_alias_set (elttype)); } } @@ -6385,7 +6372,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size) target = copy_rtx (target); MEM_KEEP_ALIAS_SET_P (target) = 1; } - store_constructor_field (target, bitsize, bitpos, mode, value, + store_constructor_field (target, bitsize, bitpos, 0, + bitregion_end, mode, value, cleared, get_alias_set (elttype)); } } @@ -6518,7 +6506,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size) ? TYPE_MODE (TREE_TYPE (value)) : eltmode; bitpos = eltpos * elt_size; - store_constructor_field (target, bitsize, bitpos, value_mode, + store_constructor_field (target, bitsize, bitpos, 0, + bitregion_end, value_mode, value, cleared, alias); } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index beac2293cf1c..89bd178d9878 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2017-01-03 Martin Liska + + Backport from mainline + 2016-12-13 Martin Liska + + PR tree-optimization/78428 + * gcc.dg/tree-ssa/pr78428.c: New test. + 2016-12-22 Thomas Koenig Backport from trunk diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr78428.c b/gcc/testsuite/gcc.dg/tree-ssa/pr78428.c new file mode 100644 index 000000000000..3a9b99c7e036 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr78428.c @@ -0,0 +1,27 @@ +/* PR tree-optimization/78428. */ +/* { dg-options "-O2" } */ +/* { dg-do run } */ + +struct S0 +{ + int f2; + int f3:16; + int f4:18; +} ; + +int a = 5; +struct S0 b = { 3, 0, 0 }; +static struct S0 global[2] = { { 77, 0, 78 }, { 77, 0, 78 } }; + +int main () +{ + volatile struct S0 *j; + for (; a;) + { + __builtin_printf ("", b.f2); + j = &b; + *j = global[1]; + a--; + } + return 0; +}