summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-06-28 00:59:33 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-06-28 00:59:33 +0000
commit532516a87bc57f21e6d99f49548e4c2adf835551 (patch)
treeeb4dd8852caf33c4c01be6f44c463e6c4adbf7d3
parent58a6cf2c620ce4c127b926408d78aa607a373251 (diff)
downloadllvm-532516a87bc57f21e6d99f49548e4c2adf835551.tar.gz
llvm-532516a87bc57f21e6d99f49548e4c2adf835551.tar.bz2
llvm-532516a87bc57f21e6d99f49548e4c2adf835551.tar.xz
fix a off-by-one bug in intersectWith(), and add a bunch of tests
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159319 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Support/ConstantRange.cpp2
-rw-r--r--unittests/Support/ConstantRangeTest.cpp34
2 files changed, 33 insertions, 3 deletions
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index e7d8483128..61d333f24a 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/ConstantRange.cpp
@@ -316,7 +316,7 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const {
return CR;
}
- if (CR.Upper.ult(Lower)) {
+ if (CR.Upper.ule(Lower)) {
if (CR.Lower.ult(Lower))
return *this;
diff --git a/unittests/Support/ConstantRangeTest.cpp b/unittests/Support/ConstantRangeTest.cpp
index 5fcdcfd2b4..a562080981 100644
--- a/unittests/Support/ConstantRangeTest.cpp
+++ b/unittests/Support/ConstantRangeTest.cpp
@@ -234,9 +234,39 @@ TEST_F(ConstantRangeTest, IntersectWith) {
EXPECT_TRUE(LHS.intersectWith(RHS) == LHS);
// previous bug: intersection of [min, 3) and [2, max) should be 2
- LHS = ConstantRange(APInt(32, -2147483648), APInt(32, 3));
- RHS = ConstantRange(APInt(32, 2), APInt(32, 2147483648));
+ LHS = ConstantRange(APInt(32, -2147483646), APInt(32, 3));
+ RHS = ConstantRange(APInt(32, 2), APInt(32, 2147483646));
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 2)));
+
+ // [2, 0) /\ [4, 3) = [2, 0)
+ LHS = ConstantRange(APInt(32, 2), APInt(32, 0));
+ RHS = ConstantRange(APInt(32, 4), APInt(32, 3));
+ EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 2), APInt(32, 0)));
+
+ // [2, 0) /\ [4, 2) = [4, 0)
+ LHS = ConstantRange(APInt(32, 2), APInt(32, 0));
+ RHS = ConstantRange(APInt(32, 4), APInt(32, 2));
+ EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 4), APInt(32, 0)));
+
+ // [4, 2) /\ [5, 1) = [5, 1)
+ LHS = ConstantRange(APInt(32, 4), APInt(32, 2));
+ RHS = ConstantRange(APInt(32, 5), APInt(32, 1));
+ EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 5), APInt(32, 1)));
+
+ // [2, 0) /\ [7, 4) = [7, 4)
+ LHS = ConstantRange(APInt(32, 2), APInt(32, 0));
+ RHS = ConstantRange(APInt(32, 7), APInt(32, 4));
+ EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 7), APInt(32, 4)));
+
+ // [4, 2) /\ [1, 0) = [1, 0)
+ LHS = ConstantRange(APInt(32, 4), APInt(32, 2));
+ RHS = ConstantRange(APInt(32, 1), APInt(32, 0));
+ EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 4), APInt(32, 2)));
+
+ // [15, 0) /\ [7, 6) = [15, 0)
+ LHS = ConstantRange(APInt(32, 15), APInt(32, 0));
+ RHS = ConstantRange(APInt(32, 7), APInt(32, 6));
+ EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 15), APInt(32, 0)));
}
TEST_F(ConstantRangeTest, UnionWith) {