Module::getOrInsertFunction is using C-style vararg instead of variadic templates.

From a user prospective, it forces the use of an annoying nullptr to mark the end of the vararg, and there's not type checking on the arguments.
The variadic template is an obvious solution to both issues.

Differential Revision: https://reviews.llvm.org/D31070

llvm-svn: 299949
This commit is contained in:
Serge Guelton 2017-04-11 15:01:18 +00:00
parent de3b9a2ecc
commit 59a2d7b909
30 changed files with 171 additions and 200 deletions

View File

@ -74,18 +74,18 @@ void BrainF::header(LLVMContext& C) {
//declare i32 @getchar() //declare i32 @getchar()
getchar_func = cast<Function>(module-> getchar_func = cast<Function>(module->
getOrInsertFunction("getchar", IntegerType::getInt32Ty(C), NULL)); getOrInsertFunction("getchar", IntegerType::getInt32Ty(C)));
//declare i32 @putchar(i32) //declare i32 @putchar(i32)
putchar_func = cast<Function>(module-> putchar_func = cast<Function>(module->
getOrInsertFunction("putchar", IntegerType::getInt32Ty(C), getOrInsertFunction("putchar", IntegerType::getInt32Ty(C),
IntegerType::getInt32Ty(C), NULL)); IntegerType::getInt32Ty(C)));
//Function header //Function header
//define void @brainf() //define void @brainf()
brainf_func = cast<Function>(module-> brainf_func = cast<Function>(module->
getOrInsertFunction("brainf", Type::getVoidTy(C), NULL)); getOrInsertFunction("brainf", Type::getVoidTy(C)));
builder = new IRBuilder<>(BasicBlock::Create(C, label, brainf_func)); builder = new IRBuilder<>(BasicBlock::Create(C, label, brainf_func));
@ -156,7 +156,7 @@ void BrainF::header(LLVMContext& C) {
//declare i32 @puts(i8 *) //declare i32 @puts(i8 *)
Function *puts_func = cast<Function>(module-> Function *puts_func = cast<Function>(module->
getOrInsertFunction("puts", IntegerType::getInt32Ty(C), getOrInsertFunction("puts", IntegerType::getInt32Ty(C),
PointerType::getUnqual(IntegerType::getInt8Ty(C)), NULL)); PointerType::getUnqual(IntegerType::getInt8Ty(C))));
//brainf.aberror: //brainf.aberror:
aberrorbb = BasicBlock::Create(C, label, brainf_func); aberrorbb = BasicBlock::Create(C, label, brainf_func);

View File

@ -77,7 +77,7 @@ void addMainFunction(Module *mod) {
getOrInsertFunction("main", IntegerType::getInt32Ty(mod->getContext()), getOrInsertFunction("main", IntegerType::getInt32Ty(mod->getContext()),
IntegerType::getInt32Ty(mod->getContext()), IntegerType::getInt32Ty(mod->getContext()),
PointerType::getUnqual(PointerType::getUnqual( PointerType::getUnqual(PointerType::getUnqual(
IntegerType::getInt8Ty(mod->getContext()))), NULL)); IntegerType::getInt8Ty(mod->getContext())))));
{ {
Function::arg_iterator args = main_func->arg_begin(); Function::arg_iterator args = main_func->arg_begin();
Value *arg_0 = &*args++; Value *arg_0 = &*args++;

View File

@ -54,8 +54,7 @@ static Function *CreateFibFunction(Module *M, LLVMContext &Context) {
// to return an int and take an int parameter. // to return an int and take an int parameter.
Function *FibF = Function *FibF =
cast<Function>(M->getOrInsertFunction("fib", Type::getInt32Ty(Context), cast<Function>(M->getOrInsertFunction("fib", Type::getInt32Ty(Context),
Type::getInt32Ty(Context), Type::getInt32Ty(Context)));
nullptr));
// Add a basic block to the function. // Add a basic block to the function.
BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", FibF); BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", FibF);

View File

@ -69,11 +69,9 @@ int main() {
// Create the add1 function entry and insert this entry into module M. The // Create the add1 function entry and insert this entry into module M. The
// function will have a return type of "int" and take an argument of "int". // function will have a return type of "int" and take an argument of "int".
// The '0' terminates the list of argument types.
Function *Add1F = Function *Add1F =
cast<Function>(M->getOrInsertFunction("add1", Type::getInt32Ty(Context), cast<Function>(M->getOrInsertFunction("add1", Type::getInt32Ty(Context),
Type::getInt32Ty(Context), Type::getInt32Ty(Context)));
nullptr));
// Add a basic block to the function. As before, it automatically inserts // Add a basic block to the function. As before, it automatically inserts
// because of the last argument. // because of the last argument.
@ -102,8 +100,7 @@ int main() {
// Now we're going to create function `foo', which returns an int and takes no // Now we're going to create function `foo', which returns an int and takes no
// arguments. // arguments.
Function *FooF = Function *FooF =
cast<Function>(M->getOrInsertFunction("foo", Type::getInt32Ty(Context), cast<Function>(M->getOrInsertFunction("foo", Type::getInt32Ty(Context)));
nullptr));
// Add a basic block to the FooF function. // Add a basic block to the FooF function.
BB = BasicBlock::Create(Context, "EntryBlock", FooF); BB = BasicBlock::Create(Context, "EntryBlock", FooF);

View File

@ -54,8 +54,7 @@ static Function* createAdd1(Module *M) {
Function *Add1F = Function *Add1F =
cast<Function>(M->getOrInsertFunction("add1", cast<Function>(M->getOrInsertFunction("add1",
Type::getInt32Ty(M->getContext()), Type::getInt32Ty(M->getContext()),
Type::getInt32Ty(M->getContext()), Type::getInt32Ty(M->getContext())));
nullptr));
// Add a basic block to the function. As before, it automatically inserts // Add a basic block to the function. As before, it automatically inserts
// because of the last argument. // because of the last argument.
@ -85,8 +84,7 @@ static Function *CreateFibFunction(Module *M) {
Function *FibF = Function *FibF =
cast<Function>(M->getOrInsertFunction("fib", cast<Function>(M->getOrInsertFunction("fib",
Type::getInt32Ty(M->getContext()), Type::getInt32Ty(M->getContext()),
Type::getInt32Ty(M->getContext()), Type::getInt32Ty(M->getContext())));
nullptr));
// Add a basic block to the function. // Add a basic block to the function.
BasicBlock *BB = BasicBlock::Create(M->getContext(), "EntryBlock", FibF); BasicBlock *BB = BasicBlock::Create(M->getContext(), "EntryBlock", FibF);

View File

@ -321,12 +321,22 @@ public:
/// or a ConstantExpr BitCast of that type if the named function has a /// or a ConstantExpr BitCast of that type if the named function has a
/// different type. This version of the method takes a null terminated list of /// different type. This version of the method takes a null terminated list of
/// function arguments, which makes it easier for clients to use. /// function arguments, which makes it easier for clients to use.
Constant *getOrInsertFunction(StringRef Name, AttributeList AttributeList, template<typename... ArgsTy>
Type *RetTy, ...) LLVM_END_WITH_NULL; Constant *getOrInsertFunction(StringRef Name,
AttributeList AttributeList,
Type *RetTy, ArgsTy... Args)
{
SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
return getOrInsertFunction(Name,
FunctionType::get(RetTy, ArgTys, false),
AttributeList);
}
/// Same as above, but without the attributes. /// Same as above, but without the attributes.
Constant *getOrInsertFunction(StringRef Name, Type *RetTy, ...) template<typename... ArgsTy>
LLVM_END_WITH_NULL; Constant *getOrInsertFunction(StringRef Name, Type *RetTy, ArgsTy... Args) {
return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
}
/// Look up the specified function in the module symbol table. If it does not /// Look up the specified function in the module symbol table. If it does not
/// exist, return null. /// exist, return null.

View File

@ -41,7 +41,7 @@ namespace {
Type *VoidTy = Type::getVoidTy(F.getContext()); Type *VoidTy = Type::getVoidTy(F.getContext());
Constant *CountingFn = Constant *CountingFn =
F.getParent()->getOrInsertFunction(CountingFunctionName, F.getParent()->getOrInsertFunction(CountingFunctionName,
VoidTy, nullptr); VoidTy);
CallInst::Create(CountingFn, "", &*F.begin()->getFirstInsertionPt()); CallInst::Create(CountingFn, "", &*F.begin()->getFirstInsertionPt());
return true; return true;
} }

View File

@ -115,21 +115,21 @@ void IntrinsicLowering::AddPrototypes(Module &M) {
Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context),
Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context),
Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context),
DL.getIntPtrType(Context), nullptr); DL.getIntPtrType(Context));
break; break;
case Intrinsic::memmove: case Intrinsic::memmove:
M.getOrInsertFunction("memmove", M.getOrInsertFunction("memmove",
Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context),
Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context),
Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context),
DL.getIntPtrType(Context), nullptr); DL.getIntPtrType(Context));
break; break;
case Intrinsic::memset: case Intrinsic::memset:
M.getOrInsertFunction("memset", M.getOrInsertFunction("memset",
Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context),
Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context),
Type::getInt32Ty(M.getContext()), Type::getInt32Ty(M.getContext()),
DL.getIntPtrType(Context), nullptr); DL.getIntPtrType(Context));
break; break;
case Intrinsic::sqrt: case Intrinsic::sqrt:
EnsureFPIntrinsicsExist(M, F, "sqrtf", "sqrt", "sqrtl"); EnsureFPIntrinsicsExist(M, F, "sqrtf", "sqrt", "sqrtl");

