[llvm] cbd3068 - [APInt] Correct backwards static_assert condition. (#103641)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 14 00:28:26 PDT 2024
Author: Craig Topper
Date: 2024-08-14T00:28:24-07:00
New Revision: cbd306806ad4b518e664f122838e45d709db0ef6
URL: https://github.com/llvm/llvm-project/commit/cbd306806ad4b518e664f122838e45d709db0ef6
DIFF: https://github.com/llvm/llvm-project/commit/cbd306806ad4b518e664f122838e45d709db0ef6.diff
LOG: [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.
Added:
Modified:
llvm/lib/Support/APInt.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 87edf74e191d8..fe22e9ba04b6f 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;
More information about the llvm-commits
mailing list