This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR34030, wrong types in fold
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 16 Nov 2007 22:33:35 +0100 (CET)
- Subject: [PATCH] Fix PR34030, wrong types in fold
Bootstrapped and tested on x86_64-unknown-linux-gnu for trunk, 4.2
and 4.1, applied (soon).
Richard.
2007-11-16 Richard Guenther <rguenther@suse.de>
PR middle-end/34030
* fold-const.c (fold_binary): Use correct types for folding
1 << X & Y to Y >> X & 1.
* gcc.c-torture/compile/pr34030.c: New testcase.
Index: fold-const.c
===================================================================
*** fold-const.c (revision 130234)
--- fold-const.c (working copy)
*************** fold_binary (enum tree_code code, tree t
*** 10643,10666 ****
tree arg01 = TREE_OPERAND (arg0, 1);
if (TREE_CODE (arg00) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg00, 0)))
! return
! fold_build2 (code, type,
! build2 (BIT_AND_EXPR, TREE_TYPE (arg0),
! build2 (RSHIFT_EXPR, TREE_TYPE (arg00),
! arg01, TREE_OPERAND (arg00, 1)),
! fold_convert (TREE_TYPE (arg0),
! integer_one_node)),
! arg1);
! else if (TREE_CODE (TREE_OPERAND (arg0, 1)) == LSHIFT_EXPR
! && integer_onep (TREE_OPERAND (TREE_OPERAND (arg0, 1), 0)))
! return
! fold_build2 (code, type,
! build2 (BIT_AND_EXPR, TREE_TYPE (arg0),
! build2 (RSHIFT_EXPR, TREE_TYPE (arg01),
! arg00, TREE_OPERAND (arg01, 1)),
! fold_convert (TREE_TYPE (arg0),
! integer_one_node)),
! arg1);
}
/* If this is an NE or EQ comparison of zero against the result of a
--- 10643,10666 ----
tree arg01 = TREE_OPERAND (arg0, 1);
if (TREE_CODE (arg00) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg00, 0)))
! {
! tree tem = fold_build2 (RSHIFT_EXPR, TREE_TYPE (arg00),
! arg01, TREE_OPERAND (arg00, 1));
! tem = fold_build2 (BIT_AND_EXPR, TREE_TYPE (arg0), tem,
! build_int_cst (TREE_TYPE (arg0), 1));
! return fold_build2 (code, type,
! fold_convert (TREE_TYPE (arg1), tem), arg1);
! }
! else if (TREE_CODE (arg01) == LSHIFT_EXPR
! && integer_onep (TREE_OPERAND (arg01, 0)))
! {
! tree tem = fold_build2 (RSHIFT_EXPR, TREE_TYPE (arg01),
! arg00, TREE_OPERAND (arg01, 1));
! tem = fold_build2 (BIT_AND_EXPR, TREE_TYPE (arg0), tem,
! build_int_cst (TREE_TYPE (arg0), 1));
! return fold_build2 (code, type,
! fold_convert (TREE_TYPE (arg1), tem), arg1);
! }
}
/* If this is an NE or EQ comparison of zero against the result of a
Index: testsuite/gcc.c-torture/compile/pr34030.c
===================================================================
*** testsuite/gcc.c-torture/compile/pr34030.c (revision 0)
--- testsuite/gcc.c-torture/compile/pr34030.c (revision 0)
***************
*** 0 ****
--- 1,8 ----
+ int myvar;
+
+ int foo(int mynum)
+ {
+ if ((((void *)0) == (myvar & ((1U<<0) << mynum))) && (mynum > 0))
+ return 1;
+ return 0;
+ }