Patchwork Fix overflow test in fold_single_bit_test

login
register
mail settings
Submitter Richard Guenther
Date Aug. 30, 2013, 11:44 a.m.
Message ID <alpine.LNX.2.00.1308301344210.20077@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/271240/
State New
Headers show

Comments

Richard Guenther - Aug. 30, 2013, 11:44 a.m.
As noted by Kenny and Joern.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2013-08-30  Richard Biener  <rguenther@suse.de>

	* fold-const.c (fold_single_bit_test): Fix overflow test.

Patch

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	(revision 202100)
+++ gcc/fold-const.c	(working copy)
@@ -6634,10 +6634,10 @@  fold_single_bit_test (location_t loc, en
 	 not overflow, adjust BITNUM and INNER.  */
       if (TREE_CODE (inner) == RSHIFT_EXPR
 	  && TREE_CODE (TREE_OPERAND (inner, 1)) == INTEGER_CST
-	  && TREE_INT_CST_HIGH (TREE_OPERAND (inner, 1)) == 0
+	  && host_integerp (TREE_OPERAND (inner, 1), 1)
 	  && bitnum < TYPE_PRECISION (type)
-	  && 0 > compare_tree_int (TREE_OPERAND (inner, 1),
-				   bitnum - TYPE_PRECISION (type)))
+	  && (TREE_INT_CST_LOW (TREE_OPERAND (inner, 1))
+	      < (unsigned) (TYPE_PRECISION (type) - bitnum)))
 	{
 	  bitnum += TREE_INT_CST_LOW (TREE_OPERAND (inner, 1));
 	  inner = TREE_OPERAND (inner, 0);