]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[irange] Fix typo in contains_zero_p.
authorAldy Hernandez <aldyh@redhat.com>
Thu, 7 Sep 2023 19:54:20 +0000 (15:54 -0400)
committerAldy Hernandez <aldyh@redhat.com>
Thu, 7 Sep 2023 22:13:09 +0000 (18:13 -0400)
In the conversion of iranges to wide_int (commit cb779afeff204f), I
mistakenly made contains_zero_p() return TRUE for undefined ranges.
This means the rest of the patch was adjusted for this stupidity.

For example, we ended up doing the following, to make up for the fact
that contains_zero_p was broken:

-  if (!lhs.contains_p (build_zero_cst (lhs.type ())))
+  if (lhs.undefined_p () || !contains_zero_p (lhs))

This patch fixes the thinko and adjusts all callers.

In places where a caller is not checking undefined_p(), it is because
either the caller has already handled undefined ranges in the
preceeding code, or the check is superfluous.

gcc/ChangeLog:

* value-range.h (contains_zero_p): Return false for undefined ranges.
* range-op-float.cc (operator_gt::op1_op2_relation): Adjust for
contains_zero_p change above.
(operator_ge::op1_op2_relation): Same.
(operator_equal::op1_op2_relation): Same.
(operator_not_equal::op1_op2_relation): Same.
(operator_lt::op1_op2_relation): Same.
(operator_le::op1_op2_relation): Same.
(operator_ge::op1_op2_relation): Same.
* range-op.cc (operator_equal::op1_op2_relation): Same.
(operator_not_equal::op1_op2_relation): Same.
(operator_lt::op1_op2_relation): Same.
(operator_le::op1_op2_relation): Same.
(operator_cast::op1_range): Same.
(set_nonzero_range_from_mask): Same.
(operator_bitwise_xor::op1_range): Same.
(operator_addr_expr::fold_range): Same.
(operator_addr_expr::op1_range): Same.

gcc/range-op-float.cc
gcc/range-op.cc
gcc/value-range.h

index eebc73f9918c02af6f5bfda4571da6b4a4a90e3e..89c401e040a2de77a1f14632dad34c00ed317a54 100644 (file)
@@ -783,7 +783,7 @@ operator_equal::op1_op2_relation (const irange &lhs, const frange &,
     return VREL_NE;
 
   // TRUE = op1 == op2 indicates EQ_EXPR.
-  if (lhs.undefined_p () || !contains_zero_p (lhs))
+  if (!contains_zero_p (lhs))
     return VREL_EQ;
   return VREL_VARYING;
 }
@@ -915,7 +915,7 @@ operator_not_equal::op1_op2_relation (const irange &lhs, const frange &,
     return VREL_EQ;
 
   // TRUE = op1 != op2  indicates NE_EXPR.
-  if (lhs.undefined_p () || !contains_zero_p (lhs))
+  if (!contains_zero_p (lhs))
     return VREL_NE;
   return VREL_VARYING;
 }
@@ -1037,7 +1037,7 @@ operator_lt::op1_op2_relation (const irange &lhs, const frange &,
     return VREL_GE;
 
   // TRUE = op1 < op2 indicates LT_EXPR.
-  if (lhs.undefined_p () || !contains_zero_p (lhs))
+  if (!contains_zero_p (lhs))
     return VREL_LT;
   return VREL_VARYING;
 }
@@ -1144,7 +1144,7 @@ operator_le::op1_op2_relation (const irange &lhs, const frange &,
     return VREL_GT;
 
   // TRUE = op1 <= op2 indicates LE_EXPR.
-  if (lhs.undefined_p () || !contains_zero_p (lhs))
+  if (!contains_zero_p (lhs))
     return VREL_LE;
   return VREL_VARYING;
 }
index 619979f2f61da98fde27ea3fdf0ec753b33cb247..33b193be7d09ee4d6b21bd26525cf5824cb119a9 100644 (file)
@@ -915,7 +915,7 @@ operator_equal::op1_op2_relation (const irange &lhs, const irange &,
     return VREL_NE;
 
   // TRUE = op1 == op2 indicates EQ_EXPR.
-  if (lhs.undefined_p () || !contains_zero_p (lhs))
+  if (!contains_zero_p (lhs))
     return VREL_EQ;
   return VREL_VARYING;
 }
