diff options
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/Module.cpp | 41 |
2 files changed, 43 insertions, 2 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index d61684b5278..86e4409da02 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -466,7 +466,7 @@ static Instruction *createMalloc(Instruction *InsertBefore, Value *MallocFunc = MallocF; if (!MallocFunc) // prototype malloc as "void *malloc(size_t)" - MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy); + MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy, nullptr); PointerType *AllocPtrType = PointerType::getUnqual(AllocTy); CallInst *MCall = nullptr; Instruction *Result = nullptr; @@ -560,7 +560,7 @@ static Instruction *createFree(Value *Source, Type *VoidTy = Type::getVoidTy(M->getContext()); Type *IntPtrTy = Type::getInt8PtrTy(M->getContext()); // prototype free as "void free(void*)" - Value *FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy); + Value *FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy, nullptr); CallInst *Result = nullptr; Value *PtrCast = Source; if (InsertBefore) { diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index fec9df19368..c3bfee5cb68 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -147,6 +147,47 @@ Constant *Module::getOrInsertFunction(StringRef Name, return getOrInsertFunction(Name, Ty, AttributeList()); } +// getOrInsertFunction - Look up the specified function in the module symbol +// table. If it does not exist, add a prototype for the function and return it. +// This version of the method takes a null terminated list of function +// arguments, which makes it easier for clients to use. +// +Constant *Module::getOrInsertFunction(StringRef Name, + AttributeList AttributeList, Type *RetTy, + ...) { + va_list Args; + va_start(Args, RetTy); + + // Build the list of argument types... + std::vector<Type*> ArgTys; + while (Type *ArgTy = va_arg(Args, Type*)) + ArgTys.push_back(ArgTy); + + va_end(Args); + + // Build the function type and chain to the other getOrInsertFunction... + return getOrInsertFunction(Name, + FunctionType::get(RetTy, ArgTys, false), + AttributeList); +} + +Constant *Module::getOrInsertFunction(StringRef Name, + Type *RetTy, ...) { + va_list Args; + va_start(Args, RetTy); + + // Build the list of argument types... + std::vector<Type*> ArgTys; + while (Type *ArgTy = va_arg(Args, Type*)) + ArgTys.push_back(ArgTy); + + va_end(Args); + + // Build the function type and chain to the other getOrInsertFunction... + return getOrInsertFunction(Name, FunctionType::get(RetTy, ArgTys, false), + AttributeList()); +} + // getFunction - Look up the specified function in the module symbol table. // If it does not exist, return null. // |