mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-11 02:16:50 +00:00
[ConstantRangeTest] Generalize intersection testing code; NFC
Extract the exhaustive intersection tests into a separate function, so that it may be reused for unions as well. llvm-svn: 357874
This commit is contained in:
parent
4246106aba
commit
c664c2a5ec
@ -363,7 +363,8 @@ TEST_F(ConstantRangeTest, IntersectWith) {
|
||||
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 15), APInt(32, 0)));
|
||||
}
|
||||
|
||||
TEST_F(ConstantRangeTest, IntersectWithExhaustive) {
|
||||
template<typename Fn1, typename Fn2>
|
||||
void testBinarySetOperationExhaustive(Fn1 OpFn, Fn2 InResultFn) {
|
||||
unsigned Bits = 4;
|
||||
EnumerateTwoConstantRanges(Bits,
|
||||
[=](const ConstantRange &CR1, const ConstantRange &CR2) {
|
||||
@ -379,7 +380,7 @@ TEST_F(ConstantRangeTest, IntersectWithExhaustive) {
|
||||
|
||||
APInt Num(Bits, 0);
|
||||
for (unsigned I = 0, Limit = 1 << Bits; I < Limit; ++I, ++Num) {
|
||||
if (!CR1.contains(Num) || !CR2.contains(Num)) {
|
||||
if (!InResultFn(CR1, CR2, Num)) {
|
||||
if (HaveRange3)
|
||||
HaveInterrupt3 = true;
|
||||
else if (HaveRange2)
|
||||
@ -409,12 +410,9 @@ TEST_F(ConstantRangeTest, IntersectWithExhaustive) {
|
||||
|
||||
assert(!HaveInterrupt3 && "Should have at most three ranges");
|
||||
|
||||
ConstantRange SmallestCR =
|
||||
CR1.intersectWith(CR2, ConstantRange::Smallest);
|
||||
ConstantRange UnsignedCR =
|
||||
CR1.intersectWith(CR2, ConstantRange::Unsigned);
|
||||
ConstantRange SignedCR =
|
||||
CR1.intersectWith(CR2, ConstantRange::Signed);
|
||||
ConstantRange SmallestCR = OpFn(CR1, CR2, ConstantRange::Smallest);
|
||||
ConstantRange UnsignedCR = OpFn(CR1, CR2, ConstantRange::Unsigned);
|
||||
ConstantRange SignedCR = OpFn(CR1, CR2, ConstantRange::Signed);
|
||||
|
||||
if (!HaveRange1) {
|
||||
EXPECT_TRUE(SmallestCR.isEmptySet());
|
||||
@ -492,6 +490,17 @@ TEST_F(ConstantRangeTest, IntersectWithExhaustive) {
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(ConstantRangeTest, IntersectWithExhaustive) {
|
||||
testBinarySetOperationExhaustive(
|
||||
[](const ConstantRange &CR1, const ConstantRange &CR2,
|
||||
ConstantRange::PreferredRangeType Type) {
|
||||
return CR1.intersectWith(CR2, Type);
|
||||
},
|
||||
[](const ConstantRange &CR1, const ConstantRange &CR2, const APInt &N) {
|
||||
return CR1.contains(N) && CR2.contains(N);
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(ConstantRangeTest, UnionWith) {
|
||||
EXPECT_EQ(Wrap.unionWith(One),
|
||||
ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user