OSDN Git Service

"fix" PR4612, which is a crash on:
authorChris Lattner <sabre@nondot.org>
Thu, 23 Jul 2009 21:26:18 +0000 (21:26 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 23 Jul 2009 21:26:18 +0000 (21:26 +0000)
%0 = malloc [3758096384 x i32]

The "malloc" instruction doesn't support 64-bits correctly (see PR715),
and should be removed.  Victor is actively working on fixing this, in
the meantime just don't crash.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76899 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp

index 30236e3..1135376 100644 (file)
@@ -5431,9 +5431,13 @@ void SelectionDAGLowering::visitMalloc(MallocInst &I) {
   // multiply on 64-bit targets.
   // FIXME: Malloc inst should go away: PR715.
   uint64_t ElementSize = TD->getTypeAllocSize(I.getType()->getElementType());
-  if (ElementSize != 1)
+  if (ElementSize != 1) {
+    // Src is always 32-bits, make sure the constant fits.
+    assert(Src.getValueType() == MVT::i32);
+    ElementSize = (uint32_t)ElementSize;
     Src = DAG.getNode(ISD::MUL, getCurDebugLoc(), Src.getValueType(),
                       Src, DAG.getConstant(ElementSize, Src.getValueType()));
+  }
   
   MVT IntPtr = TLI.getPointerTy();