Skip to content

Commit b5ddcb9

Browse files
committed
[ConstantRange] TestAddWithNo*WrapExhaustive: check that all overflow means empty set
As disscussed in https://reviews.llvm.org/D69918 / https://reviews.llvm.org/D67339 that is an implied postcondition, but it's not really fully tested.
1 parent 76aee8a commit b5ddcb9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

llvm/unittests/IR/ConstantRangeTest.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,13 @@ static void TestAddWithNoSignedWrapExhaustive(Fn1 RangeFn, Fn2 IntFn) {
651651
ConstantRange CR = RangeFn(CR1, CR2);
652652
APInt Min = APInt::getSignedMaxValue(Bits);
653653
APInt Max = APInt::getSignedMinValue(Bits);
654+
bool AllOverflow = true;
654655
ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
655656
ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
656657
bool IsOverflow = false;
657658
APInt N = IntFn(IsOverflow, N1, N2);
658659
if (!IsOverflow) {
660+
AllOverflow = false;
659661
if (N.slt(Min))
660662
Min = N;
661663
if (N.sgt(Max))
@@ -664,6 +666,9 @@ static void TestAddWithNoSignedWrapExhaustive(Fn1 RangeFn, Fn2 IntFn) {
664666
}
665667
});
666668
});
669+
670+
EXPECT_EQ(CR.isEmptySet(), AllOverflow);
671+
667672
if (!CR1.isSignWrappedSet() && !CR2.isSignWrappedSet()) {
668673
if (Min.sgt(Max)) {
669674
EXPECT_TRUE(CR.isEmptySet());
@@ -684,11 +689,13 @@ static void TestAddWithNoUnsignedWrapExhaustive(Fn1 RangeFn, Fn2 IntFn) {
684689
ConstantRange CR = RangeFn(CR1, CR2);
685690
APInt Min = APInt::getMaxValue(Bits);
686691
APInt Max = APInt::getMinValue(Bits);
692+
bool AllOverflow = true;
687693
ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
688694
ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
689695
bool IsOverflow = false;
690696
APInt N = IntFn(IsOverflow, N1, N2);
691697
if (!IsOverflow) {
698+
AllOverflow = false;
692699
if (N.ult(Min))
693700
Min = N;
694701
if (N.ugt(Max))
@@ -698,6 +705,8 @@ static void TestAddWithNoUnsignedWrapExhaustive(Fn1 RangeFn, Fn2 IntFn) {
698705
});
699706
});
700707

708+
EXPECT_EQ(CR.isEmptySet(), AllOverflow);
709+
701710
if (!CR1.isWrappedSet() && !CR2.isWrappedSet()) {
702711
if (Min.ugt(Max)) {
703712
EXPECT_TRUE(CR.isEmptySet());
@@ -722,12 +731,14 @@ static void TestAddWithNoSignedUnsignedWrapExhaustive(Fn1 RangeFn,
722731
APInt UMax = APInt::getMinValue(Bits);
723732
APInt SMin = APInt::getSignedMaxValue(Bits);
724733
APInt SMax = APInt::getSignedMinValue(Bits);
734+
bool AllOverflow = true;
725735
ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
726736
ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
727737
bool IsOverflow = false, IsSignedOverflow = false;
728738
APInt N = IntFnSigned(IsSignedOverflow, N1, N2);
729739
(void) IntFnUnsigned(IsOverflow, N1, N2);
730740
if (!IsSignedOverflow && !IsOverflow) {
741+
AllOverflow = false;
731742
if (N.slt(SMin))
732743
SMin = N;
733744
if (N.sgt(SMax))
@@ -741,6 +752,8 @@ static void TestAddWithNoSignedUnsignedWrapExhaustive(Fn1 RangeFn,
741752
});
742753
});
743754

755+
EXPECT_EQ(CR.isEmptySet(), AllOverflow);
756+
744757
if (!CR1.isWrappedSet() && !CR2.isWrappedSet() &&
745758
!CR1.isSignWrappedSet() && !CR2.isSignWrappedSet()) {
746759
if (UMin.ugt(UMax) || SMin.sgt(SMax)) {

0 commit comments

Comments
 (0)