This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][4.3] Fix PR40404
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 17 Jun 2009 14:24:34 +0200 (CEST)
- Subject: [PATCH][4.3] Fix PR40404
We have a bogus folding in case of widened bitfields in 4.3. In
4.4 this was removed as part of a larger patch. The following
instead fixes up the folding appropriately.
Bootstrap & regtest running, I will commit this to the branch
after it succeeded and the testcase to the 4.4 branch and the trunk.
Richard.
2009-06-17 Richard Guenther <rguenther@suse.de>
PR middle-end/40404
* fold-const.c (fold_binary): Verify the type precision of the
stripped arguments of the comparison are the same before
folding the comparison.
* gcc.c-torture/execute/pr40404.c: New testcase.
Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c (revision 148604)
--- gcc/fold-const.c (working copy)
*************** fold_binary (enum tree_code code, tree t
*** 12722,12727 ****
--- 12722,12729 ----
optimizations involving comparisons with non-negative constants. */
if (TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (arg0) != INTEGER_CST
+ && (TYPE_PRECISION (TREE_TYPE (arg0))
+ == TYPE_PRECISION (TREE_TYPE (arg1)))
&& tree_int_cst_sgn (arg1) > 0)
{
if (code == GE_EXPR)
Index: gcc/testsuite/gcc.c-torture/execute/pr40404.c
===================================================================
*** gcc/testsuite/gcc.c-torture/execute/pr40404.c (revision 0)
--- gcc/testsuite/gcc.c-torture/execute/pr40404.c (revision 0)
***************
*** 0 ****
--- 1,12 ----
+ extern void abort (void);
+ struct S {
+ unsigned int ui17 : 17;
+ } s;
+ int main()
+ {
+ s.ui17 = 0x1ffff;
+ if (s.ui17 >= 0xfffffffeu)
+ abort ();
+ return 0;
+ }
+