[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
This commit is contained in:
Craig Topper
2017-05-12 07:21:09 +00:00
parent b62f430846
commit 2dfa410c1d
+5 -2
View File
@@ -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;
}