From 2dfa410c1dc28900736a1f745ce9dd060fd6293b Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 12 May 2017 07:21:09 +0000 Subject: [PATCH] [APInt] Fix a case where udivrem might delete and create a new allocation instead of reusing the original. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302882 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/APInt.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index d43e1a817c9..361fc97c2ec 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -1686,8 +1686,11 @@ void APInt::udivrem(const APInt &LHS, const APInt &RHS, // There is only one word to consider so use the native versions. uint64_t lhsValue = LHS.U.pVal[0]; uint64_t rhsValue = RHS.U.pVal[0]; - Quotient = APInt(LHS.getBitWidth(), lhsValue / rhsValue); - Remainder = APInt(LHS.getBitWidth(), lhsValue % rhsValue); + // Make sure there is enough space to hold the results. + Quotient.reallocate(LHS.BitWidth); + Remainder.reallocate(LHS.BitWidth); + Quotient = lhsValue / rhsValue; + Remainder = lhsValue % rhsValue; return; }