[llvm] r302882 - [APInt] Fix a case where udivrem might delete and create a new allocation instead of reusing the original.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri May 12 00:21:10 PDT 2017


Author: ctopper
Date: Fri May 12 02:21:09 2017
New Revision: 302882

URL: http://llvm.org/viewvc/llvm-project?rev=302882&view=rev
Log:
[APInt] Fix a case where udivrem might delete and create a new allocation instead of reusing the original.

Modified:
    llvm/trunk/lib/Support/APInt.cpp

Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=302882&r1=302881&r2=302882&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Fri May 12 02:21:09 2017
@@ -1686,8 +1686,11 @@ void APInt::udivrem(const APInt &LHS, co
     // 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;
   }
 




More information about the llvm-commits mailing list