This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [PATCH] Fix PR64822: incorrect folding of bitfield in union on big endian targets


> 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.

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;

Is this ok for trunk?

Best regards,

Thomas





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]