make this handle redefinition of malloc with different prototype correctly.
authorChris Lattner <sabre@nondot.org>
Mon, 9 Nov 2009 07:12:01 +0000 (07:12 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 9 Nov 2009 07:12:01 +0000 (07:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86525 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Instructions.cpp

index f343bd18daa136fe8401b36137e94309f92b96df..9817e4c78a82fbb7dc26099c50d03f196acc6587 100644 (file)
@@ -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<Function>(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<Function>(FreeFunc))
+    Result->setCallingConv(F->getCallingConv());
 
   return Result;
 }