aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2020-06-02 11:14:58 +0200
committerAldy Hernandez <aldyh@redhat.com>2020-06-02 14:02:29 +0200
commit455c0b2c72dfc6eb3bc753e8e1f54906c1ada484 (patch)
treead216ccadf669269aac66a241423b77ff8ad8af5
parent7b61d7a7338462ddf0f8cae92a1236444bb799e3 (diff)
downloadgcc-455c0b2c72dfc6eb3bc753e8e1f54906c1ada484.zip
gcc-455c0b2c72dfc6eb3bc753e8e1f54906c1ada484.tar.gz
gcc-455c0b2c72dfc6eb3bc753e8e1f54906c1ada484.tar.bz2
Test that [10,10][20,20] does NOT contain 15.
The problem was that value_inside_range was squishing a range into a int_range<1>. The inverse of this range no longer contained what was conservatively needed. The fix was to use widest_irange instead.
-rw-r--r--gcc/range-op.cc11
-rw-r--r--gcc/value-range.cc10
2 files changed, 18 insertions, 3 deletions
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index f4d4de5..3676dc8 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3408,6 +3408,17 @@ widest_irange_tests ()
int_range<1> tmp (INT (5), INT (37));
big.intersect (tmp);
ASSERT_TRUE (big.num_pairs () == 4);
+
+ // Test that [10,10][20,20] does NOT contain 15.
+ {
+ widest_irange i1 (build_int_cst (integer_type_node, 10),
+ build_int_cst (integer_type_node, 10));
+ widest_irange i2 (build_int_cst (integer_type_node, 20),
+ build_int_cst (integer_type_node, 20));
+ i1.union_ (i2);
+ ASSERT_FALSE (i1.contains_p (build_int_cst (integer_type_node, 15)));
+ }
+
}
static void
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 6e0d18b..ffe1835 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -875,9 +875,9 @@ irange::value_inside_range (tree val) const
/* For constants we can just intersect and avoid using VR_ANTI_RANGE
code further below. */
- if (constant_p ())
+ if (TREE_CODE (val) == INTEGER_CST && constant_p ())
{
- value_range v (val, val);
+ widest_irange v (val, val);
v.intersect (this);
return v == value_range (val, val) ? 1 : 0;
}
@@ -1776,7 +1776,11 @@ irange::intersect (const irange *other)
/* If a simple range was requested on the LHS, do the entire
operation in simple mode, because the RHS may be a
symbolic, and we only know how to deal with those in
- simple mode. */
+ simple mode.
+
+ FIXME: Squishing [10,10][20,20] into a value_range, will
+ yield [10,20]. If this result is then used with
+ contains_p(15), the result may be wrong. Revisit this. */
small = *other;
other = &small;
}