View File

@ -1098,7 +1098,7 @@ MachineOutliner::createOutlinedFunction(Module &M, const OutlinedFunction &OF,
// Create the function using an IR-level function. // Create the function using an IR-level function.
LLVMContext &C = M.getContext(); LLVMContext &C = M.getContext();
Function *F = dyn_cast<Function>( Function *F = dyn_cast<Function>(
M.getOrInsertFunction(NameStream.str(), Type::getVoidTy(C), nullptr)); M.getOrInsertFunction(NameStream.str(), Type::getVoidTy(C)));
assert(F && "Function was null!"); assert(F && "Function was null!");
// NOTE: If this is linkonceodr, then we can take advantage of linker deduping // NOTE: If this is linkonceodr, then we can take advantage of linker deduping

View File

@ -451,7 +451,7 @@ void SafeStack::checkStackGuard(IRBuilder<> &IRB, Function &F, ReturnInst &RI,
IRBuilder<> IRBFail(CheckTerm); IRBuilder<> IRBFail(CheckTerm);
// FIXME: respect -fsanitize-trap / -ftrap-function here? // FIXME: respect -fsanitize-trap / -ftrap-function here?
Constant *StackChkFail = F.getParent()->getOrInsertFunction( Constant *StackChkFail = F.getParent()->getOrInsertFunction(
"__stack_chk_fail", IRB.getVoidTy(), nullptr); "__stack_chk_fail", IRB.getVoidTy());
IRBFail.CreateCall(StackChkFail, {}); IRBFail.CreateCall(StackChkFail, {});
} }

View File

@ -482,10 +482,10 @@ bool SjLjEHPrepare::runOnFunction(Function &F) {
Module &M = *F.getParent(); Module &M = *F.getParent();
RegisterFn = M.getOrInsertFunction( RegisterFn = M.getOrInsertFunction(
"_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()), "_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()),
PointerType::getUnqual(FunctionContextTy), nullptr); PointerType::getUnqual(FunctionContextTy));
UnregisterFn = M.getOrInsertFunction( UnregisterFn = M.getOrInsertFunction(
"_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()), "_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()),
PointerType::getUnqual(FunctionContextTy), nullptr); PointerType::getUnqual(FunctionContextTy));
FrameAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::frameaddress); FrameAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::frameaddress);
StackAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::stacksave); StackAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::stacksave);
StackRestoreFn = Intrinsic::getDeclaration(&M, Intrinsic::stackrestore); StackRestoreFn = Intrinsic::getDeclaration(&M, Intrinsic::stackrestore);

View File

@ -484,13 +484,13 @@ BasicBlock *StackProtector::CreateFailBB() {
Constant *StackChkFail = Constant *StackChkFail =
M->getOrInsertFunction("__stack_smash_handler", M->getOrInsertFunction("__stack_smash_handler",
Type::getVoidTy(Context), Type::getVoidTy(Context),
Type::getInt8PtrTy(Context), nullptr); Type::getInt8PtrTy(Context));
B.CreateCall(StackChkFail, B.CreateGlobalStringPtr(F->getName(), "SSH")); B.CreateCall(StackChkFail, B.CreateGlobalStringPtr(F->getName(), "SSH"));
} else { } else {
Constant *StackChkFail = Constant *StackChkFail =
M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context), M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context));
nullptr);
B.CreateCall(StackChkFail, {}); B.CreateCall(StackChkFail, {});
} }
B.CreateUnreachable(); B.CreateUnreachable();

View File

@ -1818,7 +1818,7 @@ Value *TargetLoweringBase::getSafeStackPointerLocation(IRBuilder<> &IRB) const {
Module *M = IRB.GetInsertBlock()->getParent()->getParent(); Module *M = IRB.GetInsertBlock()->getParent()->getParent();
Type *StackPtrTy = Type::getInt8PtrTy(M->getContext()); Type *StackPtrTy = Type::getInt8PtrTy(M->getContext());
Value *Fn = M->getOrInsertFunction("__safestack_pointer_address", Value *Fn = M->getOrInsertFunction("__safestack_pointer_address",
StackPtrTy->getPointerTo(0), nullptr); StackPtrTy->getPointerTo(0));
return IRB.CreateCall(Fn); return IRB.CreateCall(Fn);
} }

View File

