diff mbox

Fix PR64822: incorrect folding of bitfield in union on big endian targets

Message ID 00d701d04024$9aa50250$cfef06f0$@arm.com
State New
Headers show

Commit Message

Thomas Preud'homme Feb. 4, 2015, 2:45 a.m. UTC
> From: Jakub Jelinek [mailto:jakub@redhat.com]
> Sent: Thursday, January 29, 2015 6:39 PM
> 

> You should mention
> 	PR middle-end/62103

Right, please find the new ChangeLog entries below:

2015-01-30  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	PR middle-end/62103
	* tree-ssa-sccvn.c (fully_constant_vn_reference_p): Use TYPE_PRECISION
	to compute size of referenced value in the constant case.

2015-01-30  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	PR middle-end/62103
	* gcc.c-torture/execute/bitfld-7.c: New test adapted from bitfld-6.c
	to use 24 bits for bitfield b.

> > 2015-01-28  Thomas Preud'homme  <thomas.preudhomme@arm.com>
> >
> >         * gcc.c-torture/execute/bitfld-6.c: Use 24 bits for bitfield b.  Adapt
> >         expected values accordingly.
> 
> IMHO if the old testcase wasn't incorrect, you'd better add a new
> testcase
> instead of modifying existing one.

Alright, here you are. I changed the existing testcase because the new setup felt as
a superset. Both setup goes into the code I added back then when I closed PR62103
but the new setup reaches it from SCC value numbering code.

You're right though the two testcases will exercise different code path for the rest
of the compiler and there is value in having both.


Is this ok for trunk?

Best regards,

Thomas

Comments

Jakub Jelinek Feb. 4, 2015, 7:54 a.m. UTC | #1
On Wed, Feb 04, 2015 at 10:45:11AM +0800, Thomas Preud'homme wrote:
> 2015-01-30  Thomas Preud'homme  <thomas.preudhomme@arm.com>
> 
> 	PR middle-end/62103
> 	* tree-ssa-sccvn.c (fully_constant_vn_reference_p): Use TYPE_PRECISION
> 	to compute size of referenced value in the constant case.
> 
> 2015-01-30  Thomas Preud'homme  <thomas.preudhomme@arm.com>
> 
> 	PR middle-end/62103
> 	* gcc.c-torture/execute/bitfld-7.c: New test adapted from bitfld-6.c
> 	to use 24 bits for bitfield b.

Richard already acked it with the new testcase, so yes, this is ok for the
trunk (just use today's date).

	Jakub
Thomas Preud'homme Feb. 4, 2015, 8:26 a.m. UTC | #2
> From: Jakub Jelinek [mailto:jakub@redhat.com]
> Sent: Wednesday, February 04, 2015 3:54 PM
> 
> Richard already acked it with the new testcase, so yes, this is ok for the
> trunk (just use today's date).

Oups my bad, I forgot he acked it.

Thanks and best regards.

Thomas
diff mbox

Patch

diff --git a/gcc/testsuite/gcc.c-torture/execute/bitfld-7.c b/gcc/testsuite/gcc.c-torture/execute/bitfld-7.c
new file mode 100644
index 0000000..e9a61df
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/bitfld-7.c
@@ -0,0 +1,23 @@ 
+union U
+{
+  const int a;
+  unsigned b : 24;
+};
+
+static union U u = { 0x12345678 };
+
+/* Constant folding used to fail to account for endianness when folding a
+   union.  */
+
+int
+main (void)
+{
+#ifdef __BYTE_ORDER__
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+  return u.b - 0x345678;
+#else
+  return u.b - 0x123456;
+#endif
+#endif
+  return 0;
+}
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index 25c67d0..0f1299a 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -1352,7 +1352,7 @@  fully_constant_vn_reference_p (vn_reference_t ref)
 	       || TYPE_PRECISION (ref->type) % BITS_PER_UNIT == 0))
     {
       HOST_WIDE_INT off = 0;
-      HOST_WIDE_INT size = tree_to_shwi (TYPE_SIZE (ref->type));
+      HOST_WIDE_INT size = TYPE_PRECISION (ref->type);
       if (size % BITS_PER_UNIT != 0
 	  || size > MAX_BITSIZE_MODE_ANY_MODE)
 	return NULL_TREE;