Fix an error in ConstantRange::getSignedMax on wrapped ranges. Thanks once
authorNick Lewycky <nicholas@mxc.ca>
Mon, 13 Jul 2009 04:50:21 +0000 (04:50 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Mon, 13 Jul 2009 04:50:21 +0000 (04:50 +0000)
again to Daniel Dunbar and KLEE!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75449 91177308-0d34-0410-b5e6-96231b3b80d8

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

index ca25491f6233b182757b920250a9a42538c8663b..4cb54bde1bd7f890a3ac1a347d498862ecc27363 100644 (file)
@@ -159,14 +159,10 @@ APInt ConstantRange::getSignedMax() const {
     else
       return SignedMax;
   } else {
-    if ((getUpper() - 1).slt(getLower())) {
-      if (getLower() != SignedMax)
-        return SignedMax;
-      else
-        return getUpper() - 1;
-    } else {
+    if (getLower().isNegative() == getUpper().isNegative())
+      return SignedMax;
+    else
       return getUpper() - 1;
-    }
   }
 }
 
index f929425e5475a9da6fde449cbb63f229f22d30b4..3ebb92967fd71709428e27b08784b4de3d6f7797 100644 (file)
@@ -137,6 +137,10 @@ TEST_F(ConstantRangeTest, GetMinsAndMaxes) {
   EXPECT_EQ(One.getSignedMin(), APInt(16, 0xa));
   EXPECT_EQ(Some.getSignedMin(), APInt(16, 0xa));
   EXPECT_EQ(Wrap.getSignedMin(), APInt(16, INT16_MIN));
+
+  // Found by Klee
+  EXPECT_EQ(ConstantRange(APInt(4, 7), APInt(4, 0)).getSignedMax(),
+            APInt(4, 7));
 }
 
 TEST_F(ConstantRangeTest, Trunc) {