convert all the constant range EXPECT_EQ tests to use EXPECT_TRUE since

ConstantRange doesn't have an std::ostream inserter anymore.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79831 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-08-23 06:32:25 +00:00
parent 45cfe545ec
commit 8142ce568d

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/ConstantRange.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
@ -78,21 +79,21 @@ TEST_F(ConstantRangeTest, Basics) {
}
TEST_F(ConstantRangeTest, Equality) {
EXPECT_EQ(Full, Full);
EXPECT_EQ(Empty, Empty);
EXPECT_EQ(One, One);
EXPECT_EQ(Some, Some);
EXPECT_EQ(Wrap, Wrap);
EXPECT_NE(Full, Empty);
EXPECT_NE(Full, One);
EXPECT_NE(Full, Some);
EXPECT_NE(Full, Wrap);
EXPECT_NE(Empty, One);
EXPECT_NE(Empty, Some);
EXPECT_NE(Empty, Wrap);
EXPECT_NE(One, Some);
EXPECT_NE(One, Wrap);
EXPECT_NE(Some, Wrap);
EXPECT_TRUE(Full == Full);
EXPECT_TRUE(Empty == Empty);
EXPECT_TRUE(One == One);
EXPECT_TRUE(Some == Some);
EXPECT_TRUE(Wrap == Wrap);
EXPECT_TRUE(Full != Empty);
EXPECT_TRUE(Full != One);
EXPECT_TRUE(Full != Some);
EXPECT_TRUE(Full != Wrap);
EXPECT_TRUE(Empty != One);
EXPECT_TRUE(Empty != Some);
EXPECT_TRUE(Empty != Wrap);
EXPECT_TRUE(One != Some);
EXPECT_TRUE(One != Wrap);
EXPECT_TRUE(Some != Wrap);
}
TEST_F(ConstantRangeTest, SingleElement) {
@ -151,7 +152,7 @@ TEST_F(ConstantRangeTest, Trunc) {
ConstantRange TWrap = Wrap.truncate(10);
EXPECT_TRUE(TFull.isFullSet());
EXPECT_TRUE(TEmpty.isEmptySet());
EXPECT_EQ(TOne, ConstantRange(APInt(One.getLower()).trunc(10),
EXPECT_TRUE(TOne == ConstantRange(APInt(One.getLower()).trunc(10),
APInt(One.getUpper()).trunc(10)));
EXPECT_TRUE(TSome.isFullSet());
}
@ -162,14 +163,14 @@ TEST_F(ConstantRangeTest, ZExt) {
ConstantRange ZOne = One.zeroExtend(20);
ConstantRange ZSome = Some.zeroExtend(20);
ConstantRange ZWrap = Wrap.zeroExtend(20);
EXPECT_EQ(ZFull, ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
EXPECT_TRUE(ZFull == ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
EXPECT_TRUE(ZEmpty.isEmptySet());
EXPECT_EQ(ZOne, ConstantRange(APInt(One.getLower()).zext(20),
APInt(One.getUpper()).zext(20)));
EXPECT_EQ(ZSome, ConstantRange(APInt(Some.getLower()).zext(20),
APInt(Some.getUpper()).zext(20)));
EXPECT_EQ(ZWrap, ConstantRange(APInt(Wrap.getLower()).zext(20),
APInt(Wrap.getUpper()).zext(20)));
EXPECT_TRUE(ZOne == ConstantRange(APInt(One.getLower()).zext(20),
APInt(One.getUpper()).zext(20)));
EXPECT_TRUE(ZSome == ConstantRange(APInt(Some.getLower()).zext(20),
APInt(Some.getUpper()).zext(20)));
EXPECT_TRUE(ZWrap == ConstantRange(APInt(Wrap.getLower()).zext(20),
APInt(Wrap.getUpper()).zext(20)));
}
TEST_F(ConstantRangeTest, SExt) {
@ -178,15 +179,15 @@ TEST_F(ConstantRangeTest, SExt) {
ConstantRange SOne = One.signExtend(20);
ConstantRange SSome = Some.signExtend(20);
ConstantRange SWrap = Wrap.signExtend(20);
EXPECT_EQ(SFull, ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
APInt(20, INT16_MAX + 1, true)));
EXPECT_TRUE(SFull == ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
APInt(20, INT16_MAX + 1, true)));
EXPECT_TRUE(SEmpty.isEmptySet());
EXPECT_EQ(SOne, ConstantRange(APInt(One.getLower()).sext(20),
APInt(One.getUpper()).sext(20)));
EXPECT_EQ(SSome, ConstantRange(APInt(Some.getLower()).sext(20),
APInt(Some.getUpper()).sext(20)));
EXPECT_EQ(SWrap, ConstantRange(APInt(Wrap.getLower()).sext(20),
APInt(Wrap.getUpper()).sext(20)));
EXPECT_TRUE(SOne == ConstantRange(APInt(One.getLower()).sext(20),
APInt(One.getUpper()).sext(20)));
EXPECT_TRUE(SSome == ConstantRange(APInt(Some.getLower()).sext(20),
APInt(Some.getUpper()).sext(20)));
EXPECT_TRUE(SWrap == ConstantRange(APInt(Wrap.getLower()).sext(20),
APInt(Wrap.getUpper()).sext(20)));
}
TEST_F(ConstantRangeTest, IntersectWith) {
@ -202,150 +203,150 @@ TEST_F(ConstantRangeTest, IntersectWith) {
EXPECT_TRUE(Full.intersectWith(Some) == Some);
EXPECT_TRUE(Some.intersectWith(Wrap).isEmptySet());
EXPECT_TRUE(One.intersectWith(Wrap).isEmptySet());
EXPECT_EQ(One.intersectWith(Wrap), Wrap.intersectWith(One));
EXPECT_TRUE(One.intersectWith(Wrap) == Wrap.intersectWith(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_EQ(LHS.intersectWith(RHS), LHS);
EXPECT_TRUE(LHS.intersectWith(RHS) == LHS);
}
TEST_F(ConstantRangeTest, UnionWith) {
EXPECT_EQ(Wrap.unionWith(One),
ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
EXPECT_EQ(One.unionWith(Wrap), Wrap.unionWith(One));
EXPECT_TRUE(Wrap.unionWith(One) ==
ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
EXPECT_TRUE(One.unionWith(Wrap) == Wrap.unionWith(One));
EXPECT_TRUE(Empty.unionWith(Empty).isEmptySet());
EXPECT_TRUE(Full.unionWith(Full).isFullSet());
EXPECT_TRUE(Some.unionWith(Wrap).isFullSet());
// PR4545
EXPECT_EQ(ConstantRange(APInt(16, 14), APInt(16, 1)).unionWith(
ConstantRange(APInt(16, 0), APInt(16, 8))),
ConstantRange(APInt(16, 14), APInt(16, 8)));
EXPECT_EQ(ConstantRange(APInt(16, 6), APInt(16, 4)).unionWith(
ConstantRange(APInt(16, 4), APInt(16, 0))),
ConstantRange(16));
EXPECT_EQ(ConstantRange(APInt(16, 1), APInt(16, 0)).unionWith(
ConstantRange(APInt(16, 2), APInt(16, 1))),
ConstantRange(16));
EXPECT_TRUE(ConstantRange(APInt(16, 14), APInt(16, 1)).unionWith(
ConstantRange(APInt(16, 0), APInt(16, 8))) ==
ConstantRange(APInt(16, 14), APInt(16, 8)));
EXPECT_TRUE(ConstantRange(APInt(16, 6), APInt(16, 4)).unionWith(
ConstantRange(APInt(16, 4), APInt(16, 0))) ==
ConstantRange(16));
EXPECT_TRUE(ConstantRange(APInt(16, 1), APInt(16, 0)).unionWith(
ConstantRange(APInt(16, 2), APInt(16, 1))) ==
ConstantRange(16));
}
TEST_F(ConstantRangeTest, SubtractAPInt) {
EXPECT_TRUE(Full.subtract(APInt(16, 4)).isFullSet());
EXPECT_TRUE(Empty.subtract(APInt(16, 4)).isEmptySet());
EXPECT_EQ(Some.subtract(APInt(16, 4)),
ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
EXPECT_EQ(Wrap.subtract(APInt(16, 4)),
ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
EXPECT_EQ(One.subtract(APInt(16, 4)),
ConstantRange(APInt(16, 0x6)));
EXPECT_TRUE(Some.subtract(APInt(16, 4)) ==
ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
EXPECT_TRUE(Wrap.subtract(APInt(16, 4)) ==
ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
EXPECT_TRUE(One.subtract(APInt(16, 4)) ==
ConstantRange(APInt(16, 0x6)));
}
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);
EXPECT_EQ(Full.add(Wrap), Full);
EXPECT_EQ(Empty.add(Empty), Empty);
EXPECT_EQ(Empty.add(One), Empty);
EXPECT_EQ(Empty.add(Some), Empty);
EXPECT_EQ(Empty.add(Wrap), Empty);
EXPECT_TRUE(Full.add(Full) == Full);
EXPECT_TRUE(Full.add(Empty) == Empty);
EXPECT_TRUE(Full.add(One) == Full);
EXPECT_TRUE(Full.add(Some) == Full);
EXPECT_TRUE(Full.add(Wrap) == Full);
EXPECT_TRUE(Empty.add(Empty) == Empty);
EXPECT_TRUE(Empty.add(One) == Empty);
EXPECT_TRUE(Empty.add(Some) == Empty);
EXPECT_TRUE(Empty.add(Wrap) == Empty);
EXPECT_TRUE(Empty.add(APInt(16, 4)).isEmptySet());
EXPECT_EQ(Some.add(APInt(16, 4)),
ConstantRange(APInt(16, 0xe), APInt(16, 0xaae)));
EXPECT_EQ(Wrap.add(APInt(16, 4)),
ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
EXPECT_EQ(One.add(APInt(16, 4)),
ConstantRange(APInt(16, 0xe)));
EXPECT_TRUE(Some.add(APInt(16, 4)) ==
ConstantRange(APInt(16, 0xe), APInt(16, 0xaae)));
EXPECT_TRUE(Wrap.add(APInt(16, 4)) ==
ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
EXPECT_TRUE(One.add(APInt(16, 4)) ==
ConstantRange(APInt(16, 0xe)));
}
TEST_F(ConstantRangeTest, Multiply) {
EXPECT_EQ(Full.multiply(Full), Full);
EXPECT_EQ(Full.multiply(Empty), Empty);
EXPECT_EQ(Full.multiply(One), Full);
EXPECT_EQ(Full.multiply(Some), Full);
EXPECT_EQ(Full.multiply(Wrap), Full);
EXPECT_EQ(Empty.multiply(Empty), Empty);
EXPECT_EQ(Empty.multiply(One), Empty);
EXPECT_EQ(Empty.multiply(Some), Empty);
EXPECT_EQ(Empty.multiply(Wrap), Empty);
EXPECT_EQ(One.multiply(One), ConstantRange(APInt(16, 0xa*0xa),
APInt(16, 0xa*0xa + 1)));
EXPECT_EQ(One.multiply(Some), ConstantRange(APInt(16, 0xa*0xa),
APInt(16, 0xa*0xaa9 + 1)));
EXPECT_TRUE(Full.multiply(Full) == Full);
EXPECT_TRUE(Full.multiply(Empty) == Empty);
EXPECT_TRUE(Full.multiply(One) == Full);
EXPECT_TRUE(Full.multiply(Some) == Full);
EXPECT_TRUE(Full.multiply(Wrap) == Full);
EXPECT_TRUE(Empty.multiply(Empty) == Empty);
EXPECT_TRUE(Empty.multiply(One) == Empty);
EXPECT_TRUE(Empty.multiply(Some) == Empty);
EXPECT_TRUE(Empty.multiply(Wrap) == Empty);
EXPECT_TRUE(One.multiply(One) == ConstantRange(APInt(16, 0xa*0xa),
APInt(16, 0xa*0xa + 1)));
EXPECT_TRUE(One.multiply(Some) == ConstantRange(APInt(16, 0xa*0xa),
APInt(16, 0xa*0xaa9 + 1)));
EXPECT_TRUE(One.multiply(Wrap).isFullSet());
EXPECT_TRUE(Some.multiply(Some).isFullSet());
EXPECT_EQ(Some.multiply(Wrap), Full);
EXPECT_EQ(Wrap.multiply(Wrap), Full);
EXPECT_TRUE(Some.multiply(Wrap) == Full);
EXPECT_TRUE(Wrap.multiply(Wrap) == Full);
// http://llvm.org/PR4545
EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
ConstantRange(APInt(4, 6), APInt(4, 2))),
ConstantRange(4, /*isFullSet=*/true));
EXPECT_TRUE(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
ConstantRange(APInt(4, 6), APInt(4, 2))) ==
ConstantRange(4, /*isFullSet=*/true));
}
TEST_F(ConstantRangeTest, UMax) {
EXPECT_TRUE(Full.umax(Full).isFullSet());
EXPECT_TRUE(Full.umax(Empty).isEmptySet());
EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_TRUE(Full.umax(Some) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_TRUE(Full.umax(Wrap).isFullSet());
EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_EQ(Empty.umax(Empty), Empty);
EXPECT_EQ(Empty.umax(Some), Empty);
EXPECT_EQ(Empty.umax(Wrap), Empty);
EXPECT_EQ(Empty.umax(One), Empty);
EXPECT_EQ(Some.umax(Some), Some);
EXPECT_EQ(Some.umax(Wrap), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_EQ(Some.umax(One), Some);
EXPECT_TRUE(Full.umax(Some) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_TRUE(Empty.umax(Empty) == Empty);
EXPECT_TRUE(Empty.umax(Some) == Empty);
EXPECT_TRUE(Empty.umax(Wrap) == Empty);
EXPECT_TRUE(Empty.umax(One) == Empty);
EXPECT_TRUE(Some.umax(Some) == Some);
EXPECT_TRUE(Some.umax(Wrap) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_TRUE(Some.umax(One) == Some);
// TODO: ConstantRange is currently over-conservative here.
EXPECT_EQ(Wrap.umax(Wrap), Full);
EXPECT_EQ(Wrap.umax(One), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_EQ(One.umax(One), One);
EXPECT_TRUE(Wrap.umax(Wrap) == Full);
EXPECT_TRUE(Wrap.umax(One) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_TRUE(One.umax(One) == One);
}
TEST_F(ConstantRangeTest, SMax) {
EXPECT_TRUE(Full.smax(Full).isFullSet());
EXPECT_TRUE(Full.smax(Empty).isEmptySet());
EXPECT_EQ(Full.smax(Some), ConstantRange(APInt(16, 0xa),
APInt::getSignedMinValue(16)));
EXPECT_TRUE(Full.smax(Some) == ConstantRange(APInt(16, 0xa),
APInt::getSignedMinValue(16)));
EXPECT_TRUE(Full.smax(Wrap).isFullSet());
EXPECT_EQ(Full.smax(One), ConstantRange(APInt(16, 0xa),
APInt::getSignedMinValue(16)));
EXPECT_EQ(Empty.smax(Empty), Empty);
EXPECT_EQ(Empty.smax(Some), Empty);
EXPECT_EQ(Empty.smax(Wrap), Empty);
EXPECT_EQ(Empty.smax(One), Empty);
EXPECT_EQ(Some.smax(Some), Some);
EXPECT_EQ(Some.smax(Wrap), ConstantRange(APInt(16, 0xa),
APInt(16, (uint64_t)INT16_MIN)));
EXPECT_EQ(Some.smax(One), Some);
EXPECT_EQ(Wrap.smax(One), ConstantRange(APInt(16, 0xa),
APInt(16, (uint64_t)INT16_MIN)));
EXPECT_EQ(One.smax(One), One);
EXPECT_TRUE(Full.smax(One) == ConstantRange(APInt(16, 0xa),
APInt::getSignedMinValue(16)));
EXPECT_TRUE(Empty.smax(Empty) == Empty);
EXPECT_TRUE(Empty.smax(Some) == Empty);
EXPECT_TRUE(Empty.smax(Wrap) == Empty);
EXPECT_TRUE(Empty.smax(One) == Empty);
EXPECT_TRUE(Some.smax(Some) == Some);
EXPECT_TRUE(Some.smax(Wrap) == ConstantRange(APInt(16, 0xa),
APInt(16, (uint64_t)INT16_MIN)));
EXPECT_TRUE(Some.smax(One) == Some);
EXPECT_TRUE(Wrap.smax(One) == ConstantRange(APInt(16, 0xa),
APInt(16, (uint64_t)INT16_MIN)));
EXPECT_TRUE(One.smax(One) == One);
}
TEST_F(ConstantRangeTest, UDiv) {
EXPECT_EQ(Full.udiv(Full), Full);
EXPECT_EQ(Full.udiv(Empty), Empty);
EXPECT_EQ(Full.udiv(One), ConstantRange(APInt(16, 0),
APInt(16, 0xffff / 0xa + 1)));
EXPECT_EQ(Full.udiv(Some), ConstantRange(APInt(16, 0),
APInt(16, 0xffff / 0xa + 1)));
EXPECT_EQ(Full.udiv(Wrap), Full);
EXPECT_EQ(Empty.udiv(Empty), Empty);
EXPECT_EQ(Empty.udiv(One), Empty);
EXPECT_EQ(Empty.udiv(Some), Empty);
EXPECT_EQ(Empty.udiv(Wrap), Empty);
EXPECT_EQ(One.udiv(One), ConstantRange(APInt(16, 1)));
EXPECT_EQ(One.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 2)));
EXPECT_EQ(One.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
EXPECT_EQ(Some.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 0x111)));
EXPECT_EQ(Some.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
EXPECT_EQ(Wrap.udiv(Wrap), Full);
EXPECT_TRUE(Full.udiv(Full) == Full);
EXPECT_TRUE(Full.udiv(Empty) == Empty);
EXPECT_TRUE(Full.udiv(One) == ConstantRange(APInt(16, 0),
APInt(16, 0xffff / 0xa + 1)));
EXPECT_TRUE(Full.udiv(Some) == ConstantRange(APInt(16, 0),
APInt(16, 0xffff / 0xa + 1)));
EXPECT_TRUE(Full.udiv(Wrap) == Full);
EXPECT_TRUE(Empty.udiv(Empty) == Empty);
EXPECT_TRUE(Empty.udiv(One) == Empty);
EXPECT_TRUE(Empty.udiv(Some) == Empty);
EXPECT_TRUE(Empty.udiv(Wrap) == Empty);
EXPECT_TRUE(One.udiv(One) == ConstantRange(APInt(16, 1)));
EXPECT_TRUE(One.udiv(Some) == ConstantRange(APInt(16, 0), APInt(16, 2)));
EXPECT_TRUE(One.udiv(Wrap) == ConstantRange(APInt(16, 0), APInt(16, 0xb)));
EXPECT_TRUE(Some.udiv(Some) == ConstantRange(APInt(16, 0), APInt(16, 0x111)));
EXPECT_TRUE(Some.udiv(Wrap) == ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
EXPECT_TRUE(Wrap.udiv(Wrap) == Full);
}
} // anonymous namespace