@ -466,7 +466,7 @@ static Instruction *createMalloc(Instruction *InsertBefore,
Value *MallocFunc = MallocF; Value *MallocFunc = MallocF;
if (!MallocFunc) if (!MallocFunc)
// prototype malloc as "void *malloc(size_t)" // prototype malloc as "void *malloc(size_t)"
MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy, nullptr); MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy);
PointerType *AllocPtrType = PointerType::getUnqual(AllocTy); PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
CallInst *MCall = nullptr; CallInst *MCall = nullptr;
Instruction *Result = nullptr; Instruction *Result = nullptr;
@ -560,7 +560,7 @@ static Instruction *createFree(Value *Source,
Type *VoidTy = Type::getVoidTy(M->getContext()); Type *VoidTy = Type::getVoidTy(M->getContext());
Type *IntPtrTy = Type::getInt8PtrTy(M->getContext()); Type *IntPtrTy = Type::getInt8PtrTy(M->getContext());
// prototype free as "void free(void*)" // prototype free as "void free(void*)"
Value *FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy, nullptr); Value *FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy);
CallInst *Result = nullptr; CallInst *Result = nullptr;
Value *PtrCast = Source; Value *PtrCast = Source;
if (InsertBefore) { if (InsertBefore) {

View File

@ -147,47 +147,6 @@ Constant *Module::getOrInsertFunction(StringRef Name,
return getOrInsertFunction(Name, Ty, AttributeList()); 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. // getFunction - Look up the specified function in the module symbol table.
// If it does not exist, return null. // If it does not exist, return null.
// //

View File

@ -2146,8 +2146,7 @@ CleanupAndExit:
Type *VoidTy = Type::getVoidTy(Ctx); Type *VoidTy = Type::getVoidTy(Ctx);
Module *M = Func->getParent(); Module *M = Func->getParent();
Constant *CF = M->getOrInsertFunction(HexagonVolatileMemcpyName, VoidTy, Constant *CF = M->getOrInsertFunction(HexagonVolatileMemcpyName, VoidTy,
Int32PtrTy, Int32PtrTy, Int32Ty, Int32PtrTy, Int32PtrTy, Int32Ty);
nullptr);
Function *Fn = cast<Function>(CF); Function *Fn = cast<Function>(CF);
Fn->setLinkage(Function::ExternalLinkage); Fn->setLinkage(Function::ExternalLinkage);

View File

@ -420,7 +420,7 @@ static bool fixupFPReturnAndCall(Function &F, Module *M,
Attribute::ReadNone); Attribute::ReadNone);
A = A.addAttribute(C, AttributeList::FunctionIndex, A = A.addAttribute(C, AttributeList::FunctionIndex,
Attribute::NoInline); Attribute::NoInline);
Value *F = (M->getOrInsertFunction(Name, A, MyVoid, T, nullptr)); Value *F = (M->getOrInsertFunction(Name, A, MyVoid, T));
CallInst::Create(F, Params, "", &I); CallInst::Create(F, Params, "", &I);
} else if (const CallInst *CI = dyn_cast<CallInst>(&I)) { } else if (const CallInst *CI = dyn_cast<CallInst>(&I)) {
FunctionType *FT = CI->getFunctionType(); FunctionType *FT = CI->getFunctionType();

View File

@ -2101,7 +2101,7 @@ void X86TargetLowering::insertSSPDeclarations(Module &M) const {
auto *SecurityCheckCookie = cast<Function>( auto *SecurityCheckCookie = cast<Function>(
M.getOrInsertFunction("__security_check_cookie", M.getOrInsertFunction("__security_check_cookie",
Type::getVoidTy(M.getContext()), Type::getVoidTy(M.getContext()),
Type::getInt8PtrTy(M.getContext()), nullptr)); Type::getInt8PtrTy(M.getContext())));
SecurityCheckCookie->setCallingConv(CallingConv::X86_FastCall); SecurityCheckCookie->setCallingConv(CallingConv::X86_FastCall);
SecurityCheckCookie->addAttribute(1, Attribute::AttrKind::InReg); SecurityCheckCookie->addAttribute(1, Attribute::AttrKind::InReg);
return; return;

View File

@ -98,7 +98,7 @@ void CrossDSOCFI::buildCFICheck(Module &M) {
LLVMContext &Ctx = M.getContext(); LLVMContext &Ctx = M.getContext();
Constant *C = M.getOrInsertFunction( Constant *C = M.getOrInsertFunction(
"__cfi_check", Type::getVoidTy(Ctx), Type::getInt64Ty(Ctx), "__cfi_check", Type::getVoidTy(Ctx), Type::getInt64Ty(Ctx),
Type::getInt8PtrTy(Ctx), Type::getInt8PtrTy(Ctx), nullptr); Type::getInt8PtrTy(Ctx), Type::getInt8PtrTy(Ctx));
Function *F = dyn_cast<Function>(C); Function *F = dyn_cast<Function>(C);
// Take over the existing function. The frontend emits a weak stub so that the // Take over the existing function. The frontend emits a weak stub so that the
// linker knows about the symbol; this pass replaces the function body. // linker knows about the symbol; this pass replaces the function body.
@ -120,7 +120,7 @@ void CrossDSOCFI::buildCFICheck(Module &M) {
IRBuilder<> IRBFail(TrapBB); IRBuilder<> IRBFail(TrapBB);
Constant *CFICheckFailFn = M.getOrInsertFunction( Constant *CFICheckFailFn = M.getOrInsertFunction(
"__cfi_check_fail", Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx), "__cfi_check_fail", Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx),
Type::getInt8PtrTy(Ctx), nullptr); Type::getInt8PtrTy(Ctx));
IRBFail.CreateCall(CFICheckFailFn, {&CFICheckFailData, &Addr}); IRBFail.CreateCall(CFICheckFailFn, {&CFICheckFailData, &Addr});
IRBFail.CreateBr(ExitBB); IRBFail.CreateBr(ExitBB);

View File

@ -1221,7 +1221,7 @@ void DevirtModule::importResolution(VTableSlot Slot, VTableSlotInfo &SlotInfo) {
// The type of the function in the declaration is irrelevant because every // The type of the function in the declaration is irrelevant because every
// call site will cast it to the correct type. // call site will cast it to the correct type.
auto *SingleImpl = M.getOrInsertFunction( auto *SingleImpl = M.getOrInsertFunction(
Res.SingleImplName, Type::getVoidTy(M.getContext()), nullptr); Res.SingleImplName, Type::getVoidTy(M.getContext()));
// This is the import phase so we should not be exporting anything. // This is the import phase so we should not be exporting anything.
bool IsExported = false; bool IsExported = false;

View File

@ -1568,31 +1568,31 @@ void AddressSanitizerModule::initializeCallbacks(Module &M) {
// Declare our poisoning and unpoisoning functions. // Declare our poisoning and unpoisoning functions.
AsanPoisonGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction( AsanPoisonGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanPoisonGlobalsName, IRB.getVoidTy(), IntptrTy, nullptr)); kAsanPoisonGlobalsName, IRB.getVoidTy(), IntptrTy));
AsanPoisonGlobals->setLinkage(Function::ExternalLinkage); AsanPoisonGlobals->setLinkage(Function::ExternalLinkage);
AsanUnpoisonGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction( AsanUnpoisonGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanUnpoisonGlobalsName, IRB.getVoidTy(), nullptr)); kAsanUnpoisonGlobalsName, IRB.getVoidTy()));
AsanUnpoisonGlobals->setLinkage(Function::ExternalLinkage); AsanUnpoisonGlobals->setLinkage(Function::ExternalLinkage);
// Declare functions that register/unregister globals. // Declare functions that register/unregister globals.
AsanRegisterGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction( AsanRegisterGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanRegisterGlobalsName, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr)); kAsanRegisterGlobalsName, IRB.getVoidTy(), IntptrTy, IntptrTy));
AsanRegisterGlobals->setLinkage(Function::ExternalLinkage); AsanRegisterGlobals->setLinkage(Function::ExternalLinkage);
AsanUnregisterGlobals = checkSanitizerInterfaceFunction( AsanUnregisterGlobals = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(kAsanUnregisterGlobalsName, IRB.getVoidTy(), M.getOrInsertFunction(kAsanUnregisterGlobalsName, IRB.getVoidTy(),
IntptrTy, IntptrTy, nullptr)); IntptrTy, IntptrTy));
AsanUnregisterGlobals->setLinkage(Function::ExternalLinkage); AsanUnregisterGlobals->setLinkage(Function::ExternalLinkage);
// Declare the functions that find globals in a shared object and then invoke // Declare the functions that find globals in a shared object and then invoke
// the (un)register function on them. // the (un)register function on them.
AsanRegisterImageGlobals = AsanRegisterImageGlobals =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanRegisterImageGlobalsName, IRB.getVoidTy(), IntptrTy, nullptr)); kAsanRegisterImageGlobalsName, IRB.getVoidTy(), IntptrTy));
AsanRegisterImageGlobals->setLinkage(Function::ExternalLinkage); AsanRegisterImageGlobals->setLinkage(Function::ExternalLinkage);
AsanUnregisterImageGlobals = AsanUnregisterImageGlobals =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanUnregisterImageGlobalsName, IRB.getVoidTy(), IntptrTy, nullptr)); kAsanUnregisterImageGlobalsName, IRB.getVoidTy(), IntptrTy));
AsanUnregisterImageGlobals->setLinkage(Function::ExternalLinkage); AsanUnregisterImageGlobals->setLinkage(Function::ExternalLinkage);
} }
@ -1963,49 +1963,60 @@ void AddressSanitizer::initializeCallbacks(Module &M) {
const std::string ExpStr = Exp ? "exp_" : ""; const std::string ExpStr = Exp ? "exp_" : "";
const std::string SuffixStr = CompileKernel ? "N" : "_n"; const std::string SuffixStr = CompileKernel ? "N" : "_n";
const std::string EndingStr = Recover ? "_noabort" : ""; const std::string EndingStr = Recover ? "_noabort" : "";
Type *ExpType = Exp ? Type::getInt32Ty(*C) : nullptr;
AsanErrorCallbackSized[AccessIsWrite][Exp] = SmallVector<Type *, 3> Args2 = {IntptrTy, IntptrTy};
checkSanitizerInterfaceFunction(M.getOrInsertFunction( SmallVector<Type *, 2> Args1{1, IntptrTy};
kAsanReportErrorTemplate + ExpStr + TypeStr + SuffixStr + EndingStr, if (Exp) {
IRB.getVoidTy(), IntptrTy, IntptrTy, ExpType, nullptr)); Type *ExpType = Type::getInt32Ty(*C);
AsanMemoryAccessCallbackSized[AccessIsWrite][Exp] = Args2.push_back(ExpType);
checkSanitizerInterfaceFunction(M.getOrInsertFunction( Args1.push_back(ExpType);
ClMemoryAccessCallbackPrefix + ExpStr + TypeStr + "N" + EndingStr,
IRB.getVoidTy(), IntptrTy, IntptrTy, ExpType, nullptr));
for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes;
AccessSizeIndex++) {
const std::string Suffix = TypeStr + itostr(1ULL << AccessSizeIndex);
AsanErrorCallback[AccessIsWrite][Exp][AccessSizeIndex] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanReportErrorTemplate + ExpStr + Suffix + EndingStr,
IRB.getVoidTy(), IntptrTy, ExpType, nullptr));
AsanMemoryAccessCallback[AccessIsWrite][Exp][AccessSizeIndex] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction(
ClMemoryAccessCallbackPrefix + ExpStr + Suffix + EndingStr,
IRB.getVoidTy(), IntptrTy, ExpType, nullptr));
} }
} AsanErrorCallbackSized[AccessIsWrite][Exp] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanReportErrorTemplate + ExpStr + TypeStr + SuffixStr +
EndingStr,
FunctionType::get(IRB.getVoidTy(), Args2, false)));
AsanMemoryAccessCallbackSized[AccessIsWrite][Exp] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction(
ClMemoryAccessCallbackPrefix + ExpStr + TypeStr + "N" + EndingStr,
FunctionType::get(IRB.getVoidTy(), Args2, false)));
for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes;
AccessSizeIndex++) {
const std::string Suffix = TypeStr + itostr(1ULL << AccessSizeIndex);
AsanErrorCallback[AccessIsWrite][Exp][AccessSizeIndex] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanReportErrorTemplate + ExpStr + Suffix + EndingStr,
FunctionType::get(IRB.getVoidTy(), Args1, false)));
AsanMemoryAccessCallback[AccessIsWrite][Exp][AccessSizeIndex] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction(
ClMemoryAccessCallbackPrefix + ExpStr + Suffix + EndingStr,
FunctionType::get(IRB.getVoidTy(), Args1, false)));
}
}
} }
const std::string MemIntrinCallbackPrefix = const std::string MemIntrinCallbackPrefix =
CompileKernel ? std::string("") : ClMemoryAccessCallbackPrefix; CompileKernel ? std::string("") : ClMemoryAccessCallbackPrefix;
AsanMemmove = checkSanitizerInterfaceFunction(M.getOrInsertFunction( AsanMemmove = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
MemIntrinCallbackPrefix + "memmove", IRB.getInt8PtrTy(), MemIntrinCallbackPrefix + "memmove", IRB.getInt8PtrTy(),
IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy, nullptr)); IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy));
AsanMemcpy = checkSanitizerInterfaceFunction(M.getOrInsertFunction( AsanMemcpy = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
MemIntrinCallbackPrefix + "memcpy", IRB.getInt8PtrTy(), MemIntrinCallbackPrefix + "memcpy", IRB.getInt8PtrTy(),
IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy, nullptr)); IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy));
AsanMemset = checkSanitizerInterfaceFunction(M.getOrInsertFunction( AsanMemset = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
MemIntrinCallbackPrefix + "memset", IRB.getInt8PtrTy(), MemIntrinCallbackPrefix + "memset", IRB.getInt8PtrTy(),
IRB.getInt8PtrTy(), IRB.getInt32Ty(), IntptrTy, nullptr)); IRB.getInt8PtrTy(), IRB.getInt32Ty(), IntptrTy));
AsanHandleNoReturnFunc = checkSanitizerInterfaceFunction( AsanHandleNoReturnFunc = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(kAsanHandleNoReturnName, IRB.getVoidTy(), nullptr)); M.getOrInsertFunction(kAsanHandleNoReturnName, IRB.getVoidTy()));
AsanPtrCmpFunction = checkSanitizerInterfaceFunction(M.getOrInsertFunction( AsanPtrCmpFunction = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanPtrCmp, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr)); kAsanPtrCmp, IRB.getVoidTy(), IntptrTy, IntptrTy));
AsanPtrSubFunction = checkSanitizerInterfaceFunction(M.getOrInsertFunction( AsanPtrSubFunction = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanPtrSub, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr)); kAsanPtrSub, IRB.getVoidTy(), IntptrTy, IntptrTy));
// We insert an empty inline asm after __asan_report* to avoid callback merge. // We insert an empty inline asm after __asan_report* to avoid callback merge.
EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false), EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
StringRef(""), StringRef(""), StringRef(""), StringRef(""),
@ -2242,18 +2253,18 @@ void FunctionStackPoisoner::initializeCallbacks(Module &M) {
std::string Suffix = itostr(i); std::string Suffix = itostr(i);
AsanStackMallocFunc[i] = checkSanitizerInterfaceFunction( AsanStackMallocFunc[i] = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(kAsanStackMallocNameTemplate + Suffix, IntptrTy, M.getOrInsertFunction(kAsanStackMallocNameTemplate + Suffix, IntptrTy,
IntptrTy, nullptr)); IntptrTy));
AsanStackFreeFunc[i] = checkSanitizerInterfaceFunction( AsanStackFreeFunc[i] = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(kAsanStackFreeNameTemplate + Suffix, M.getOrInsertFunction(kAsanStackFreeNameTemplate + Suffix,
IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr)); IRB.getVoidTy(), IntptrTy, IntptrTy));
} }
if (ASan.UseAfterScope) { if (ASan.UseAfterScope) {
AsanPoisonStackMemoryFunc = checkSanitizerInterfaceFunction( AsanPoisonStackMemoryFunc = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(kAsanPoisonStackMemoryName, IRB.getVoidTy(), M.getOrInsertFunction(kAsanPoisonStackMemoryName, IRB.getVoidTy(),
IntptrTy, IntptrTy, nullptr)); IntptrTy, IntptrTy));
AsanUnpoisonStackMemoryFunc = checkSanitizerInterfaceFunction( AsanUnpoisonStackMemoryFunc = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(kAsanUnpoisonStackMemoryName, IRB.getVoidTy(), M.getOrInsertFunction(kAsanUnpoisonStackMemoryName, IRB.getVoidTy(),
IntptrTy, IntptrTy, nullptr)); IntptrTy, IntptrTy));
} }
for (size_t Val : {0x00, 0xf1, 0xf2, 0xf3, 0xf5, 0xf8}) { for (size_t Val : {0x00, 0xf1, 0xf2, 0xf3, 0xf5, 0xf8}) {
@ -2262,14 +2273,14 @@ void FunctionStackPoisoner::initializeCallbacks(Module &M) {
Name << std::setw(2) << std::setfill('0') << std::hex << Val; Name << std::setw(2) << std::setfill('0') << std::hex << Val;
AsanSetShadowFunc[Val] = AsanSetShadowFunc[Val] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
Name.str(), IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr)); Name.str(), IRB.getVoidTy(), IntptrTy, IntptrTy));
} }
AsanAllocaPoisonFunc = checkSanitizerInterfaceFunction(M.getOrInsertFunction( AsanAllocaPoisonFunc = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanAllocaPoison, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr)); kAsanAllocaPoison, IRB.getVoidTy(), IntptrTy, IntptrTy));
AsanAllocasUnpoisonFunc = AsanAllocasUnpoisonFunc =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
kAsanAllocasUnpoison, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr)); kAsanAllocasUnpoison, IRB.getVoidTy(), IntptrTy, IntptrTy));
} }
void FunctionStackPoisoner::copyToShadowInline(ArrayRef<uint8_t> ShadowMask, void FunctionStackPoisoner::copyToShadowInline(ArrayRef<uint8_t> ShadowMask,

View File

@ -267,35 +267,35 @@ void EfficiencySanitizer::initializeCallbacks(Module &M) {
SmallString<32> AlignedLoadName("__esan_aligned_load" + ByteSizeStr); SmallString<32> AlignedLoadName("__esan_aligned_load" + ByteSizeStr);
EsanAlignedLoad[Idx] = EsanAlignedLoad[Idx] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
AlignedLoadName, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr)); AlignedLoadName, IRB.getVoidTy(), IRB.getInt8PtrTy()));
SmallString<32> AlignedStoreName("__esan_aligned_store" + ByteSizeStr); SmallString<32> AlignedStoreName("__esan_aligned_store" + ByteSizeStr);
EsanAlignedStore[Idx] = EsanAlignedStore[Idx] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
AlignedStoreName, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr)); AlignedStoreName, IRB.getVoidTy(), IRB.getInt8PtrTy()));
SmallString<32> UnalignedLoadName("__esan_unaligned_load" + ByteSizeStr); SmallString<32> UnalignedLoadName("__esan_unaligned_load" + ByteSizeStr);
EsanUnalignedLoad[Idx] = EsanUnalignedLoad[Idx] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
UnalignedLoadName, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr)); UnalignedLoadName, IRB.getVoidTy(), IRB.getInt8PtrTy()));
SmallString<32> UnalignedStoreName("__esan_unaligned_store" + ByteSizeStr); SmallString<32> UnalignedStoreName("__esan_unaligned_store" + ByteSizeStr);
EsanUnalignedStore[Idx] = EsanUnalignedStore[Idx] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
UnalignedStoreName, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr)); UnalignedStoreName, IRB.getVoidTy(), IRB.getInt8PtrTy()));
} }
EsanUnalignedLoadN = checkSanitizerInterfaceFunction( EsanUnalignedLoadN = checkSanitizerInterfaceFunction(
M.getOrInsertFunction("__esan_unaligned_loadN", IRB.getVoidTy(), M.getOrInsertFunction("__esan_unaligned_loadN", IRB.getVoidTy(),
IRB.getInt8PtrTy(), IntptrTy, nullptr)); IRB.getInt8PtrTy(), IntptrTy));
EsanUnalignedStoreN = checkSanitizerInterfaceFunction( EsanUnalignedStoreN = checkSanitizerInterfaceFunction(
M.getOrInsertFunction("__esan_unaligned_storeN", IRB.getVoidTy(), M.getOrInsertFunction("__esan_unaligned_storeN", IRB.getVoidTy(),
IRB.getInt8PtrTy(), IntptrTy, nullptr)); IRB.getInt8PtrTy(), IntptrTy));
MemmoveFn = checkSanitizerInterfaceFunction( MemmoveFn = checkSanitizerInterfaceFunction(
M.getOrInsertFunction("memmove", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), M.getOrInsertFunction("memmove", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
IRB.getInt8PtrTy(), IntptrTy, nullptr)); IRB.getInt8PtrTy(), IntptrTy));
MemcpyFn = checkSanitizerInterfaceFunction( MemcpyFn = checkSanitizerInterfaceFunction(
M.getOrInsertFunction("memcpy", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), M.getOrInsertFunction("memcpy", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
IRB.getInt8PtrTy(), IntptrTy, nullptr)); IRB.getInt8PtrTy(), IntptrTy));
MemsetFn = checkSanitizerInterfaceFunction( MemsetFn = checkSanitizerInterfaceFunction(
M.getOrInsertFunction("memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), M.getOrInsertFunction("memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
IRB.getInt32Ty(), IntptrTy, nullptr)); IRB.getInt32Ty(), IntptrTy));
} }
bool EfficiencySanitizer::shouldIgnoreStructType(StructType *StructTy) { bool EfficiencySanitizer::shouldIgnoreStructType(StructType *StructTy) {
@ -533,7 +533,7 @@ void EfficiencySanitizer::createDestructor(Module &M, Constant *ToolInfoArg) {
IRBuilder<> IRB_Dtor(EsanDtorFunction->getEntryBlock().getTerminator()); IRBuilder<> IRB_Dtor(EsanDtorFunction->getEntryBlock().getTerminator());
Function *EsanExit = checkSanitizerInterfaceFunction( Function *EsanExit = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(EsanExitName, IRB_Dtor.getVoidTy(), M.getOrInsertFunction(EsanExitName, IRB_Dtor.getVoidTy(),
Int8PtrTy, nullptr)); Int8PtrTy));
EsanExit->setLinkage(Function::ExternalLinkage); EsanExit->setLinkage(Function::ExternalLinkage);
IRB_Dtor.CreateCall(EsanExit, {ToolInfoArg}); IRB_Dtor.CreateCall(EsanExit, {ToolInfoArg});
appendToGlobalDtors(M, EsanDtorFunction, EsanCtorAndDtorPriority); appendToGlobalDtors(M, EsanDtorFunction, EsanCtorAndDtorPriority);

View File

@ -425,7 +425,7 @@ void MemorySanitizer::initializeCallbacks(Module &M) {
// which is not yet implemented. // which is not yet implemented.
StringRef WarningFnName = Recover ? "__msan_warning" StringRef WarningFnName = Recover ? "__msan_warning"
: "__msan_warning_noreturn"; : "__msan_warning_noreturn";
WarningFn = M.getOrInsertFunction(WarningFnName, IRB.getVoidTy(), nullptr); WarningFn = M.getOrInsertFunction(WarningFnName, IRB.getVoidTy());
for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes; for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes;
AccessSizeIndex++) { AccessSizeIndex++) {
@ -433,31 +433,31 @@ void MemorySanitizer::initializeCallbacks(Module &M) {
std::string FunctionName = "__msan_maybe_warning_" + itostr(AccessSize); std::string FunctionName = "__msan_maybe_warning_" + itostr(AccessSize);
MaybeWarningFn[AccessSizeIndex] = M.getOrInsertFunction( MaybeWarningFn[AccessSizeIndex] = M.getOrInsertFunction(
FunctionName, IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8), FunctionName, IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8),
IRB.getInt32Ty(), nullptr); IRB.getInt32Ty());
FunctionName = "__msan_maybe_store_origin_" + itostr(AccessSize); FunctionName = "__msan_maybe_store_origin_" + itostr(AccessSize);
MaybeStoreOriginFn[AccessSizeIndex] = M.getOrInsertFunction( MaybeStoreOriginFn[AccessSizeIndex] = M.getOrInsertFunction(
FunctionName, IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8), FunctionName, IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8),
IRB.getInt8PtrTy(), IRB.getInt32Ty(), nullptr); IRB.getInt8PtrTy(), IRB.getInt32Ty());
} }
MsanSetAllocaOrigin4Fn = M.getOrInsertFunction( MsanSetAllocaOrigin4Fn = M.getOrInsertFunction(
"__msan_set_alloca_origin4", IRB.getVoidTy(), IRB.getInt8PtrTy(), IntptrTy, "__msan_set_alloca_origin4", IRB.getVoidTy(), IRB.getInt8PtrTy(), IntptrTy,
IRB.getInt8PtrTy(), IntptrTy, nullptr); IRB.getInt8PtrTy(), IntptrTy);
MsanPoisonStackFn = MsanPoisonStackFn =
M.getOrInsertFunction("__msan_poison_stack", IRB.getVoidTy(), M.getOrInsertFunction("__msan_poison_stack", IRB.getVoidTy(),
IRB.getInt8PtrTy(), IntptrTy, nullptr); IRB.getInt8PtrTy(), IntptrTy);
MsanChainOriginFn = M.getOrInsertFunction( MsanChainOriginFn = M.getOrInsertFunction(
"__msan_chain_origin", IRB.getInt32Ty(), IRB.getInt32Ty(), nullptr); "__msan_chain_origin", IRB.getInt32Ty(), IRB.getInt32Ty());
MemmoveFn = M.getOrInsertFunction( MemmoveFn = M.getOrInsertFunction(
"__msan_memmove", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), "__msan_memmove", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
IRB.getInt8PtrTy(), IntptrTy, nullptr); IRB.getInt8PtrTy(), IntptrTy);
MemcpyFn = M.getOrInsertFunction( MemcpyFn = M.getOrInsertFunction(
"__msan_memcpy", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), "__msan_memcpy", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
IntptrTy, nullptr); IntptrTy);
MemsetFn = M.getOrInsertFunction( MemsetFn = M.getOrInsertFunction(
"__msan_memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt32Ty(), "__msan_memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt32Ty(),
IntptrTy, nullptr); IntptrTy);
// Create globals. // Create globals.
RetvalTLS = new GlobalVariable( RetvalTLS = new GlobalVariable(

View File

@ -262,39 +262,39 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
Int32Ty = IRB.getInt32Ty(); Int32Ty = IRB.getInt32Ty();
SanCovFunction = checkSanitizerInterfaceFunction( SanCovFunction = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(SanCovName, VoidTy, Int32PtrTy, nullptr)); M.getOrInsertFunction(SanCovName, VoidTy, Int32PtrTy));
SanCovWithCheckFunction = checkSanitizerInterfaceFunction( SanCovWithCheckFunction = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(SanCovWithCheckName, VoidTy, Int32PtrTy, nullptr)); M.getOrInsertFunction(SanCovWithCheckName, VoidTy, Int32PtrTy));
SanCovTracePCIndir = checkSanitizerInterfaceFunction( SanCovTracePCIndir = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(SanCovTracePCIndirName, VoidTy, IntptrTy, nullptr)); M.getOrInsertFunction(SanCovTracePCIndirName, VoidTy, IntptrTy));
SanCovIndirCallFunction = SanCovIndirCallFunction =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
SanCovIndirCallName, VoidTy, IntptrTy, IntptrTy, nullptr)); SanCovIndirCallName, VoidTy, IntptrTy, IntptrTy));
SanCovTraceCmpFunction[0] = SanCovTraceCmpFunction[0] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
SanCovTraceCmp1, VoidTy, IRB.getInt8Ty(), IRB.getInt8Ty(), nullptr)); SanCovTraceCmp1, VoidTy, IRB.getInt8Ty(), IRB.getInt8Ty()));
SanCovTraceCmpFunction[1] = checkSanitizerInterfaceFunction( SanCovTraceCmpFunction[1] = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(SanCovTraceCmp2, VoidTy, IRB.getInt16Ty(), M.getOrInsertFunction(SanCovTraceCmp2, VoidTy, IRB.getInt16Ty(),
IRB.getInt16Ty(), nullptr)); IRB.getInt16Ty()));
SanCovTraceCmpFunction[2] = checkSanitizerInterfaceFunction( SanCovTraceCmpFunction[2] = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(SanCovTraceCmp4, VoidTy, IRB.getInt32Ty(), M.getOrInsertFunction(SanCovTraceCmp4, VoidTy, IRB.getInt32Ty(),
IRB.getInt32Ty(), nullptr)); IRB.getInt32Ty()));
SanCovTraceCmpFunction[3] = SanCovTraceCmpFunction[3] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
SanCovTraceCmp8, VoidTy, Int64Ty, Int64Ty, nullptr)); SanCovTraceCmp8, VoidTy, Int64Ty, Int64Ty));
SanCovTraceDivFunction[0] = SanCovTraceDivFunction[0] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
SanCovTraceDiv4, VoidTy, IRB.getInt32Ty(), nullptr)); SanCovTraceDiv4, VoidTy, IRB.getInt32Ty()));
SanCovTraceDivFunction[1] = SanCovTraceDivFunction[1] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
SanCovTraceDiv8, VoidTy, Int64Ty, nullptr)); SanCovTraceDiv8, VoidTy, Int64Ty));
SanCovTraceGepFunction = SanCovTraceGepFunction =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
SanCovTraceGep, VoidTy, IntptrTy, nullptr)); SanCovTraceGep, VoidTy, IntptrTy));
SanCovTraceSwitchFunction = SanCovTraceSwitchFunction =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
SanCovTraceSwitchName, VoidTy, Int64Ty, Int64PtrTy, nullptr)); SanCovTraceSwitchName, VoidTy, Int64Ty, Int64PtrTy));
// We insert an empty inline asm after cov callbacks to avoid callback merge. // We insert an empty inline asm after cov callbacks to avoid callback merge.
EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false), EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
@ -302,13 +302,13 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
/*hasSideEffects=*/true); /*hasSideEffects=*/true);
SanCovTracePC = checkSanitizerInterfaceFunction( SanCovTracePC = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(SanCovTracePCName, VoidTy, nullptr)); M.getOrInsertFunction(SanCovTracePCName, VoidTy));
SanCovTracePCGuard = checkSanitizerInterfaceFunction(M.getOrInsertFunction( SanCovTracePCGuard = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
SanCovTracePCGuardName, VoidTy, Int32PtrTy, nullptr)); SanCovTracePCGuardName, VoidTy, Int32PtrTy));
SanCovTraceEnter = checkSanitizerInterfaceFunction( SanCovTraceEnter = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(SanCovTraceEnterName, VoidTy, Int32PtrTy, nullptr)); M.getOrInsertFunction(SanCovTraceEnterName, VoidTy, Int32PtrTy));
SanCovTraceBB = checkSanitizerInterfaceFunction( SanCovTraceBB = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(SanCovTraceBBName, VoidTy, Int32PtrTy, nullptr)); M.getOrInsertFunction(SanCovTraceBBName, VoidTy, Int32PtrTy));
// At this point we create a dummy array of guards because we don't // At this point we create a dummy array of guards because we don't
// know how many elements we will need. // know how many elements we will need.

