From 47fc9d336619f45c0d6c80750cfbeb01b7dda207 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 9 Nov 2009 07:12:01 +0000 Subject: [PATCH] make this handle redefinition of malloc with different prototype correctly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86525 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Instructions.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index f343bd18daa..9817e4c78a8 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -568,8 +568,7 @@ static Instruction* createFree(Value* Source, Instruction *InsertBefore, const Type *VoidTy = Type::getVoidTy(M->getContext()); const Type *IntPtrTy = Type::getInt8PtrTy(M->getContext()); // prototype free as "void free(void*)" - Function *FreeFunc = cast(M->getOrInsertFunction("free", VoidTy, - IntPtrTy, NULL)); + Value *FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy, NULL); CallInst* Result = NULL; Value *PtrCast = Source; if (InsertBefore) { @@ -582,7 +581,8 @@ static Instruction* createFree(Value* Source, Instruction *InsertBefore, Result = CallInst::Create(FreeFunc, PtrCast, ""); } Result->setTailCall(); - Result->setCallingConv(FreeFunc->getCallingConv()); + if (Function *F = dyn_cast(FreeFunc)) + Result->setCallingConv(F->getCallingConv()); return Result; }