Fix a bug summing two full sets. The overflow checking doesn't handle sets as
authorNick Lewycky <nicholas@mxc.ca>
Mon, 13 Jul 2009 02:49:08 +0000 (02:49 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Mon, 13 Jul 2009 02:49:08 +0000 (02:49 +0000)
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

lib/Support/ConstantRange.cpp
unittests/Support/ConstantRangeTest.cpp

index 04a1b68e0728dfa8e2789ec57a12b043286379e5..8bab53779528a98b89e6b063b7fce63852ef29bb 100644 (file)
@@ -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();
index 891c209f11c02f0005ec60796a08705ffeb951e1..cd91a9e103cf5c6bafdddb3864ddfd6e844d130c 100644 (file)
@@ -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);