mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-10-25 10:27:04 +00:00
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
This commit is contained in:
@@ -494,22 +494,21 @@ static Instruction *createMalloc(Instruction *InsertBefore,
|
|||||||
BasicBlock* BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
|
BasicBlock* BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
|
||||||
Module* M = BB->getParent()->getParent();
|
Module* M = BB->getParent()->getParent();
|
||||||
const Type *BPTy = Type::getInt8PtrTy(BB->getContext());
|
const Type *BPTy = Type::getInt8PtrTy(BB->getContext());
|
||||||
if (!MallocF)
|
Value *MallocFunc = MallocF;
|
||||||
|
if (!MallocFunc)
|
||||||
// prototype malloc as "void *malloc(size_t)"
|
// prototype malloc as "void *malloc(size_t)"
|
||||||
MallocF = cast<Function>(M->getOrInsertFunction("malloc", BPTy,
|
MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy, NULL);
|
||||||
IntPtrTy, NULL));
|
|
||||||
if (!MallocF->doesNotAlias(0)) MallocF->setDoesNotAlias(0);
|
|
||||||
const PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
|
const PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
|
||||||
CallInst *MCall = NULL;
|
CallInst *MCall = NULL;
|
||||||
Instruction *Result = NULL;
|
Instruction *Result = NULL;
|
||||||
if (InsertBefore) {
|
if (InsertBefore) {
|
||||||
MCall = CallInst::Create(MallocF, AllocSize, "malloccall", InsertBefore);
|
MCall = CallInst::Create(MallocFunc, AllocSize, "malloccall", InsertBefore);
|
||||||
Result = MCall;
|
Result = MCall;
|
||||||
if (Result->getType() != AllocPtrType)
|
if (Result->getType() != AllocPtrType)
|
||||||
// Create a cast instruction to convert to the right type...
|
// Create a cast instruction to convert to the right type...
|
||||||
Result = new BitCastInst(MCall, AllocPtrType, Name, InsertBefore);
|
Result = new BitCastInst(MCall, AllocPtrType, Name, InsertBefore);
|
||||||
} else {
|
} else {
|
||||||
MCall = CallInst::Create(MallocF, AllocSize, "malloccall");
|
MCall = CallInst::Create(MallocFunc, AllocSize, "malloccall");
|
||||||
Result = MCall;
|
Result = MCall;
|
||||||
if (Result->getType() != AllocPtrType) {
|
if (Result->getType() != AllocPtrType) {
|
||||||
InsertAtEnd->getInstList().push_back(MCall);
|
InsertAtEnd->getInstList().push_back(MCall);
|
||||||
@@ -518,7 +517,10 @@ static Instruction *createMalloc(Instruction *InsertBefore,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
MCall->setTailCall();
|
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()) &&
|
assert(MCall->getType() != Type::getVoidTy(BB->getContext()) &&
|
||||||
"Malloc has void return type");
|
"Malloc has void return type");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user