diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 78d573966c6c99..2348a4c9b795e1 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -34,9 +34,7 @@ using namespace llvm; /// A utility function for allocating memory, checking for allocation failures, /// and ensuring the contents are zeroed. inline static uint64_t* getClearedMemory(unsigned numWords) { - uint64_t *result = new uint64_t[numWords]; - memset(result, 0, numWords * sizeof(uint64_t)); - return result; + return new uint64_t[numWords](); } /// A utility function for allocating memory and checking for allocation @@ -74,12 +72,15 @@ 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; - clearUnusedBits(); + if (isSigned && int64_t(val) < 0) { + U.pVal = getMemory(getNumWords()); + U.pVal[0] = val; + memset(&U.pVal[1], 0xFF, APINT_WORD_SIZE * (getNumWords() - 1)); + clearUnusedBits(); + } else { + U.pVal = getClearedMemory(getNumWords()); + U.pVal[0] = val; + } } void APInt::initSlowCase(const APInt& that) {