[llvm] [APInt] remove getClearedMemory and improve slow initialization (PR #106945)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 2 00:56:57 PDT 2024
================
@@ -74,11 +66,14 @@ inline static unsigned getDigit(char cdigit, uint8_t radix) {
void APInt::initSlowCase(uint64_t val, bool isSigned) {
- U.pVal = getClearedMemory(getNumWords());
- U.pVal[0] = val;
- if (isSigned && int64_t(val) < 0)
- for (unsigned i = 1; i < getNumWords(); ++i)
- U.pVal[i] = WORDTYPE_MAX;
+ if (isSigned && int64_t(val) < 0) {
+ U.pVal = new WordType[getNumWords()];
+ U.pVal[0] = val;
+ memset(&U.pVal[1], 0xFF, sizeof(WordType) * (getNumWords() - 1));
+ } else {
+ U.pVal = new WordType[getNumWords()]();
+ U.pVal[0] = val;
----------------
nikic wrote:
This doesn't look correct to me. Not that clearUnusedBits() only clears bits in the high order word, so you will leave everything between the high order word and the low order word uninitialized.
https://github.com/llvm/llvm-project/pull/106945
More information about the llvm-commits
mailing list