View File

@ -160,13 +160,13 @@ void ThreadSanitizer::initializeCallbacks(Module &M) {
Attribute::NoUnwind); Attribute::NoUnwind);
// Initialize the callbacks. // Initialize the callbacks.
TsanFuncEntry = checkSanitizerInterfaceFunction(M.getOrInsertFunction( TsanFuncEntry = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
"__tsan_func_entry", Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr)); "__tsan_func_entry", Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
TsanFuncExit = checkSanitizerInterfaceFunction( TsanFuncExit = checkSanitizerInterfaceFunction(
M.getOrInsertFunction("__tsan_func_exit", Attr, IRB.getVoidTy(), nullptr)); M.getOrInsertFunction("__tsan_func_exit", Attr, IRB.getVoidTy()));
TsanIgnoreBegin = checkSanitizerInterfaceFunction(M.getOrInsertFunction( TsanIgnoreBegin = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
"__tsan_ignore_thread_begin", Attr, IRB.getVoidTy(), nullptr)); "__tsan_ignore_thread_begin", Attr, IRB.getVoidTy()));
TsanIgnoreEnd = checkSanitizerInterfaceFunction(M.getOrInsertFunction( TsanIgnoreEnd = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
"__tsan_ignore_thread_end", Attr, IRB.getVoidTy(), nullptr)); "__tsan_ignore_thread_end", Attr, IRB.getVoidTy()));
OrdTy = IRB.getInt32Ty(); OrdTy = IRB.getInt32Ty();
for (size_t i = 0; i < kNumberOfAccessSizes; ++i) { for (size_t i = 0; i < kNumberOfAccessSizes; ++i) {
const unsigned ByteSize = 1U << i; const unsigned ByteSize = 1U << i;
@ -175,31 +175,31 @@ void ThreadSanitizer::initializeCallbacks(Module &M) {
std::string BitSizeStr = utostr(BitSize); std::string BitSizeStr = utostr(BitSize);
SmallString<32> ReadName("__tsan_read" + ByteSizeStr); SmallString<32> ReadName("__tsan_read" + ByteSizeStr);
TsanRead[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction( TsanRead[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
ReadName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr)); ReadName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
SmallString<32> WriteName("__tsan_write" + ByteSizeStr); SmallString<32> WriteName("__tsan_write" + ByteSizeStr);
TsanWrite[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction( TsanWrite[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
WriteName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr)); WriteName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
SmallString<64> UnalignedReadName("__tsan_unaligned_read" + ByteSizeStr); SmallString<64> UnalignedReadName("__tsan_unaligned_read" + ByteSizeStr);
TsanUnalignedRead[i] = TsanUnalignedRead[i] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
UnalignedReadName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr)); UnalignedReadName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
SmallString<64> UnalignedWriteName("__tsan_unaligned_write" + ByteSizeStr); SmallString<64> UnalignedWriteName("__tsan_unaligned_write" + ByteSizeStr);
TsanUnalignedWrite[i] = TsanUnalignedWrite[i] =
checkSanitizerInterfaceFunction(M.getOrInsertFunction( checkSanitizerInterfaceFunction(M.getOrInsertFunction(
UnalignedWriteName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr)); UnalignedWriteName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
Type *Ty = Type::getIntNTy(M.getContext(), BitSize); Type *Ty = Type::getIntNTy(M.getContext(), BitSize);
Type *PtrTy = Ty->getPointerTo(); Type *PtrTy = Ty->getPointerTo();
SmallString<32> AtomicLoadName("__tsan_atomic" + BitSizeStr + "_load"); SmallString<32> AtomicLoadName("__tsan_atomic" + BitSizeStr + "_load");
TsanAtomicLoad[i] = checkSanitizerInterfaceFunction( TsanAtomicLoad[i] = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(AtomicLoadName, Attr, Ty, PtrTy, OrdTy, nullptr)); M.getOrInsertFunction(AtomicLoadName, Attr, Ty, PtrTy, OrdTy));
SmallString<32> AtomicStoreName("__tsan_atomic" + BitSizeStr + "_store"); SmallString<32> AtomicStoreName("__tsan_atomic" + BitSizeStr + "_store");
TsanAtomicStore[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction( TsanAtomicStore[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
AtomicStoreName, Attr, IRB.getVoidTy(), PtrTy, Ty, OrdTy, nullptr)); AtomicStoreName, Attr, IRB.getVoidTy(), PtrTy, Ty, OrdTy));
for (int op = AtomicRMWInst::FIRST_BINOP; for (int op = AtomicRMWInst::FIRST_BINOP;
op <= AtomicRMWInst::LAST_BINOP; ++op) { op <= AtomicRMWInst::LAST_BINOP; ++op) {
@ -223,33 +223,33 @@ void ThreadSanitizer::initializeCallbacks(Module &M) {
continue; continue;
SmallString<32> RMWName("__tsan_atomic" + itostr(BitSize) + NamePart); SmallString<32> RMWName("__tsan_atomic" + itostr(BitSize) + NamePart);
TsanAtomicRMW[op][i] = checkSanitizerInterfaceFunction( TsanAtomicRMW[op][i] = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(RMWName, Attr, Ty, PtrTy, Ty, OrdTy, nullptr)); M.getOrInsertFunction(RMWName, Attr, Ty, PtrTy, Ty, OrdTy));
} }
SmallString<32> AtomicCASName("__tsan_atomic" + BitSizeStr + SmallString<32> AtomicCASName("__tsan_atomic" + BitSizeStr +
"_compare_exchange_val"); "_compare_exchange_val");
TsanAtomicCAS[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction( TsanAtomicCAS[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
AtomicCASName, Attr, Ty, PtrTy, Ty, Ty, OrdTy, OrdTy, nullptr)); AtomicCASName, Attr, Ty, PtrTy, Ty, Ty, OrdTy, OrdTy));
} }
TsanVptrUpdate = checkSanitizerInterfaceFunction( TsanVptrUpdate = checkSanitizerInterfaceFunction(
M.getOrInsertFunction("__tsan_vptr_update", Attr, IRB.getVoidTy(), M.getOrInsertFunction("__tsan_vptr_update", Attr, IRB.getVoidTy(),
IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), nullptr)); IRB.getInt8PtrTy(), IRB.getInt8PtrTy()));
TsanVptrLoad = checkSanitizerInterfaceFunction(M.getOrInsertFunction( TsanVptrLoad = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
"__tsan_vptr_read", Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr)); "__tsan_vptr_read", Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
TsanAtomicThreadFence = checkSanitizerInterfaceFunction(M.getOrInsertFunction( TsanAtomicThreadFence = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
"__tsan_atomic_thread_fence", Attr, IRB.getVoidTy(), OrdTy, nullptr)); "__tsan_atomic_thread_fence", Attr, IRB.getVoidTy(), OrdTy));
TsanAtomicSignalFence = checkSanitizerInterfaceFunction(M.getOrInsertFunction( TsanAtomicSignalFence = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
"__tsan_atomic_signal_fence", Attr, IRB.getVoidTy(), OrdTy, nullptr)); "__tsan_atomic_signal_fence", Attr, IRB.getVoidTy(), OrdTy));
MemmoveFn = checkSanitizerInterfaceFunction( MemmoveFn = checkSanitizerInterfaceFunction(
M.getOrInsertFunction("memmove", Attr, IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), M.getOrInsertFunction("memmove", Attr, IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
IRB.getInt8PtrTy(), IntptrTy, nullptr)); IRB.getInt8PtrTy(), IntptrTy));
MemcpyFn = checkSanitizerInterfaceFunction( MemcpyFn = checkSanitizerInterfaceFunction(
M.getOrInsertFunction("memcpy", Attr, IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), M.getOrInsertFunction("memcpy", Attr, IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
IRB.getInt8PtrTy(), IntptrTy, nullptr)); IRB.getInt8PtrTy(), IntptrTy));
MemsetFn = checkSanitizerInterfaceFunction( MemsetFn = checkSanitizerInterfaceFunction(
M.getOrInsertFunction("memset", Attr, IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), M.getOrInsertFunction("memset", Attr, IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
IRB.getInt32Ty(), IntptrTy, nullptr)); IRB.getInt32Ty(), IntptrTy));
} }
bool ThreadSanitizer::doInitialization(Module &M) { bool ThreadSanitizer::doInitialization(Module &M) {

View File

@ -823,7 +823,7 @@ bool LoopIdiomRecognize::processLoopStridedStore(
Module *M = TheStore->getModule(); Module *M = TheStore->getModule();
Value *MSP = Value *MSP =
M->getOrInsertFunction("memset_pattern16", Builder.getVoidTy(), M->getOrInsertFunction("memset_pattern16", Builder.getVoidTy(),
Int8PtrTy, Int8PtrTy, IntPtr, (void *)nullptr); Int8PtrTy, Int8PtrTy, IntPtr);
inferLibFuncAttributes(*M->getFunction("memset_pattern16"), *TLI); inferLibFuncAttributes(*M->getFunction("memset_pattern16"), *TLI);
// Otherwise we should form a memset_pattern16. PatternValue is known to be // Otherwise we should form a memset_pattern16. PatternValue is known to be

View File

@ -723,7 +723,7 @@ Value *llvm::emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL,
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
LLVMContext &Context = B.GetInsertBlock()->getContext(); LLVMContext &Context = B.GetInsertBlock()->getContext();
Constant *StrLen = M->getOrInsertFunction("strlen", DL.getIntPtrType(Context), Constant *StrLen = M->getOrInsertFunction("strlen", DL.getIntPtrType(Context),
B.getInt8PtrTy(), nullptr); B.getInt8PtrTy());
inferLibFuncAttributes(*M->getFunction("strlen"), *TLI); inferLibFuncAttributes(*M->getFunction("strlen"), *TLI);
CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), "strlen"); CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), "strlen");
if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts())) if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts()))
@ -741,7 +741,7 @@ Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilder<> &B,
Type *I8Ptr = B.getInt8PtrTy(); Type *I8Ptr = B.getInt8PtrTy();
Type *I32Ty = B.getInt32Ty(); Type *I32Ty = B.getInt32Ty();
Constant *StrChr = Constant *StrChr =
M->getOrInsertFunction("strchr", I8Ptr, I8Ptr, I32Ty, nullptr); M->getOrInsertFunction("strchr", I8Ptr, I8Ptr, I32Ty);
inferLibFuncAttributes(*M->getFunction("strchr"), *TLI); inferLibFuncAttributes(*M->getFunction("strchr"), *TLI);
CallInst *CI = B.CreateCall( CallInst *CI = B.CreateCall(
StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, "strchr"); StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, "strchr");
@ -759,7 +759,7 @@ Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
LLVMContext &Context = B.GetInsertBlock()->getContext(); LLVMContext &Context = B.GetInsertBlock()->getContext();
Value *StrNCmp = M->getOrInsertFunction("strncmp", B.getInt32Ty(), Value *StrNCmp = M->getOrInsertFunction("strncmp", B.getInt32Ty(),
B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt8PtrTy(),
DL.getIntPtrType(Context), nullptr); DL.getIntPtrType(Context));
inferLibFuncAttributes(*M->getFunction("strncmp"), *TLI); inferLibFuncAttributes(*M->getFunction("strncmp"), *TLI);
CallInst *CI = B.CreateCall( CallInst *CI = B.CreateCall(
StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "strncmp"); StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "strncmp");
@ -777,7 +777,7 @@ Value *llvm::emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
Type *I8Ptr = B.getInt8PtrTy(); Type *I8Ptr = B.getInt8PtrTy();
Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr, nullptr); Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr);
inferLibFuncAttributes(*M->getFunction(Name), *TLI); inferLibFuncAttributes(*M->getFunction(Name), *TLI);
CallInst *CI = CallInst *CI =
B.CreateCall(StrCpy, {castToCStr(Dst, B), castToCStr(Src, B)}, Name); B.CreateCall(StrCpy, {castToCStr(Dst, B), castToCStr(Src, B)}, Name);
@ -794,7 +794,7 @@ Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
Type *I8Ptr = B.getInt8PtrTy(); Type *I8Ptr = B.getInt8PtrTy();
Value *StrNCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr, Value *StrNCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr,
Len->getType(), nullptr); Len->getType());
inferLibFuncAttributes(*M->getFunction(Name), *TLI); inferLibFuncAttributes(*M->getFunction(Name), *TLI);
CallInst *CI = B.CreateCall( CallInst *CI = B.CreateCall(
StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, "strncpy"); StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, "strncpy");
@ -817,7 +817,7 @@ Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
Value *MemCpy = M->getOrInsertFunction( Value *MemCpy = M->getOrInsertFunction(
"__memcpy_chk", AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(), "__memcpy_chk", AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(),
B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context), B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context),
DL.getIntPtrType(Context), nullptr); DL.getIntPtrType(Context));
Dst = castToCStr(Dst, B); Dst = castToCStr(Dst, B);
Src = castToCStr(Src, B); Src = castToCStr(Src, B);
CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize}); CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
@ -835,7 +835,7 @@ Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B,
LLVMContext &Context = B.GetInsertBlock()->getContext(); LLVMContext &Context = B.GetInsertBlock()->getContext();
Value *MemChr = M->getOrInsertFunction("memchr", B.getInt8PtrTy(), Value *MemChr = M->getOrInsertFunction("memchr", B.getInt8PtrTy(),
B.getInt8PtrTy(), B.getInt32Ty(), B.getInt8PtrTy(), B.getInt32Ty(),
DL.getIntPtrType(Context), nullptr); DL.getIntPtrType(Context));
inferLibFuncAttributes(*M->getFunction("memchr"), *TLI); inferLibFuncAttributes(*M->getFunction("memchr"), *TLI);
CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, "memchr"); CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, "memchr");
@ -854,7 +854,7 @@ Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
LLVMContext &Context = B.GetInsertBlock()->getContext(); LLVMContext &Context = B.GetInsertBlock()->getContext();
Value *MemCmp = M->getOrInsertFunction("memcmp", B.getInt32Ty(), Value *MemCmp = M->getOrInsertFunction("memcmp", B.getInt32Ty(),
B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt8PtrTy(),
DL.getIntPtrType(Context), nullptr); DL.getIntPtrType(Context));
inferLibFuncAttributes(*M->getFunction("memcmp"), *TLI); inferLibFuncAttributes(*M->getFunction("memcmp"), *TLI);
CallInst *CI = B.CreateCall( CallInst *CI = B.CreateCall(
MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "memcmp"); MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "memcmp");
@ -887,7 +887,7 @@ Value *llvm::emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
Value *Callee = M->getOrInsertFunction(Name, Op->getType(), Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
Op->getType(), nullptr); Op->getType());
CallInst *CI = B.CreateCall(Callee, Op, Name); CallInst *CI = B.CreateCall(Callee, Op, Name);
CI->setAttributes(Attrs); CI->setAttributes(Attrs);
if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts())) if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
@ -903,7 +903,7 @@ Value *llvm::emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
Value *Callee = M->getOrInsertFunction(Name, Op1->getType(), Op1->getType(), Value *Callee = M->getOrInsertFunction(Name, Op1->getType(), Op1->getType(),
Op2->getType(), nullptr); Op2->getType());
CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name); CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name);
CI->setAttributes(Attrs); CI->setAttributes(Attrs);
if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts())) if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
@ -918,8 +918,7 @@ Value *llvm::emitPutChar(Value *Char, IRBuilder<> &B,
return nullptr; return nullptr;
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(), Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(), B.getInt32Ty());
B.getInt32Ty(), nullptr);
inferLibFuncAttributes(*M->getFunction("putchar"), *TLI); inferLibFuncAttributes(*M->getFunction("putchar"), *TLI);
CallInst *CI = B.CreateCall(PutChar, CallInst *CI = B.CreateCall(PutChar,
B.CreateIntCast(Char, B.CreateIntCast(Char,
@ -940,7 +939,7 @@ Value *llvm::emitPutS(Value *Str, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
Value *PutS = Value *PutS =
M->getOrInsertFunction("puts", B.getInt32Ty(), B.getInt8PtrTy(), nullptr); M->getOrInsertFunction("puts", B.getInt32Ty(), B.getInt8PtrTy());
inferLibFuncAttributes(*M->getFunction("puts"), *TLI); inferLibFuncAttributes(*M->getFunction("puts"), *TLI);
CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), "puts"); CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), "puts");
if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts())) if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts()))
@ -955,7 +954,7 @@ Value *llvm::emitFPutC(Value *Char, Value *File, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
Constant *F = M->getOrInsertFunction("fputc", B.getInt32Ty(), B.getInt32Ty(), Constant *F = M->getOrInsertFunction("fputc", B.getInt32Ty(), B.getInt32Ty(),
File->getType(), nullptr); File->getType());
if (File->getType()->isPointerTy()) if (File->getType()->isPointerTy())
inferLibFuncAttributes(*M->getFunction("fputc"), *TLI); inferLibFuncAttributes(*M->getFunction("fputc"), *TLI);
Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true, Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
@ -975,7 +974,7 @@ Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
StringRef FPutsName = TLI->getName(LibFunc_fputs); StringRef FPutsName = TLI->getName(LibFunc_fputs);
Constant *F = M->getOrInsertFunction( Constant *F = M->getOrInsertFunction(
FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType(), nullptr); FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType());
if (File->getType()->isPointerTy()) if (File->getType()->isPointerTy())
inferLibFuncAttributes(*M->getFunction(FPutsName), *TLI); inferLibFuncAttributes(*M->getFunction(FPutsName), *TLI);
CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, "fputs"); CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, "fputs");
@ -995,8 +994,8 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
StringRef FWriteName = TLI->getName(LibFunc_fwrite); StringRef FWriteName = TLI->getName(LibFunc_fwrite);
Constant *F = M->getOrInsertFunction( Constant *F = M->getOrInsertFunction(
FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(), FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType(), DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
nullptr);
if (File->getType()->isPointerTy()) if (File->getType()->isPointerTy())
inferLibFuncAttributes(*M->getFunction(FWriteName), *TLI); inferLibFuncAttributes(*M->getFunction(FWriteName), *TLI);
CallInst *CI = CallInst *CI =

View File

@ -819,7 +819,7 @@ static Value *emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs,
const DataLayout &DL = M->getDataLayout(); const DataLayout &DL = M->getDataLayout();
IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext())); IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext()));
Value *Calloc = M->getOrInsertFunction("calloc", Attrs, B.getInt8PtrTy(), Value *Calloc = M->getOrInsertFunction("calloc", Attrs, B.getInt8PtrTy(),
PtrType, PtrType, nullptr); PtrType, PtrType);
CallInst *CI = B.CreateCall(Calloc, { Num, Size }, "calloc"); CallInst *CI = B.CreateCall(Calloc, { Num, Size }, "calloc");
if (const auto *F = dyn_cast<Function>(Calloc->stripPointerCasts())) if (const auto *F = dyn_cast<Function>(Calloc->stripPointerCasts()))
@ -1219,7 +1219,7 @@ Value *LibCallSimplifier::optimizeExp2(CallInst *CI, IRBuilder<> &B) {
Module *M = CI->getModule(); Module *M = CI->getModule();
Value *NewCallee = Value *NewCallee =
M->getOrInsertFunction(TLI->getName(LdExp), Op->getType(), M->getOrInsertFunction(TLI->getName(LdExp), Op->getType(),
Op->getType(), B.getInt32Ty(), nullptr); Op->getType(), B.getInt32Ty());
CallInst *CI = B.CreateCall(NewCallee, {One, LdExpArg}); CallInst *CI = B.CreateCall(NewCallee, {One, LdExpArg});
if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts())) if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv()); CI->setCallingConv(F->getCallingConv());
@ -1443,7 +1443,7 @@ static void insertSinCosCall(IRBuilder<> &B, Function *OrigCallee, Value *Arg,
Module *M = OrigCallee->getParent(); Module *M = OrigCallee->getParent();
Value *Callee = M->getOrInsertFunction(Name, OrigCallee->getAttributes(), Value *Callee = M->getOrInsertFunction(Name, OrigCallee->getAttributes(),
ResTy, ArgTy, nullptr); ResTy, ArgTy);
if (Instruction *ArgInst = dyn_cast<Instruction>(Arg)) { if (Instruction *ArgInst = dyn_cast<Instruction>(Arg)) {
// If the argument is an instruction, it must dominate all uses so put our // If the argument is an instruction, it must dominate all uses so put our

View File

@ -841,7 +841,7 @@ static void CleanupAndPrepareModules(BugDriver &BD,
// Prototype: void *getPointerToNamedFunction(const char* Name) // Prototype: void *getPointerToNamedFunction(const char* Name)
Constant *resolverFunc = Safe->getOrInsertFunction( Constant *resolverFunc = Safe->getOrInsertFunction(
"getPointerToNamedFunction", Type::getInt8PtrTy(Safe->getContext()), "getPointerToNamedFunction", Type::getInt8PtrTy(Safe->getContext()),
Type::getInt8PtrTy(Safe->getContext()), (Type *)nullptr); Type::getInt8PtrTy(Safe->getContext()));
// Use the function we just added to get addresses of functions we need. // Use the function we just added to get addresses of functions we need.
for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) { for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) {

View File

@ -606,8 +606,7 @@ int main(int argc, char **argv, char * const *envp) {
// If the program doesn't explicitly call exit, we will need the Exit // If the program doesn't explicitly call exit, we will need the Exit
// function later on to make an explicit call, so get the function now. // function later on to make an explicit call, so get the function now.
Constant *Exit = Mod->getOrInsertFunction("exit", Type::getVoidTy(Context), Constant *Exit = Mod->getOrInsertFunction("exit", Type::getVoidTy(Context),
Type::getInt32Ty(Context), Type::getInt32Ty(Context));
nullptr);
// Run static constructors. // Run static constructors.
if (!ForceInterpreter) { if (!ForceInterpreter) {