From an API perspective, it does not make a lot of sense that 0
is not a valid argument to this function. Add the exact check needed
to support it.
bool
ConstantRange::isSizeLargerThan(uint64_t MaxSize) const {
- assert(MaxSize && "MaxSize can't be 0.");
// If this a full set, we need special handling to avoid needing an extra bit
// to represent the size.
if (isFullSet())
- return APInt::getMaxValue(getBitWidth()).ugt(MaxSize - 1);
+ return MaxSize == 0 || APInt::getMaxValue(getBitWidth()).ugt(MaxSize - 1);
return (Upper - Lower).ugt(MaxSize);
}
}
}
+TEST_F(ConstantRangeTest, isSizeLargerThan) {
+ EXPECT_FALSE(Empty.isSizeLargerThan(0));
+
+ EXPECT_TRUE(Full.isSizeLargerThan(0));
+ EXPECT_TRUE(Full.isSizeLargerThan(65535));
+ EXPECT_FALSE(Full.isSizeLargerThan(65536));
+
+ EXPECT_TRUE(One.isSizeLargerThan(0));
+ EXPECT_FALSE(One.isSizeLargerThan(1));
+}
+
} // anonymous namespace