[llvm-commits] [llvm] r159319 - in /llvm/trunk: lib/Support/ConstantRange.cpp unittests/Support/ConstantRangeTest.cpp

Nuno Lopes nunoplopes at sapo.pt
Wed Jun 27 17:59:34 PDT 2012


Author: nlopes
Date: Wed Jun 27 19:59:33 2012
New Revision: 159319

URL: http://llvm.org/viewvc/llvm-project?rev=159319&view=rev
Log:
fix a off-by-one bug in intersectWith(), and add a bunch of tests

Modified:
    llvm/trunk/lib/Support/ConstantRange.cpp
    llvm/trunk/unittests/Support/ConstantRangeTest.cpp

Modified: llvm/trunk/lib/Support/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ConstantRange.cpp?rev=159319&r1=159318&r2=159319&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ConstantRange.cpp (original)
+++ llvm/trunk/lib/Support/ConstantRange.cpp Wed Jun 27 19:59:33 2012
@@ -316,7 +316,7 @@
 
     return CR;
   }
-  if (CR.Upper.ult(Lower)) {
+  if (CR.Upper.ule(Lower)) {
     if (CR.Lower.ult(Lower))
       return *this;
 

Modified: llvm/trunk/unittests/Support/ConstantRangeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ConstantRangeTest.cpp?rev=159319&r1=159318&r2=159319&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/ConstantRangeTest.cpp (original)
+++ llvm/trunk/unittests/Support/ConstantRangeTest.cpp Wed Jun 27 19:59:33 2012
@@ -234,9 +234,39 @@
   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) {





More information about the llvm-commits mailing list