aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2023-09-07 15:54:20 -0400
committerAldy Hernandez <aldyh@redhat.com>2023-09-07 18:13:09 -0400
commit7ece864adde82e6906e20a8b841361be2fd649d8 (patch)
treec1d8f533a100845204b71ce2f0da024cafb1397a /gcc
parent7d2274b9e346f44f8f6598b9dbb9fa95259274a2 (diff)
downloadgcc-7ece864adde82e6906e20a8b841361be2fd649d8.zip
gcc-7ece864adde82e6906e20a8b841361be2fd649d8.tar.gz
gcc-7ece864adde82e6906e20a8b841361be2fd649d8.tar.bz2
[irange] Fix typo in contains_zero_p.
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/range-op-float.cc8
-rw-r--r--gcc/range-op.cc30
-rw-r--r--gcc/value-range.h2
3 files changed, 20 insertions, 20 deletions
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index eebc73f99..89c401e 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -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;
}
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 619979f..33b193b 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -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;
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 6c5be36..da04be0 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -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);