diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2019-01-25 16:57:32 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@gcc.gnu.org> | 2019-01-25 16:57:32 +0000 |
commit | 3c35efc322f7ff8d25b81cf9ebc01d0ec202bb89 (patch) | |
tree | 8c687e9e504a57ca6818174a9eb80e2cade73e41 /gcc/varasm.c | |
parent | 62fa42ce812c699b8cc270b486ef8d644c0342de (diff) | |
download | gcc-3c35efc322f7ff8d25b81cf9ebc01d0ec202bb89.zip gcc-3c35efc322f7ff8d25b81cf9ebc01d0ec202bb89.tar.gz gcc-3c35efc322f7ff8d25b81cf9ebc01d0ec202bb89.tar.bz2 |
Fix output_constructor_bitfield handling of wide bitfields (PR89037)
The testcase was failing because we were trying to access
TREE_INT_CST_ELT (x, 1) of a 128-bit integer that was small enough
to need only a single element.
2019-01-25 Richard Sandiford <richard.sandiford@arm.com>
gcc/
PR middle-end/89037
* varasm.c (output_constructor_bitfield): Use wi::extract_uhwi
instead of accessing TREE_INT_CST_ELT directly.
gcc/testsuite/
PR middle-end/89037
* gcc.dg/pr89037.c: New test.
From-SVN: r268272
Diffstat (limited to 'gcc/varasm.c')
-rw-r--r-- | gcc/varasm.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/gcc/varasm.c b/gcc/varasm.c index bddd3d2..0be44f1 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -5349,7 +5349,7 @@ output_constructor_bitfield (oc_local_state *local, unsigned int bit_offset) { int this_time; int shift; - HOST_WIDE_INT value; + unsigned HOST_WIDE_INT value; HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT; HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT; @@ -5381,15 +5381,13 @@ output_constructor_bitfield (oc_local_state *local, unsigned int bit_offset) this_time = end - shift + 1; } - /* Now get the bits from the appropriate constant word. */ - value = TREE_INT_CST_ELT (local->val, shift / HOST_BITS_PER_WIDE_INT); - shift = shift & (HOST_BITS_PER_WIDE_INT - 1); + /* Now get the bits we want to insert. */ + value = wi::extract_uhwi (wi::to_widest (local->val), + shift, this_time); /* Get the result. This works only when: 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */ - local->byte |= (((value >> shift) - & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1)) - << (BITS_PER_UNIT - this_time - next_bit)); + local->byte |= value << (BITS_PER_UNIT - this_time - next_bit); } else { @@ -5406,15 +5404,13 @@ output_constructor_bitfield (oc_local_state *local, unsigned int bit_offset) this_time = HOST_BITS_PER_WIDE_INT - (shift & (HOST_BITS_PER_WIDE_INT - 1)); - /* Now get the bits from the appropriate constant word. */ - value = TREE_INT_CST_ELT (local->val, shift / HOST_BITS_PER_WIDE_INT); - shift = shift & (HOST_BITS_PER_WIDE_INT - 1); + /* Now get the bits we want to insert. */ + value = wi::extract_uhwi (wi::to_widest (local->val), + shift, this_time); /* Get the result. This works only when: 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */ - local->byte |= (((value >> shift) - & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1)) - << next_bit); + local->byte |= value << next_bit; } next_offset += this_time; |