aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-10-15 21:35:57 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-10-15 21:52:17 +0200
commit82e858d1bf4bbfa6c25cbf8ae86aced85e4b78f5 (patch)
tree033509076d19fd05c5da2bcb3a6ea87257f6e944 /llvm/unittests/IR/ConstantRangeTest.cpp
parentd0e7bdc208491fd5d4245878c1ec2962694e2baa (diff)
downloadllvm-82e858d1bf4bbfa6c25cbf8ae86aced85e4b78f5.zip
llvm-82e858d1bf4bbfa6c25cbf8ae86aced85e4b78f5.tar.gz
llvm-82e858d1bf4bbfa6c25cbf8ae86aced85e4b78f5.tar.bz2
[ConstantRange] Better diagnostic for correctness test failure (NFC)
Print a friendly error message including the inputs, result and not-contained element if an exhaustive correctness test fails, same as we do if the optimality test fails.
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index 3a37b732..45d50cc 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -95,7 +95,17 @@ bool PreferSmallestNonFullSigned(const ConstantRange &CR1,
return PreferSmallestSigned(CR1, CR2);
}
+testing::AssertionResult rangeContains(const ConstantRange &CR, const APInt &N,
+ ArrayRef<ConstantRange> Inputs) {
+ if (CR.contains(N))
+ return testing::AssertionSuccess();
+ testing::AssertionResult Result = testing::AssertionFailure();
+ Result << CR << " does not contain " << N << " for inputs: ";
+ for (const ConstantRange &Input : Inputs)
+ Result << Input << ", ";
+ return Result;
+}
// Check whether constant range CR is an optimal approximation of the set
// Elems under the given PreferenceFn. The preference function should return
@@ -106,7 +116,7 @@ static void TestRange(const ConstantRange &CR, const SmallBitVector &Elems,
// Check conservative correctness.
for (unsigned Elem : Elems.set_bits()) {
- EXPECT_TRUE(CR.contains(APInt(BitWidth, Elem)));
+ EXPECT_TRUE(rangeContains(CR, APInt(BitWidth, Elem), Inputs));
}
// Make sure we have at least one element for the code below.
@@ -198,7 +208,7 @@ static void TestBinaryOpExhaustiveCorrectnessOnly(BinaryRangeFn RangeFn,
ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
if (Optional<APInt> ResultN = IntFn(N1, N2)) {
- EXPECT_TRUE(ResultCR.contains(*ResultN));
+ EXPECT_TRUE(rangeContains(ResultCR, *ResultN, {CR1, CR2}));
}
});
});