aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2009-07-13 02:49:08 +0000
committerNick Lewycky <nicholas@mxc.ca>2009-07-13 02:49:08 +0000
commit70c5ab85595c3b8706c7bf6ac96ea427a9cd5799 (patch)
treeb6236c5fb84c073c3faca05ca55d4a3d946687b4
parent238dcb7f78f7cd0950e6eca3a23aa53f4eadb1e7 (diff)
downloadexternal_llvm-70c5ab85595c3b8706c7bf6ac96ea427a9cd5799.zip
external_llvm-70c5ab85595c3b8706c7bf6ac96ea427a9cd5799.tar.gz
external_llvm-70c5ab85595c3b8706c7bf6ac96ea427a9cd5799.tar.bz2
Fix a bug summing two full sets. The overflow checking doesn't handle sets as
large as the full set, only those one size smaller. Thanks to Daniel Dunbar who found this bug using Klee! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75443 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Support/ConstantRange.cpp2
-rw-r--r--unittests/Support/ConstantRangeTest.cpp1
2 files changed, 3 insertions, 0 deletions
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index 04a1b68..8bab537 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/ConstantRange.cpp
@@ -533,6 +533,8 @@ ConstantRange
ConstantRange::add(const ConstantRange &Other) const {
if (isEmptySet() || Other.isEmptySet())
return ConstantRange(getBitWidth(), /*isFullSet=*/false);
+ if (isFullSet() || Other.isFullSet())
+ return ConstantRange(getBitWidth(), /*isFullSet=*/true);
APInt Spread_X = getSetSize(), Spread_Y = Other.getSetSize();
APInt NewLower = getLower() + Other.getLower();
diff --git a/unittests/Support/ConstantRangeTest.cpp b/unittests/Support/ConstantRangeTest.cpp
index 891c209..cd91a9e 100644
--- a/unittests/Support/ConstantRangeTest.cpp
+++ b/unittests/Support/ConstantRangeTest.cpp
@@ -239,6 +239,7 @@ TEST_F(ConstantRangeTest, SubtractAPInt) {
TEST_F(ConstantRangeTest, Add) {
EXPECT_TRUE(Full.add(APInt(16, 4)).isFullSet());
+ EXPECT_EQ(Full.add(Full), Full);
EXPECT_EQ(Full.add(Empty), Empty);
EXPECT_EQ(Full.add(One), Full);
EXPECT_EQ(Full.add(Some), Full);