Skip to content

Commit 23f0fbf

Browse files
authored
[APInt] APInt::clearBitsSlowCase - fix cut+paste typo when merging lo/himasks (#141108)
Fixes #141098
1 parent 3ea2cec commit 23f0fbf

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

llvm/lib/Support/APInt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ void APInt::clearBitsSlowCase(unsigned LoBit, unsigned HiBit) {
349349
// Create a high mask with ones above HiBit.
350350
uint64_t HiMask = ~(WORDTYPE_MAX >> (APINT_BITS_PER_WORD - HiShiftAmt));
351351
// If LoWord and HiWord are equal, then we combine the masks. Otherwise,
352-
// set the bits in HiWord.
352+
// clear the bits in HiWord.
353353
if (HiWord == LoWord)
354-
LoMask &= HiMask;
354+
LoMask |= HiMask;
355355
else
356356
U.pVal[HiWord] &= HiMask;
357357
}

llvm/unittests/ADT/APIntTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,6 +2556,15 @@ TEST(APIntTest, clearBits) {
25562556
EXPECT_EQ(6u, i256.countl_one());
25572557
EXPECT_EQ(16u, i256.popcount());
25582558

2559+
APInt i299 = APInt::getAllOnes(299);
2560+
i299.clearBits(240, 250);
2561+
EXPECT_EQ(240u, i299.countr_one());
2562+
EXPECT_EQ(0u, i299.countr_zero());
2563+
EXPECT_EQ(299u, i299.getActiveBits());
2564+
EXPECT_EQ(0u, i299.countl_zero());
2565+
EXPECT_EQ(49u, i299.countl_one());
2566+
EXPECT_EQ(289u, i299.popcount());
2567+
25592568
APInt i311 = APInt::getAllOnes(311);
25602569
i311.clearBits(33, 99);
25612570
EXPECT_EQ(33u, i311.countr_one());

0 commit comments

Comments
 (0)