forked from OSchip/llvm-project
[APInt] Fix a bug in lshr by a value more than 64 bits above the bit width.
This was throwing an assert because we determined the intra-word shift amount by subtracting the size of the full word shift from the total shift amount. But we failed to account for the fact that we clipped the full word shifts by total words first. To fix this just calculate the intra-word shift as the remainder of dividing by bits per word. llvm-svn: 300405
This commit is contained in:
parent
909b3376ba
commit
9edfb08d93
|
@ -1188,7 +1188,7 @@ void APInt::lshrInPlace(unsigned shiftAmt) {
|
|||
|
||||
// Fill in first Words - ShiftFullWords by shifting.
|
||||
lshrWords(pVal, pVal + ShiftFullWords, Words - ShiftFullWords,
|
||||
shiftAmt - (ShiftFullWords * APINT_BITS_PER_WORD));
|
||||
shiftAmt % APINT_BITS_PER_WORD);
|
||||
|
||||
// The remaining high words are all zero.
|
||||
for (unsigned I = Words - ShiftFullWords; I != Words; ++I)
|
||||
|
|
|
@ -37,6 +37,11 @@ TEST(APIntTest, i64_ArithmeticRightShiftNegative) {
|
|||
EXPECT_EQ(neg_one, neg_one.ashr(7));
|
||||
}
|
||||
|
||||
TEST(APIntTest, i64_LogicalRightShiftNegative) {
|
||||
const APInt neg_one(128, static_cast<uint64_t>(-1), true);
|
||||
EXPECT_EQ(0, neg_one.lshr(257));
|
||||
}
|
||||
|
||||
TEST(APIntTest, i128_NegativeCount) {
|
||||
APInt Minus3(128, static_cast<uint64_t>(-3), true);
|
||||
EXPECT_EQ(126u, Minus3.countLeadingOnes());
|
||||
|
|
Loading…
Reference in New Issue