This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch for bit-field fallout (bug 16437)
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 11 Jul 2004 00:33:15 +0000 (UTC)
- Subject: Patch for bit-field fallout (bug 16437)
Here is a patch towards fixing bug 16437 (fallout from the bit-field
patch). I don't know whether it fixes the original bug on x86_64, but
it fixes the included testcase (and both of the changes are needed to
fix the testcase, either one on its own does not suffice). If it
fixes the original problem, someone testing on x86_64 should remove
the XFAILs, otherwise please update that bug and I'll investigate
further.
Bugs with the interaction of TREE_CONSTANT_OVERFLOW and integer_zerop
(cf. <http://gcc.gnu.org/ml/gcc/2004-06/msg00645.html>) are obscure to
find. TREE_OVERFLOW and TREE_CONSTANT_OVERFLOW have joined
TREE_COMPLEXITY and NON_LVALUE_EXPR on my little list.
Bootstrapped with no regressions on i686-pc-linux-gnu. OK to commit (the
fold-const.c change)?
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
2004-07-11 Joseph S. Myers <jsm@polyomino.org.uk>
PR tree-optimization/16437
* c-common.c (shorten_compare): Don't mark result of conversion to
narrower signed type as overflowing.
* fold-const.c (decode_field_reference): Determine whether
signedness comes from outer type using precision rather than size.
testsuite:
2004-07-11 Joseph S. Myers <jsm@polyomino.org.uk>
PR tree-optimization/16437
* gcc.c-torture/execute/bitfld-4.c: New test.
diff -rupN GCC.orig/gcc/c-common.c GCC/gcc/c-common.c
--- GCC.orig/gcc/c-common.c 2004-07-08 08:35:40.000000000 +0000
+++ GCC/gcc/c-common.c 2004-07-09 21:17:58.000000000 +0000
@@ -1924,7 +1924,12 @@ shorten_compare (tree *op0_ptr, tree *op
*restype_ptr = c_common_signed_type (*restype_ptr);
if (TREE_TYPE (primop1) != *restype_ptr)
- primop1 = convert (*restype_ptr, primop1);
+ {
+ tree tmp = convert (*restype_ptr, primop1);
+ TREE_OVERFLOW (tmp) = TREE_OVERFLOW (primop1);
+ TREE_CONSTANT_OVERFLOW (tmp) = TREE_CONSTANT_OVERFLOW (primop1);
+ primop1 = tmp;
+ }
if (type != *restype_ptr)
{
minval = convert (*restype_ptr, minval);
diff -rupN GCC.orig/gcc/fold-const.c GCC/gcc/fold-const.c
--- GCC.orig/gcc/fold-const.c 2004-07-09 16:49:23.000000000 +0000
+++ GCC/gcc/fold-const.c 2004-07-09 22:21:37.000000000 +0000
@@ -3296,7 +3296,7 @@ decode_field_reference (tree exp, HOST_W
/* If the number of bits in the reference is the same as the bitsize of
the outer type, then the outer type gives the signedness. Otherwise
(in case of a small bitfield) the signedness is unchanged. */
- if (outer_type && *pbitsize == tree_low_cst (TYPE_SIZE (outer_type), 1))
+ if (outer_type && *pbitsize == TYPE_PRECISION (outer_type))
*punsignedp = TYPE_UNSIGNED (outer_type);
/* Compute the mask to access the bitfield. */
diff -rupN GCC.orig/gcc/testsuite/gcc.c-torture/execute/bitfld-4.c GCC/gcc/testsuite/gcc.c-torture/execute/bitfld-4.c
--- GCC.orig/gcc/testsuite/gcc.c-torture/execute/bitfld-4.c 1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.c-torture/execute/bitfld-4.c 2004-07-09 21:14:37.000000000 +0000
@@ -0,0 +1,21 @@
+/* When comparisons of bit-fields to unsigned constants got shortened,
+ the shortened signed constant was wrongly marked as overflowing,
+ leading to a later integer_zerop failure and misoptimization.
+
+ Related to bug tree-optimization/16437 but shows the problem on
+ 32-bit systems. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+
+extern void abort (void);
+
+struct s { int a:12, b:20; };
+
+struct s x = { -123, -456 };
+
+int
+main (void)
+{
+ if (x.a != -123U || x.b != -456U)
+ abort ();
+ return 0;
+}