Skip to content

Commit cbd3068

Browse files
authored
[APInt] Correct backwards static_assert condition. (#103641)
In order to guarantee that extracting 64 bits doesn't require more than 2 words, the word size would need to be 64 bits or more. If the word size was smaller than 64, like 32, you may need to read 3 words to get 64 bits.
1 parent f1cb64b commit cbd3068

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llvm/lib/Support/APInt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,14 @@ uint64_t APInt::extractBitsAsZExtValue(unsigned numBits,
496496
if (isSingleWord())
497497
return (U.VAL >> bitPosition) & maskBits;
498498

499+
static_assert(APINT_BITS_PER_WORD >= 64,
500+
"This code assumes only two words affected");
499501
unsigned loBit = whichBit(bitPosition);
500502
unsigned loWord = whichWord(bitPosition);
501503
unsigned hiWord = whichWord(bitPosition + numBits - 1);
502504
if (loWord == hiWord)
503505
return (U.pVal[loWord] >> loBit) & maskBits;
504506

505-
static_assert(APINT_BITS_PER_WORD <= 64,
506-
"This code assumes only two words affected");
507507
uint64_t retBits = U.pVal[loWord] >> loBit;
508508
retBits |= U.pVal[hiWord] << (APINT_BITS_PER_WORD - loBit);
509509
retBits &= maskBits;

0 commit comments

Comments
 (0)