[llvm] r300811 - [APInt] Add back the asserts that check that the APInt shift methods aren't called with values larger than BitWidth.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 19 19:03:10 PDT 2017
Author: ctopper
Date: Wed Apr 19 21:03:09 2017
New Revision: 300811
URL: http://llvm.org/viewvc/llvm-project?rev=300811&view=rev
Log:
[APInt] Add back the asserts that check that the APInt shift methods aren't called with values larger than BitWidth.
The underlying tcShiftRight/tcShiftLeft functions support the larger bit widths but the APInt interface shouldn't rely on that.
Modified:
llvm/trunk/include/llvm/ADT/APInt.h
llvm/trunk/unittests/ADT/APIntTest.cpp
Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=300811&r1=300810&r2=300811&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Wed Apr 19 21:03:09 2017
@@ -844,8 +844,9 @@ public:
///
/// \returns *this after shifting left by ShiftAmt
APInt &operator<<=(unsigned ShiftAmt) {
+ assert(ShiftAmt <= BitWidth && "Invalid shift amount");
if (isSingleWord()) {
- if (ShiftAmt >= BitWidth)
+ if (ShiftAmt == BitWidth)
VAL = 0;
else
VAL <<= ShiftAmt;
@@ -890,8 +891,9 @@ public:
/// Logical right-shift this APInt by ShiftAmt in place.
void lshrInPlace(unsigned ShiftAmt) {
+ assert(ShiftAmt <= BitWidth && "Invalid shift amount");
if (isSingleWord()) {
- if (ShiftAmt >= BitWidth)
+ if (ShiftAmt == BitWidth)
VAL = 0;
else
VAL >>= ShiftAmt;
Modified: llvm/trunk/unittests/ADT/APIntTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APIntTest.cpp?rev=300811&r1=300810&r2=300811&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APIntTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APIntTest.cpp Wed Apr 19 21:03:09 2017
@@ -2021,7 +2021,7 @@ TEST(APIntTest, LogicalRightShift) {
// Ensure we handle large shifts of multi-word.
const APInt neg_one(128, static_cast<uint64_t>(-1), true);
- EXPECT_EQ(0, neg_one.lshr(257));
+ EXPECT_EQ(0, neg_one.lshr(128));
}
TEST(APIntTest, LeftShift) {
@@ -2054,7 +2054,7 @@ TEST(APIntTest, LeftShift) {
// Ensure we handle large shifts of multi-word.
const APInt neg_one(128, static_cast<uint64_t>(-1), true);
- EXPECT_EQ(0, neg_one.shl(257));
+ EXPECT_EQ(0, neg_one.shl(128));
}
} // end anonymous namespace
More information about the llvm-commits
mailing list