aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorVictor Hernandez <vhernandez@apple.com>2009-11-10 19:53:28 +0000
committerVictor Hernandez <vhernandez@apple.com>2009-11-10 19:53:28 +0000
commit053fd3c45f72e248641e349197db27d717c2be6e (patch)
treeff30b9129ea449257493aa153363b40a4833adea /lib/VMCore
parent4137d7cdf726c8d94ef376603d909b69037a9e91 (diff)
downloadexternal_llvm-053fd3c45f72e248641e349197db27d717c2be6e.zip
external_llvm-053fd3c45f72e248641e349197db27d717c2be6e.tar.gz
external_llvm-053fd3c45f72e248641e349197db27d717c2be6e.tar.bz2
make this handle redefinition of malloc function with different prototype correctly
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86712 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Instructions.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 9817e4c..b03ee93 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -494,22 +494,21 @@ static Instruction *createMalloc(Instruction *InsertBefore,
BasicBlock* BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
Module* M = BB->getParent()->getParent();
const Type *BPTy = Type::getInt8PtrTy(BB->getContext());
- if (!MallocF)
+ Value *MallocFunc = MallocF;
+ if (!MallocFunc)
// prototype malloc as "void *malloc(size_t)"
- MallocF = cast<Function>(M->getOrInsertFunction("malloc", BPTy,
- IntPtrTy, NULL));
- if (!MallocF->doesNotAlias(0)) MallocF->setDoesNotAlias(0);
+ MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy, NULL);
const PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
CallInst *MCall = NULL;
Instruction *Result = NULL;
if (InsertBefore) {
- MCall = CallInst::Create(MallocF, AllocSize, "malloccall", InsertBefore);
+ MCall = CallInst::Create(MallocFunc, AllocSize, "malloccall", InsertBefore);
Result = MCall;
if (Result->getType() != AllocPtrType)
// Create a cast instruction to convert to the right type...
Result = new BitCastInst(MCall, AllocPtrType, Name, InsertBefore);
} else {
- MCall = CallInst::Create(MallocF, AllocSize, "malloccall");
+ MCall = CallInst::Create(MallocFunc, AllocSize, "malloccall");
Result = MCall;
if (Result->getType() != AllocPtrType) {
InsertAtEnd->getInstList().push_back(MCall);
@@ -518,7 +517,10 @@ static Instruction *createMalloc(Instruction *InsertBefore,
}
}
MCall->setTailCall();
- MCall->setCallingConv(MallocF->getCallingConv());
+ if (Function *F = dyn_cast<Function>(MallocFunc)) {
+ MCall->setCallingConv(F->getCallingConv());
+ if (!F->doesNotAlias(0)) F->setDoesNotAlias(0);
+ }
assert(MCall->getType() != Type::getVoidTy(BB->getContext()) &&
"Malloc has void return type");