PATCH COMMITTED: Patch for PR 31953

Ian Lance Taylor iant@google.com
Fri May 18 05:43:00 GMT 2007


This patch fixes PR 31953.  The problem was VRP's handling of an
assignment of a condition to a signed single bit bitfield, when the
condition was known to be true.  The boolean 1 was converted to -1 in
the bitfield, which was an overflow operation.  This was then treated
as an overflow infinity marker, which triggered an ENABLE_CHECKING
validity check.

The patch was bootstrapped and tested on i686-pc-linux-gnu.

This problem was latent on 4.2 branch, so I committed the patch there
as well.

Ian


gcc/:
2007-05-17  Ian Lance Taylor  <iant@google.com>

	PR tree-optimization/31953
	* tree-vrp.c (set_value_range_to_value): Add equiv parameter.
	Change all callers.
	(set_value_range_to_null): Call set_value_range_to_value.
	(extract_range_from_comparison): Likewise.

gcc/testsuite/:
2007-05-17  Ian Lance Taylor  <iant@google.com>

	PR tree-optimization/31953
	* gcc.c-torture/compile/pr31953.c: New test.


Index: tree-vrp.c
===================================================================
--- tree-vrp.c	(revision 124783)
+++ tree-vrp.c	(working copy)
@@ -358,7 +358,7 @@ set_value_range_to_varying (value_range_
    infinity when we shouldn't.  */
 
 static inline void
-set_value_range_to_value (value_range_t *vr, tree val)
+set_value_range_to_value (value_range_t *vr, tree val, bitmap equiv)
 {
   gcc_assert (is_gimple_min_invariant (val));
   if (is_overflow_infinity (val))
@@ -374,7 +374,7 @@ set_value_range_to_value (value_range_t 
 	  val = TYPE_MIN_VALUE (TREE_TYPE (val));
 	}
     }
-  set_value_range (vr, VR_RANGE, val, val, NULL);
+  set_value_range (vr, VR_RANGE, val, val, equiv);
 }
 
 /* Set value range VR to a non-negative range of type TYPE.
@@ -418,8 +418,7 @@ set_value_range_to_nonnull (value_range_
 static inline void
 set_value_range_to_null (value_range_t *vr, tree type)
 {
-  tree zero = build_int_cst (type, 0);
-  set_value_range (vr, VR_RANGE, zero, zero, vr->equiv);
+  set_value_range_to_value (vr, build_int_cst (type, 0), vr->equiv);
 }
 
 
@@ -1702,7 +1701,7 @@ extract_range_from_binary_expr (value_ra
   if (TREE_CODE (op0) == SSA_NAME)
     vr0 = *(get_value_range (op0));
   else if (is_gimple_min_invariant (op0))
-    set_value_range_to_value (&vr0, op0);
+    set_value_range_to_value (&vr0, op0, NULL);
   else
     set_value_range_to_varying (&vr0);
 
@@ -1710,7 +1709,7 @@ extract_range_from_binary_expr (value_ra
   if (TREE_CODE (op1) == SSA_NAME)
     vr1 = *(get_value_range (op1));
   else if (is_gimple_min_invariant (op1))
-    set_value_range_to_value (&vr1, op1);
+    set_value_range_to_value (&vr1, op1, NULL);
   else
     set_value_range_to_varying (&vr1);
 
@@ -2107,7 +2106,7 @@ extract_range_from_unary_expr (value_ran
   if (TREE_CODE (op0) == SSA_NAME)
     vr0 = *(get_value_range (op0));
   else if (is_gimple_min_invariant (op0))
-    set_value_range_to_value (&vr0, op0);
+    set_value_range_to_value (&vr0, op0, NULL);
   else
     set_value_range_to_varying (&vr0);
 
@@ -2490,7 +2489,7 @@ extract_range_from_cond_expr (value_rang
   if (TREE_CODE (op0) == SSA_NAME)
     vr0 = *(get_value_range (op0));
   else if (is_gimple_min_invariant (op0))
-    set_value_range_to_value (&vr0, op0);
+    set_value_range_to_value (&vr0, op0, NULL);
   else
     set_value_range_to_varying (&vr0);
 
@@ -2498,7 +2497,7 @@ extract_range_from_cond_expr (value_rang
   if (TREE_CODE (op1) == SSA_NAME)
     vr1 = *(get_value_range (op1));
   else if (is_gimple_min_invariant (op1))
-    set_value_range_to_value (&vr1, op1);
+    set_value_range_to_value (&vr1, op1, NULL);
   else
     set_value_range_to_varying (&vr1);
 
@@ -2528,7 +2527,10 @@ extract_range_from_comparison (value_ran
 	 its type may be different from _Bool.  Convert VAL to EXPR's
 	 type.  */
       val = fold_convert (TREE_TYPE (expr), val);
-      set_value_range (vr, VR_RANGE, val, val, vr->equiv);
+      if (is_gimple_min_invariant (val))
+	set_value_range_to_value (vr, val, vr->equiv);
+      else
+	set_value_range (vr, VR_RANGE, val, val, vr->equiv);
     }
   else
     /* The result of a comparison is always true or false.  */
@@ -2562,7 +2564,7 @@ extract_range_from_expr (value_range_t *
   else if (TREE_CODE_CLASS (code) == tcc_comparison)
     extract_range_from_comparison (vr, expr);
   else if (is_gimple_min_invariant (expr))
-    set_value_range_to_value (vr, expr);
+    set_value_range_to_value (vr, expr, NULL);
   else
     set_value_range_to_varying (vr);
 
Index: testsuite/gcc.c-torture/compile/pr31953.c
===================================================================
--- testsuite/gcc.c-torture/compile/pr31953.c	(revision 0)
+++ testsuite/gcc.c-torture/compile/pr31953.c	(revision 0)
@@ -0,0 +1,14 @@
+struct WView
+{
+  int hexedit_mode:1;
+};
+toggle_hexedit_mode (struct WView *view)
+{
+  if (view->hexedit_mode)
+    {
+    }
+  else
+    {
+      view->hexedit_mode = !view->hexedit_mode;
+    }
+}



More information about the Gcc-patches mailing list