A real solution for the first part of PR5445
[oota-llvm.git] / lib / Bitcode / Reader / BitcodeReader.cpp
index 68527e3d474992102661fe95bb111ef951888fac..9916388dad100060067148d4a06dc183080b892d 100644 (file)
@@ -2101,8 +2101,10 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
       if (!Ty || !Size) return Error("Invalid MALLOC record");
       if (!CurBB) return Error("Invalid malloc instruction with no BB");
       const Type *Int32Ty = IntegerType::getInt32Ty(CurBB->getContext());
+      Constant *AllocSize = ConstantExpr::getSizeOf(Ty->getElementType());
+      AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, Int32Ty);
       I = CallInst::CreateMalloc(CurBB, Int32Ty, Ty->getElementType(),
-                                 Size, NULL);
+                                 AllocSize, Size, NULL);
       InstructionList.push_back(I);
       break;
     }