diff options
author | Victor Hernandez <vhernandez@apple.com> | 2009-09-24 17:47:49 +0000 |
---|---|---|
committer | Victor Hernandez <vhernandez@apple.com> | 2009-09-24 17:47:49 +0000 |
commit | 46cd46731082e7ad6cd3901e2a13f68d7a774cab (patch) | |
tree | 20ff75183155d9aea9233c735252cd4a21da91d6 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | 5fe313d6e04677908225d4e570f9d989151ba377 (diff) | |
download | bcm5719-llvm-46cd46731082e7ad6cd3901e2a13f68d7a774cab.tar.gz bcm5719-llvm-46cd46731082e7ad6cd3901e2a13f68d7a774cab.zip |
Auto-upgrade malloc instructions to malloc calls.
Reviewed by Devang Patel.
llvm-svn: 82694
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index f3ab806271a..be0ec4bd85b 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2046,14 +2046,21 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { } case bitc::FUNC_CODE_INST_MALLOC: { // MALLOC: [instty, op, align] + // Autoupgrade malloc instruction to malloc call. if (Record.size() < 3) return Error("Invalid MALLOC record"); const PointerType *Ty = dyn_cast_or_null<PointerType>(getTypeByID(Record[0])); Value *Size = getFnValueByID(Record[1], Type::getInt32Ty(Context)); - unsigned Align = Record[2]; if (!Ty || !Size) return Error("Invalid MALLOC record"); - I = new MallocInst(Ty->getElementType(), Size, (1 << Align) >> 1); + if (!CurBB) return Error("Invalid malloc instruction with no BB"); + const Type* Int32Ty = IntegerType::getInt32Ty(CurBB->getContext()); + if (Size->getType() != Int32Ty) + Size = CastInst::CreateIntegerCast(Size, Int32Ty, false /*ZExt*/, + "", CurBB); + Value* Malloc = CallInst::CreateMalloc(CurBB, Int32Ty, + Ty->getElementType(), Size, NULL); + I = cast<Instruction>(Malloc); InstructionList.push_back(I); break; } |