aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2024-08-14 00:28:24 -0700
committerGitHub <noreply@github.com>2024-08-14 00:28:24 -0700
commitcbd306806ad4b518e664f122838e45d709db0ef6 (patch)
treed4de0749220ac60dbd67c7d2fa60efae994563aa
parentf1cb64b6f07184a3624ebb77f3f0e0bddafea1a4 (diff)
downloadllvm-cbd306806ad4b518e664f122838e45d709db0ef6.zip
llvm-cbd306806ad4b518e664f122838e45d709db0ef6.tar.gz
llvm-cbd306806ad4b518e664f122838e45d709db0ef6.tar.bz2
[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.
-rw-r--r--llvm/lib/Support/APInt.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 87edf74e..fe22e9b 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -496,14 +496,14 @@ uint64_t APInt::extractBitsAsZExtValue(unsigned numBits,
if (isSingleWord())
return (U.VAL >> bitPosition) & maskBits;
+ static_assert(APINT_BITS_PER_WORD >= 64,
+ "This code assumes only two words affected");
unsigned loBit = whichBit(bitPosition);
unsigned loWord = whichWord(bitPosition);
unsigned hiWord = whichWord(bitPosition + numBits - 1);
if (loWord == hiWord)
return (U.pVal[loWord] >> loBit) & maskBits;
- static_assert(APINT_BITS_PER_WORD <= 64,
- "This code assumes only two words affected");
uint64_t retBits = U.pVal[loWord] >> loBit;
retBits |= U.pVal[hiWord] << (APINT_BITS_PER_WORD - loBit);
retBits &= maskBits;