@@ -1017,7 +1017,7 @@ operator_not_equal::op1_op2_relation (const irange &lhs, const irange &,
     return VREL_EQ;
 
   // TRUE = op1 != op2  indicates NE_EXPR.
-  if (lhs.undefined_p () || !contains_zero_p (lhs))
+  if (!contains_zero_p (lhs))
     return VREL_NE;
   return VREL_VARYING;
 }
@@ -1178,7 +1178,7 @@ operator_lt::op1_op2_relation (const irange &lhs, const irange &,
     return VREL_GE;
 
   // TRUE = op1 < op2 indicates LT_EXPR.
-  if (lhs.undefined_p () || !contains_zero_p (lhs))
+  if (!contains_zero_p (lhs))
     return VREL_LT;
   return VREL_VARYING;
 }
@@ -1279,7 +1279,7 @@ operator_le::op1_op2_relation (const irange &lhs, const irange &,
     return VREL_GT;
 
   // TRUE = op1 <= op2 indicates LE_EXPR.
-  if (lhs.undefined_p () || !contains_zero_p (lhs))
+  if (!contains_zero_p (lhs))
     return VREL_LE;
   return VREL_VARYING;
 }
@@ -2957,7 +2957,7 @@ operator_cast::op1_range (irange &r, tree type,
        {
          // If the LHS is not a pointer nor a singleton, then it is
          // either VARYING or non-zero.
-         if (!contains_zero_p (lhs))
+         if (!lhs.undefined_p () && !contains_zero_p (lhs))
            r.set_nonzero (type);
          else
            r.set_varying (type);
@@ -3368,10 +3368,10 @@ operator_bitwise_and::wi_fold (irange &r, tree type,
 static void
 set_nonzero_range_from_mask (irange &r, tree type, const irange &lhs)
 {
-  if (!contains_zero_p (lhs))
-    r = range_nonzero (type);
-  else
+  if (lhs.undefined_p () || contains_zero_p (lhs))
     r.set_varying (type);
+  else
+    r.set_nonzero (type);
 }
 
 /* Find out smallest RES where RES > VAL && (RES & MASK) == RES, if any
@@ -3798,7 +3798,7 @@ operator_bitwise_xor::op1_range (irange &r, tree type,
          else if (op2.zero_p ())
            r = range_true (type);
          // See get_bool_state for the rationale
-         else if (contains_zero_p (op2))
+         else if (op2.undefined_p () || contains_zero_p (op2))
            r = range_true_and_false (type);
          else
            r = range_false (type);
@@ -4335,10 +4335,10 @@ operator_addr_expr::fold_range (irange &r, tree type,
   // Return a non-null pointer of the LHS type (passed in op2).
   if (lh.zero_p ())
     r = range_zero (type);
-  else if (!contains_zero_p (lh))
-    r = range_nonzero (type);
-  else
+  else if (lh.undefined_p () || contains_zero_p (lh))
     r.set_varying (type);
+  else
+    r.set_nonzero (type);
   return true;
 }
 
@@ -4348,14 +4348,14 @@ operator_addr_expr::op1_range (irange &r, tree type,
                               const irange &op2,
                               relation_trio) const
 {
-   if (empty_range_varying (r, type, lhs, op2))
+  if (empty_range_varying (r, type, lhs, op2))
     return true;
 
   // Return a non-null pointer of the LHS type (passed in op2), but only
   // if we cant overflow, eitherwise a no-zero offset could wrap to zero.
   // See PR 111009.
-  if (!contains_zero_p (lhs) && TYPE_OVERFLOW_UNDEFINED (type))
-    r = range_nonzero (type);
+  if (!lhs.undefined_p () && !contains_zero_p (lhs) && TYPE_OVERFLOW_UNDEFINED (type))
+    r.set_nonzero (type);
   else
     r.set_varying (type);
   return true;
index 6c5be36d74d2167c02b143076f7cc002c6f48699..da04be00ab41e1f741f0a5d234884b549c82b8f7 100644 (file)
@@ -1158,7 +1158,7 @@ inline bool
 contains_zero_p (const irange &r)
 {
   if (r.undefined_p ())
-    return true;
+    return false;
 
   wide_int zero = wi::zero (TYPE_PRECISION (r.type ()));
   return r.contains_p (zero);