///
/// \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;
/// 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;
// 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) {
// 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