[llvm] [APInt] Correct backwards static_assert condition. (PR #103641)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 13 22:25:00 PDT 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/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.
>From 268208fd3475307c7ea15426ba34db3a32ead390 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 13 Aug 2024 22:18:24 -0700
Subject: [PATCH] [APInt] Correct backwards static_assert condition.
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.
---
llvm/lib/Support/APInt.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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