aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Core.cpp8
-rw-r--r--lib/VMCore/Instructions.cpp20
2 files changed, 18 insertions, 10 deletions
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index 1dbf5c4..248127d 100644
--- a/lib/VMCore/Core.cpp
+++ b/lib/VMCore/Core.cpp
@@ -1636,12 +1636,16 @@ LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
const char *Name) {
- return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), 0, Name));
+ const Type* IntPtrT = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
+ return wrap(CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(), IntPtrT,
+ unwrap(Ty), 0, 0, Twine(Name)));
}
LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
LLVMValueRef Val, const char *Name) {
- return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), unwrap(Val), Name));
+ const Type* IntPtrT = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
+ return wrap(CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(), IntPtrT,
+ unwrap(Ty), unwrap(Val), 0, Twine(Name)));
}
LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index b7acce7..611bf16 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -462,7 +462,8 @@ static Value *checkArraySize(Value *Amt, const Type *IntPtrTy) {
static Value *createMalloc(Instruction *InsertBefore, BasicBlock *InsertAtEnd,
const Type *IntPtrTy, const Type *AllocTy,
- Value *ArraySize, const Twine &NameStr) {
+ Value *ArraySize, Function* MallocF,
+ const Twine &NameStr) {
assert(((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) &&
"createMalloc needs either InsertBefore or InsertAtEnd");
@@ -499,10 +500,11 @@ static Value *createMalloc(Instruction *InsertBefore, BasicBlock *InsertAtEnd,
BasicBlock* BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
Module* M = BB->getParent()->getParent();
const Type *BPTy = PointerType::getUnqual(Type::getInt8Ty(BB->getContext()));
- // prototype malloc as "void *malloc(size_t)"
- Constant *MallocF = M->getOrInsertFunction("malloc", BPTy, IntPtrTy, NULL);
- if (!cast<Function>(MallocF)->doesNotAlias(0))
- cast<Function>(MallocF)->setDoesNotAlias(0);
+ if (!MallocF)
+ // prototype malloc as "void *malloc(size_t)"
+ MallocF = cast<Function>(M->getOrInsertFunction("malloc", BPTy,
+ IntPtrTy, NULL));
+ if (!MallocF->doesNotAlias(0)) MallocF->setDoesNotAlias(0);
const PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
CallInst *MCall = NULL;
Value *MCast = NULL;
@@ -531,7 +533,8 @@ static Value *createMalloc(Instruction *InsertBefore, BasicBlock *InsertAtEnd,
Value *CallInst::CreateMalloc(Instruction *InsertBefore, const Type *IntPtrTy,
const Type *AllocTy, Value *ArraySize,
const Twine &Name) {
- return createMalloc(InsertBefore, NULL, IntPtrTy, AllocTy, ArraySize, Name);
+ return createMalloc(InsertBefore, NULL, IntPtrTy, AllocTy,
+ ArraySize, NULL, Name);
}
/// CreateMalloc - Generate the IR for a call to malloc:
@@ -544,8 +547,9 @@ Value *CallInst::CreateMalloc(Instruction *InsertBefore, const Type *IntPtrTy,
/// responsibility of the caller.
Value *CallInst::CreateMalloc(BasicBlock *InsertAtEnd, const Type *IntPtrTy,
const Type *AllocTy, Value *ArraySize,
- const Twine &Name) {
- return createMalloc(NULL, InsertAtEnd, IntPtrTy, AllocTy, ArraySize, Name);
+ Function* MallocF, const Twine &Name) {
+ return createMalloc(NULL, InsertAtEnd, IntPtrTy, AllocTy,
+ ArraySize, MallocF, Name);
}
//===----------------------------------------------------------------------===//