-TEST_F(ConstantRangeTest, MaximalIntersectWith) {
- EXPECT_TRUE(Empty.maximalIntersectWith(Full).isEmptySet());
- EXPECT_TRUE(Empty.maximalIntersectWith(Empty).isEmptySet());
- EXPECT_TRUE(Empty.maximalIntersectWith(One).isEmptySet());
- EXPECT_TRUE(Empty.maximalIntersectWith(Some).isEmptySet());
- EXPECT_TRUE(Empty.maximalIntersectWith(Wrap).isEmptySet());
- EXPECT_TRUE(Full.maximalIntersectWith(Full).isFullSet());
- EXPECT_TRUE(Some.maximalIntersectWith(Some) == Some);
- EXPECT_TRUE(Some.maximalIntersectWith(One) == One);
- EXPECT_TRUE(Full.maximalIntersectWith(One) == One);
- EXPECT_TRUE(Full.maximalIntersectWith(Some) == Some);
- EXPECT_TRUE(Some.maximalIntersectWith(Wrap).isEmptySet());
- EXPECT_TRUE(One.maximalIntersectWith(Wrap).isEmptySet());
- EXPECT_EQ(One.maximalIntersectWith(Wrap), Wrap.maximalIntersectWith(One));
+ // Klee generated testcase from PR4545.
+ // The intersection of i16 [4, 2) and [6, 5) is disjoint, looking like
+ // 01..4.6789ABCDEF where the dots represent values not in the intersection.
+ ConstantRange LHS(APInt(16, 4), APInt(16, 2));
+ ConstantRange RHS(APInt(16, 6), APInt(16, 5));
+ EXPECT_TRUE(LHS.intersectWith(RHS) == LHS);
+
+ // previous bug: intersection of [min, 3) and [2, max) should be 2
+ 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)));