[llvm] [APInt] Correct backwards static_assert condition. (PR #103641)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 13 22:25:28 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/103641.diff
1 Files Affected:
- (modified) llvm/lib/Support/APInt.cpp (+2-2)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/103641
More information about the llvm-commits
mailing list