llvm.org GIT mirror llvm / 1d02724
Revert "Turn some C-style vararg into variadic templates" This reverts commit r299925 because it broke the buildbots. See e.g. http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/6008 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299928 91177308-0d34-0410-b5e6-96231b3b80d8 Diana Picus 2 years ago
24 changed file(s) with 166 addition(s) and 132 deletion(s). Raw diff Collapse all Expand all
320320 /// or a ConstantExpr BitCast of that type if the named function has a
321321 /// different type. This version of the method takes a null terminated list of
322322 /// function arguments, which makes it easier for clients to use.
323 template
324 Constant *getOrInsertFunction(StringRef Name,
325 AttributeList AttributeList,
326 Type *RetTy, ArgsTy... Args)
327 {
328 SmallVector ArgTys{Args...};
329 return getOrInsertFunction(Name,
330 FunctionType::get(RetTy, ArgTys, false),
331 AttributeList);
332 }
323 Constant *getOrInsertFunction(StringRef Name, AttributeList AttributeList,
324 Type *RetTy, ...) LLVM_END_WITH_NULL;
333325
334326 /// Same as above, but without the attributes.
335 template
336 Constant *getOrInsertFunction(StringRef Name, Type *RetTy, ArgsTy... Args) {
337 return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
338 }
327 Constant *getOrInsertFunction(StringRef Name, Type *RetTy, ...)
328 LLVM_END_WITH_NULL;
339329
340330 /// Look up the specified function in the module symbol table. If it does not
341331 /// exist, return null.
4040 Type *VoidTy = Type::getVoidTy(F.getContext());
4141 Constant *CountingFn =
4242 F.getParent()->getOrInsertFunction(CountingFunctionName,
43 VoidTy);
43 VoidTy, nullptr);
4444 CallInst::Create(CountingFn, "", &*F.begin()->getFirstInsertionPt());
4545 return true;
4646 }
114114 Type::getInt8PtrTy(Context),
115115 Type::getInt8PtrTy(Context),
116116 Type::getInt8PtrTy(Context),
117 DL.getIntPtrType(Context));
117 DL.getIntPtrType(Context), nullptr);
118118 break;
119119 case Intrinsic::memmove:
120120 M.getOrInsertFunction("memmove",
121121 Type::getInt8PtrTy(Context),
122122 Type::getInt8PtrTy(Context),
123123 Type::getInt8PtrTy(Context),
124 DL.getIntPtrType(Context));
124 DL.getIntPtrType(Context), nullptr);
125125 break;
126126 case Intrinsic::memset:
127127 M.getOrInsertFunction("memset",
128128 Type::getInt8PtrTy(Context),
129129 Type::getInt8PtrTy(Context),
130130 Type::getInt32Ty(M.getContext()),
131 DL.getIntPtrType(Context));
131 DL.getIntPtrType(Context), nullptr);
132132 break;
133133 case Intrinsic::sqrt:
134134 EnsureFPIntrinsicsExist(M, F, "sqrtf", "sqrt", "sqrtl");
10971097 // Create the function using an IR-level function.
10981098 LLVMContext &C = M.getContext();
10991099 Function *F = dyn_cast(
1100 M.getOrInsertFunction(NameStream.str(), Type::getVoidTy(C)));
1100 M.getOrInsertFunction(NameStream.str(), Type::getVoidTy(C), nullptr));
11011101 assert(F && "Function was null!");
11021102
11031103 // NOTE: If this is linkonceodr, then we can take advantage of linker deduping
450450 IRBuilder<> IRBFail(CheckTerm);
451451 // FIXME: respect -fsanitize-trap / -ftrap-function here?
452452 Constant *StackChkFail = F.getParent()->getOrInsertFunction(
453 "__stack_chk_fail", IRB.getVoidTy());
453 "__stack_chk_fail", IRB.getVoidTy(), nullptr);
454454 IRBFail.CreateCall(StackChkFail, {});
455455 }
456456
481481 Module &M = *F.getParent();
482482 RegisterFn = M.getOrInsertFunction(
483483 "_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()),
484 PointerType::getUnqual(FunctionContextTy));
484 PointerType::getUnqual(FunctionContextTy), nullptr);
485485 UnregisterFn = M.getOrInsertFunction(
486486 "_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()),
487 PointerType::getUnqual(FunctionContextTy));
487 PointerType::getUnqual(FunctionContextTy), nullptr);
488488 FrameAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::frameaddress);
489489 StackAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::stacksave);
490490 StackRestoreFn = Intrinsic::getDeclaration(&M, Intrinsic::stackrestore);
483483 Constant *StackChkFail =
484484 M->getOrInsertFunction("__stack_smash_handler",
485485 Type::getVoidTy(Context),
486 Type::getInt8PtrTy(Context));
486 Type::getInt8PtrTy(Context), nullptr);
487487
488488 B.CreateCall(StackChkFail, B.CreateGlobalStringPtr(F->getName(), "SSH"));
489489 } else {
490490 Constant *StackChkFail =
491 M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context));
492
491 M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context),
492 nullptr);
493493 B.CreateCall(StackChkFail, {});
494494 }
495495 B.CreateUnreachable();
18171817 Module *M = IRB.GetInsertBlock()->getParent()->getParent();
18181818 Type *StackPtrTy = Type::getInt8PtrTy(M->getContext());
18191819 Value *Fn = M->getOrInsertFunction("__safestack_pointer_address",
1820 StackPtrTy->getPointerTo(0));
1820 StackPtrTy->getPointerTo(0), nullptr);
18211821 return IRB.CreateCall(Fn);
18221822 }
18231823
465465 Value *MallocFunc = MallocF;
466466 if (!MallocFunc)
467467 // prototype malloc as "void *malloc(size_t)"
468 MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy);
468 MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy, nullptr);
469469 PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
470470 CallInst *MCall = nullptr;
471471 Instruction *Result = nullptr;
559559 Type *VoidTy = Type::getVoidTy(M->getContext());
560560 Type *IntPtrTy = Type::getInt8PtrTy(M->getContext());
561561 // prototype free as "void free(void*)"
562 Value *FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy);
562 Value *FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy, nullptr);
563563 CallInst *Result = nullptr;
564564 Value *PtrCast = Source;
565565 if (InsertBefore) {
146146 return getOrInsertFunction(Name, Ty, AttributeList());
147147 }
148148
149 // getOrInsertFunction - Look up the specified function in the module symbol
150 // table. If it does not exist, add a prototype for the function and return it.
151 // This version of the method takes a null terminated list of function
152 // arguments, which makes it easier for clients to use.
153 //
154 Constant *Module::getOrInsertFunction(StringRef Name,
155 AttributeList AttributeList, Type *RetTy,
156 ...) {
157 va_list Args;
158 va_start(Args, RetTy);
159
160 // Build the list of argument types...
161 std::vector ArgTys;
162 while (Type *ArgTy = va_arg(Args, Type*))
163 ArgTys.push_back(ArgTy);
164
165 va_end(Args);
166
167 // Build the function type and chain to the other getOrInsertFunction...
168 return getOrInsertFunction(Name,
169 FunctionType::get(RetTy, ArgTys, false),
170 AttributeList);
171 }
172
173 Constant *Module::getOrInsertFunction(StringRef Name,
174 Type *RetTy, ...) {
175 va_list Args;
176 va_start(Args, RetTy);
177
178 // Build the list of argument types...
179 std::vector ArgTys;
180 while (Type *ArgTy = va_arg(Args, Type*))
181 ArgTys.push_back(ArgTy);
182
183 va_end(Args);
184
185 // Build the function type and chain to the other getOrInsertFunction...
186 return getOrInsertFunction(Name, FunctionType::get(RetTy, ArgTys, false),
187 AttributeList());
188 }
189
149190 // getFunction - Look up the specified function in the module symbol table.
150191 // If it does not exist, return null.
151192 //
21452145 Type *VoidTy = Type::getVoidTy(Ctx);
21462146 Module *M = Func->getParent();
21472147 Constant *CF = M->getOrInsertFunction(HexagonVolatileMemcpyName, VoidTy,
2148 Int32PtrTy, Int32PtrTy, Int32Ty);
2148 Int32PtrTy, Int32PtrTy, Int32Ty,
2149 nullptr);
21492150 Function *Fn = cast(CF);
21502151 Fn->setLinkage(Function::ExternalLinkage);
21512152
419419 Attribute::ReadNone);
420420 A = A.addAttribute(C, AttributeList::FunctionIndex,
421421 Attribute::NoInline);
422 Value *F = (M->getOrInsertFunction(Name, A, MyVoid, T));
422 Value *F = (M->getOrInsertFunction(Name, A, MyVoid, T, nullptr));
423423 CallInst::Create(F, Params, "", &I);
424424 } else if (const CallInst *CI = dyn_cast(&I)) {
425425 FunctionType *FT = CI->getFunctionType();
21002100 auto *SecurityCheckCookie = cast(
21012101 M.getOrInsertFunction("__security_check_cookie",
21022102 Type::getVoidTy(M.getContext()),
2103 Type::getInt8PtrTy(M.getContext())));
2103 Type::getInt8PtrTy(M.getContext()), nullptr));
21042104 SecurityCheckCookie->setCallingConv(CallingConv::X86_FastCall);
21052105 SecurityCheckCookie->addAttribute(1, Attribute::AttrKind::InReg);
21062106 return;
9797 LLVMContext &Ctx = M.getContext();
9898 Constant *C = M.getOrInsertFunction(
9999 "__cfi_check", Type::getVoidTy(Ctx), Type::getInt64Ty(Ctx),
100 Type::getInt8PtrTy(Ctx), Type::getInt8PtrTy(Ctx));
100 Type::getInt8PtrTy(Ctx), Type::getInt8PtrTy(Ctx), nullptr);
101101 Function *F = dyn_cast(C);
102102 // Take over the existing function. The frontend emits a weak stub so that the
103103 // linker knows about the symbol; this pass replaces the function body.
119119 IRBuilder<> IRBFail(TrapBB);
120120 Constant *CFICheckFailFn = M.getOrInsertFunction(
121121 "__cfi_check_fail", Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx),
122 Type::getInt8PtrTy(Ctx));
122 Type::getInt8PtrTy(Ctx), nullptr);
123123 IRBFail.CreateCall(CFICheckFailFn, {&CFICheckFailData, &Addr});
124124 IRBFail.CreateBr(ExitBB);
125125
12201220 // The type of the function in the declaration is irrelevant because every
12211221 // call site will cast it to the correct type.
12221222 auto *SingleImpl = M.getOrInsertFunction(
1223 Res.SingleImplName, Type::getVoidTy(M.getContext()));
1223 Res.SingleImplName, Type::getVoidTy(M.getContext()), nullptr);
12241224
12251225 // This is the import phase so we should not be exporting anything.
12261226 bool IsExported = false;
15671567
15681568 // Declare our poisoning and unpoisoning functions.
15691569 AsanPoisonGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
1570 kAsanPoisonGlobalsName, IRB.getVoidTy(), IntptrTy));
1570 kAsanPoisonGlobalsName, IRB.getVoidTy(), IntptrTy, nullptr));
15711571 AsanPoisonGlobals->setLinkage(Function::ExternalLinkage);
15721572 AsanUnpoisonGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
1573 kAsanUnpoisonGlobalsName, IRB.getVoidTy()));
1573 kAsanUnpoisonGlobalsName, IRB.getVoidTy(), nullptr));
15741574 AsanUnpoisonGlobals->setLinkage(Function::ExternalLinkage);
15751575
15761576 // Declare functions that register/unregister globals.
15771577 AsanRegisterGlobals = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
1578 kAsanRegisterGlobalsName, IRB.getVoidTy(), IntptrTy, IntptrTy));
1578 kAsanRegisterGlobalsName, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr));
15791579 AsanRegisterGlobals->setLinkage(Function::ExternalLinkage);
15801580 AsanUnregisterGlobals = checkSanitizerInterfaceFunction(
15811581 M.getOrInsertFunction(kAsanUnregisterGlobalsName, IRB.getVoidTy(),
1582 IntptrTy, IntptrTy));
1582 IntptrTy, IntptrTy, nullptr));
15831583 AsanUnregisterGlobals->setLinkage(Function::ExternalLinkage);
15841584
15851585 // Declare the functions that find globals in a shared object and then invoke
15861586 // the (un)register function on them.
15871587 AsanRegisterImageGlobals =
15881588 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
1589 kAsanRegisterImageGlobalsName, IRB.getVoidTy(), IntptrTy));
1589 kAsanRegisterImageGlobalsName, IRB.getVoidTy(), IntptrTy, nullptr));
15901590 AsanRegisterImageGlobals->setLinkage(Function::ExternalLinkage);
15911591
15921592 AsanUnregisterImageGlobals =
15931593 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
1594 kAsanUnregisterImageGlobalsName, IRB.getVoidTy(), IntptrTy));
1594 kAsanUnregisterImageGlobalsName, IRB.getVoidTy(), IntptrTy, nullptr));
15951595 AsanUnregisterImageGlobals->setLinkage(Function::ExternalLinkage);
15961596 }
15971597
19661966 AsanErrorCallbackSized[AccessIsWrite][Exp] =
19671967 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
19681968 kAsanReportErrorTemplate + ExpStr + TypeStr + SuffixStr + EndingStr,
1969 IRB.getVoidTy(), IntptrTy, IntptrTy, ExpType));
1969 IRB.getVoidTy(), IntptrTy, IntptrTy, ExpType, nullptr));
19701970 AsanMemoryAccessCallbackSized[AccessIsWrite][Exp] =
19711971 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
19721972 ClMemoryAccessCallbackPrefix + ExpStr + TypeStr + "N" + EndingStr,
1973 IRB.getVoidTy(), IntptrTy, IntptrTy, ExpType));
1973 IRB.getVoidTy(), IntptrTy, IntptrTy, ExpType, nullptr));
19741974 for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes;
19751975 AccessSizeIndex++) {
19761976 const std::string Suffix = TypeStr + itostr(1ULL << AccessSizeIndex);
19771977 AsanErrorCallback[AccessIsWrite][Exp][AccessSizeIndex] =
19781978 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
19791979 kAsanReportErrorTemplate + ExpStr + Suffix + EndingStr,
1980 IRB.getVoidTy(), IntptrTy, ExpType));
1980 IRB.getVoidTy(), IntptrTy, ExpType, nullptr));
19811981 AsanMemoryAccessCallback[AccessIsWrite][Exp][AccessSizeIndex] =
19821982 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
19831983 ClMemoryAccessCallbackPrefix + ExpStr + Suffix + EndingStr,
1984 IRB.getVoidTy(), IntptrTy, ExpType));
1984 IRB.getVoidTy(), IntptrTy, ExpType, nullptr));
19851985 }
19861986 }
19871987 }
19901990 CompileKernel ? std::string("") : ClMemoryAccessCallbackPrefix;
19911991 AsanMemmove = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
19921992 MemIntrinCallbackPrefix + "memmove", IRB.getInt8PtrTy(),
1993 IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy));
1993 IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy, nullptr));
19941994 AsanMemcpy = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
19951995 MemIntrinCallbackPrefix + "memcpy", IRB.getInt8PtrTy(),
1996 IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy));
1996 IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy, nullptr));
19971997 AsanMemset = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
19981998 MemIntrinCallbackPrefix + "memset", IRB.getInt8PtrTy(),
1999 IRB.getInt8PtrTy(), IRB.getInt32Ty(), IntptrTy));
1999 IRB.getInt8PtrTy(), IRB.getInt32Ty(), IntptrTy, nullptr));
20002000
20012001 AsanHandleNoReturnFunc = checkSanitizerInterfaceFunction(
2002 M.getOrInsertFunction(kAsanHandleNoReturnName, IRB.getVoidTy()));
2002 M.getOrInsertFunction(kAsanHandleNoReturnName, IRB.getVoidTy(), nullptr));
20032003
20042004 AsanPtrCmpFunction = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
2005 kAsanPtrCmp, IRB.getVoidTy(), IntptrTy, IntptrTy));
2005 kAsanPtrCmp, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr));
20062006 AsanPtrSubFunction = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
2007 kAsanPtrSub, IRB.getVoidTy(), IntptrTy, IntptrTy));
2007 kAsanPtrSub, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr));
20082008 // We insert an empty inline asm after __asan_report* to avoid callback merge.
20092009 EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
20102010 StringRef(""), StringRef(""),
22412241 std::string Suffix = itostr(i);
22422242 AsanStackMallocFunc[i] = checkSanitizerInterfaceFunction(
22432243 M.getOrInsertFunction(kAsanStackMallocNameTemplate + Suffix, IntptrTy,
2244 IntptrTy));
2244 IntptrTy, nullptr));
22452245 AsanStackFreeFunc[i] = checkSanitizerInterfaceFunction(
22462246 M.getOrInsertFunction(kAsanStackFreeNameTemplate + Suffix,
2247 IRB.getVoidTy(), IntptrTy, IntptrTy));
2247 IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr));
22482248 }
22492249 if (ASan.UseAfterScope) {
22502250 AsanPoisonStackMemoryFunc = checkSanitizerInterfaceFunction(
22512251 M.getOrInsertFunction(kAsanPoisonStackMemoryName, IRB.getVoidTy(),
2252 IntptrTy, IntptrTy));
2252 IntptrTy, IntptrTy, nullptr));
22532253 AsanUnpoisonStackMemoryFunc = checkSanitizerInterfaceFunction(
22542254 M.getOrInsertFunction(kAsanUnpoisonStackMemoryName, IRB.getVoidTy(),
2255 IntptrTy, IntptrTy));
2255 IntptrTy, IntptrTy, nullptr));
22562256 }
22572257
22582258 for (size_t Val : {0x00, 0xf1, 0xf2, 0xf3, 0xf5, 0xf8}) {
22612261 Name << std::setw(2) << std::setfill('0') << std::hex << Val;
22622262 AsanSetShadowFunc[Val] =
22632263 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
2264 Name.str(), IRB.getVoidTy(), IntptrTy, IntptrTy));
2264 Name.str(), IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr));
22652265 }
22662266
22672267 AsanAllocaPoisonFunc = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
2268 kAsanAllocaPoison, IRB.getVoidTy(), IntptrTy, IntptrTy));
2268 kAsanAllocaPoison, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr));
22692269 AsanAllocasUnpoisonFunc =
22702270 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
2271 kAsanAllocasUnpoison, IRB.getVoidTy(), IntptrTy, IntptrTy));
2271 kAsanAllocasUnpoison, IRB.getVoidTy(), IntptrTy, IntptrTy, nullptr));
22722272 }
22732273
22742274 void FunctionStackPoisoner::copyToShadowInline(ArrayRef ShadowMask,
266266 SmallString<32> AlignedLoadName("__esan_aligned_load" + ByteSizeStr);
267267 EsanAlignedLoad[Idx] =
268268 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
269 AlignedLoadName, IRB.getVoidTy(), IRB.getInt8PtrTy()));
269 AlignedLoadName, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr));
270270 SmallString<32> AlignedStoreName("__esan_aligned_store" + ByteSizeStr);
271271 EsanAlignedStore[Idx] =
272272 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
273 AlignedStoreName, IRB.getVoidTy(), IRB.getInt8PtrTy()));
273 AlignedStoreName, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr));
274274 SmallString<32> UnalignedLoadName("__esan_unaligned_load" + ByteSizeStr);
275275 EsanUnalignedLoad[Idx] =
276276 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
277 UnalignedLoadName, IRB.getVoidTy(), IRB.getInt8PtrTy()));
277 UnalignedLoadName, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr));
278278 SmallString<32> UnalignedStoreName("__esan_unaligned_store" + ByteSizeStr);
279279 EsanUnalignedStore[Idx] =
280280 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
281 UnalignedStoreName, IRB.getVoidTy(), IRB.getInt8PtrTy()));
281 UnalignedStoreName, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr));
282282 }
283283 EsanUnalignedLoadN = checkSanitizerInterfaceFunction(
284284 M.getOrInsertFunction("__esan_unaligned_loadN", IRB.getVoidTy(),
285 IRB.getInt8PtrTy(), IntptrTy));
285 IRB.getInt8PtrTy(), IntptrTy, nullptr));
286286 EsanUnalignedStoreN = checkSanitizerInterfaceFunction(
287287 M.getOrInsertFunction("__esan_unaligned_storeN", IRB.getVoidTy(),
288 IRB.getInt8PtrTy(), IntptrTy));
288 IRB.getInt8PtrTy(), IntptrTy, nullptr));
289289 MemmoveFn = checkSanitizerInterfaceFunction(
290290 M.getOrInsertFunction("memmove", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
291 IRB.getInt8PtrTy(), IntptrTy));
291 IRB.getInt8PtrTy(), IntptrTy, nullptr));
292292 MemcpyFn = checkSanitizerInterfaceFunction(
293293 M.getOrInsertFunction("memcpy", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
294 IRB.getInt8PtrTy(), IntptrTy));
294 IRB.getInt8PtrTy(), IntptrTy, nullptr));
295295 MemsetFn = checkSanitizerInterfaceFunction(
296296 M.getOrInsertFunction("memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
297 IRB.getInt32Ty(), IntptrTy));
297 IRB.getInt32Ty(), IntptrTy, nullptr));
298298 }
299299
300300 bool EfficiencySanitizer::shouldIgnoreStructType(StructType *StructTy) {
532532 IRBuilder<> IRB_Dtor(EsanDtorFunction->getEntryBlock().getTerminator());
533533 Function *EsanExit = checkSanitizerInterfaceFunction(
534534 M.getOrInsertFunction(EsanExitName, IRB_Dtor.getVoidTy(),
535 Int8PtrTy));
535 Int8PtrTy, nullptr));
536536 EsanExit->setLinkage(Function::ExternalLinkage);
537537 IRB_Dtor.CreateCall(EsanExit, {ToolInfoArg});
538538 appendToGlobalDtors(M, EsanDtorFunction, EsanCtorAndDtorPriority);
424424 // which is not yet implemented.
425425 StringRef WarningFnName = Recover ? "__msan_warning"
426426 : "__msan_warning_noreturn";
427 WarningFn = M.getOrInsertFunction(WarningFnName, IRB.getVoidTy());
427 WarningFn = M.getOrInsertFunction(WarningFnName, IRB.getVoidTy(), nullptr);
428428
429429 for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes;
430430 AccessSizeIndex++) {
432432 std::string FunctionName = "__msan_maybe_warning_" + itostr(AccessSize);
433433 MaybeWarningFn[AccessSizeIndex] = M.getOrInsertFunction(
434434 FunctionName, IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8),
435 IRB.getInt32Ty());
435 IRB.getInt32Ty(), nullptr);
436436
437437 FunctionName = "__msan_maybe_store_origin_" + itostr(AccessSize);
438438 MaybeStoreOriginFn[AccessSizeIndex] = M.getOrInsertFunction(
439439 FunctionName, IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8),
440 IRB.getInt8PtrTy(), IRB.getInt32Ty());
440 IRB.getInt8PtrTy(), IRB.getInt32Ty(), nullptr);
441441 }
442442
443443 MsanSetAllocaOrigin4Fn = M.getOrInsertFunction(
444444 "__msan_set_alloca_origin4", IRB.getVoidTy(), IRB.getInt8PtrTy(), IntptrTy,
445 IRB.getInt8PtrTy(), IntptrTy);
445 IRB.getInt8PtrTy(), IntptrTy, nullptr);
446446 MsanPoisonStackFn =
447447 M.getOrInsertFunction("__msan_poison_stack", IRB.getVoidTy(),
448 IRB.getInt8PtrTy(), IntptrTy);
448 IRB.getInt8PtrTy(), IntptrTy, nullptr);
449449 MsanChainOriginFn = M.getOrInsertFunction(
450 "__msan_chain_origin", IRB.getInt32Ty(), IRB.getInt32Ty());
450 "__msan_chain_origin", IRB.getInt32Ty(), IRB.getInt32Ty(), nullptr);
451451 MemmoveFn = M.getOrInsertFunction(
452452 "__msan_memmove", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
453 IRB.getInt8PtrTy(), IntptrTy);
453 IRB.getInt8PtrTy(), IntptrTy, nullptr);
454454 MemcpyFn = M.getOrInsertFunction(
455455 "__msan_memcpy", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
456 IntptrTy);
456 IntptrTy, nullptr);
457457 MemsetFn = M.getOrInsertFunction(
458458 "__msan_memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt32Ty(),
459 IntptrTy);
459 IntptrTy, nullptr);
460460
461461 // Create globals.
462462 RetvalTLS = new GlobalVariable(
261261 Int32Ty = IRB.getInt32Ty();
262262
263263 SanCovFunction = checkSanitizerInterfaceFunction(
264 M.getOrInsertFunction(SanCovName, VoidTy, Int32PtrTy));
264 M.getOrInsertFunction(SanCovName, VoidTy, Int32PtrTy, nullptr));
265265 SanCovWithCheckFunction = checkSanitizerInterfaceFunction(
266 M.getOrInsertFunction(SanCovWithCheckName, VoidTy, Int32PtrTy));
266 M.getOrInsertFunction(SanCovWithCheckName, VoidTy, Int32PtrTy, nullptr));
267267 SanCovTracePCIndir = checkSanitizerInterfaceFunction(
268 M.getOrInsertFunction(SanCovTracePCIndirName, VoidTy, IntptrTy));
268 M.getOrInsertFunction(SanCovTracePCIndirName, VoidTy, IntptrTy, nullptr));
269269 SanCovIndirCallFunction =
270270 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
271 SanCovIndirCallName, VoidTy, IntptrTy, IntptrTy));
271 SanCovIndirCallName, VoidTy, IntptrTy, IntptrTy, nullptr));
272272 SanCovTraceCmpFunction[0] =
273273 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
274 SanCovTraceCmp1, VoidTy, IRB.getInt8Ty(), IRB.getInt8Ty()));
274 SanCovTraceCmp1, VoidTy, IRB.getInt8Ty(), IRB.getInt8Ty(), nullptr));
275275 SanCovTraceCmpFunction[1] = checkSanitizerInterfaceFunction(
276276 M.getOrInsertFunction(SanCovTraceCmp2, VoidTy, IRB.getInt16Ty(),
277 IRB.getInt16Ty()));
277 IRB.getInt16Ty(), nullptr));
278278 SanCovTraceCmpFunction[2] = checkSanitizerInterfaceFunction(
279279 M.getOrInsertFunction(SanCovTraceCmp4, VoidTy, IRB.getInt32Ty(),
280 IRB.getInt32Ty()));
280 IRB.getInt32Ty(), nullptr));
281281 SanCovTraceCmpFunction[3] =
282282 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
283 SanCovTraceCmp8, VoidTy, Int64Ty, Int64Ty));
283 SanCovTraceCmp8, VoidTy, Int64Ty, Int64Ty, nullptr));
284284
285285 SanCovTraceDivFunction[0] =
286286 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
287 SanCovTraceDiv4, VoidTy, IRB.getInt32Ty()));
287 SanCovTraceDiv4, VoidTy, IRB.getInt32Ty(), nullptr));
288288 SanCovTraceDivFunction[1] =
289289 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
290 SanCovTraceDiv8, VoidTy, Int64Ty));
290 SanCovTraceDiv8, VoidTy, Int64Ty, nullptr));
291291 SanCovTraceGepFunction =
292292 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
293 SanCovTraceGep, VoidTy, IntptrTy));
293 SanCovTraceGep, VoidTy, IntptrTy, nullptr));
294294 SanCovTraceSwitchFunction =
295295 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
296 SanCovTraceSwitchName, VoidTy, Int64Ty, Int64PtrTy));
296 SanCovTraceSwitchName, VoidTy, Int64Ty, Int64PtrTy, nullptr));
297297
298298 // We insert an empty inline asm after cov callbacks to avoid callback merge.
299299 EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
301301 /*hasSideEffects=*/true);
302302
303303 SanCovTracePC = checkSanitizerInterfaceFunction(
304 M.getOrInsertFunction(SanCovTracePCName, VoidTy));
304 M.getOrInsertFunction(SanCovTracePCName, VoidTy, nullptr));
305305 SanCovTracePCGuard = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
306 SanCovTracePCGuardName, VoidTy, Int32PtrTy));
306 SanCovTracePCGuardName, VoidTy, Int32PtrTy, nullptr));
307307 SanCovTraceEnter = checkSanitizerInterfaceFunction(
308 M.getOrInsertFunction(SanCovTraceEnterName, VoidTy, Int32PtrTy));
308 M.getOrInsertFunction(SanCovTraceEnterName, VoidTy, Int32PtrTy, nullptr));
309309 SanCovTraceBB = checkSanitizerInterfaceFunction(
310 M.getOrInsertFunction(SanCovTraceBBName, VoidTy, Int32PtrTy));
310 M.getOrInsertFunction(SanCovTraceBBName, VoidTy, Int32PtrTy, nullptr));
311311
312312 // At this point we create a dummy array of guards because we don't
313313 // know how many elements we will need.
159159 Attribute::NoUnwind);
160160 // Initialize the callbacks.
161161 TsanFuncEntry = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
162 "__tsan_func_entry", Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
162 "__tsan_func_entry", Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr));
163163 TsanFuncExit = checkSanitizerInterfaceFunction(
164 M.getOrInsertFunction("__tsan_func_exit", Attr, IRB.getVoidTy()));
164 M.getOrInsertFunction("__tsan_func_exit", Attr, IRB.getVoidTy(), nullptr));
165165 TsanIgnoreBegin = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
166 "__tsan_ignore_thread_begin", Attr, IRB.getVoidTy()));
166 "__tsan_ignore_thread_begin", Attr, IRB.getVoidTy(), nullptr));
167167 TsanIgnoreEnd = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
168 "__tsan_ignore_thread_end", Attr, IRB.getVoidTy()));
168 "__tsan_ignore_thread_end", Attr, IRB.getVoidTy(), nullptr));
169169 OrdTy = IRB.getInt32Ty();
170170 for (size_t i = 0; i < kNumberOfAccessSizes; ++i) {
171171 const unsigned ByteSize = 1U << i;
174174 std::string BitSizeStr = utostr(BitSize);
175175 SmallString<32> ReadName("__tsan_read" + ByteSizeStr);
176176 TsanRead[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
177 ReadName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
177 ReadName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr));
178178
179179 SmallString<32> WriteName("__tsan_write" + ByteSizeStr);
180180 TsanWrite[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
181 WriteName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
181 WriteName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr));
182182
183183 SmallString<64> UnalignedReadName("__tsan_unaligned_read" + ByteSizeStr);
184184 TsanUnalignedRead[i] =
185185 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
186 UnalignedReadName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
186 UnalignedReadName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr));
187187
188188 SmallString<64> UnalignedWriteName("__tsan_unaligned_write" + ByteSizeStr);
189189 TsanUnalignedWrite[i] =
190190 checkSanitizerInterfaceFunction(M.getOrInsertFunction(
191 UnalignedWriteName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
191 UnalignedWriteName, Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr));
192192
193193 Type *Ty = Type::getIntNTy(M.getContext(), BitSize);
194194 Type *PtrTy = Ty->getPointerTo();
195195 SmallString<32> AtomicLoadName("__tsan_atomic" + BitSizeStr + "_load");
196196 TsanAtomicLoad[i] = checkSanitizerInterfaceFunction(
197 M.getOrInsertFunction(AtomicLoadName, Attr, Ty, PtrTy, OrdTy));
197 M.getOrInsertFunction(AtomicLoadName, Attr, Ty, PtrTy, OrdTy, nullptr));
198198
199199 SmallString<32> AtomicStoreName("__tsan_atomic" + BitSizeStr + "_store");
200200 TsanAtomicStore[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
201 AtomicStoreName, Attr, IRB.getVoidTy(), PtrTy, Ty, OrdTy));
201 AtomicStoreName, Attr, IRB.getVoidTy(), PtrTy, Ty, OrdTy, nullptr));
202202
203203 for (int op = AtomicRMWInst::FIRST_BINOP;
204204 op <= AtomicRMWInst::LAST_BINOP; ++op) {
222222 continue;
223223 SmallString<32> RMWName("__tsan_atomic" + itostr(BitSize) + NamePart);
224224 TsanAtomicRMW[op][i] = checkSanitizerInterfaceFunction(
225 M.getOrInsertFunction(RMWName, Attr, Ty, PtrTy, Ty, OrdTy));
225 M.getOrInsertFunction(RMWName, Attr, Ty, PtrTy, Ty, OrdTy, nullptr));
226226 }
227227
228228 SmallString<32> AtomicCASName("__tsan_atomic" + BitSizeStr +
229229 "_compare_exchange_val");
230230 TsanAtomicCAS[i] = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
231 AtomicCASName, Attr, Ty, PtrTy, Ty, Ty, OrdTy, OrdTy));
231 AtomicCASName, Attr, Ty, PtrTy, Ty, Ty, OrdTy, OrdTy, nullptr));
232232 }
233233 TsanVptrUpdate = checkSanitizerInterfaceFunction(
234234 M.getOrInsertFunction("__tsan_vptr_update", Attr, IRB.getVoidTy(),
235 IRB.getInt8PtrTy(), IRB.getInt8PtrTy()));
235 IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), nullptr));
236236 TsanVptrLoad = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
237 "__tsan_vptr_read", Attr, IRB.getVoidTy(), IRB.getInt8PtrTy()));
237 "__tsan_vptr_read", Attr, IRB.getVoidTy(), IRB.getInt8PtrTy(), nullptr));
238238 TsanAtomicThreadFence = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
239 "__tsan_atomic_thread_fence", Attr, IRB.getVoidTy(), OrdTy));
239 "__tsan_atomic_thread_fence", Attr, IRB.getVoidTy(), OrdTy, nullptr));
240240 TsanAtomicSignalFence = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
241 "__tsan_atomic_signal_fence", Attr, IRB.getVoidTy(), OrdTy));
241 "__tsan_atomic_signal_fence", Attr, IRB.getVoidTy(), OrdTy, nullptr));
242242
243243 MemmoveFn = checkSanitizerInterfaceFunction(
244244 M.getOrInsertFunction("memmove", Attr, IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
245 IRB.getInt8PtrTy(), IntptrTy));
245 IRB.getInt8PtrTy(), IntptrTy, nullptr));
246246 MemcpyFn = checkSanitizerInterfaceFunction(
247247 M.getOrInsertFunction("memcpy", Attr, IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
248 IRB.getInt8PtrTy(), IntptrTy));
248 IRB.getInt8PtrTy(), IntptrTy, nullptr));
249249 MemsetFn = checkSanitizerInterfaceFunction(
250250 M.getOrInsertFunction("memset", Attr, IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
251 IRB.getInt32Ty(), IntptrTy));
251 IRB.getInt32Ty(), IntptrTy, nullptr));
252252 }
253253
254254 bool ThreadSanitizer::doInitialization(Module &M) {
822822 Module *M = TheStore->getModule();
823823 Value *MSP =
824824 M->getOrInsertFunction("memset_pattern16", Builder.getVoidTy(),
825 Int8PtrTy, Int8PtrTy, IntPtr);
825 Int8PtrTy, Int8PtrTy, IntPtr, (void *)nullptr);
826826 inferLibFuncAttributes(*M->getFunction("memset_pattern16"), *TLI);
827827
828828 // Otherwise we should form a memset_pattern16. PatternValue is known to be
722722 Module *M = B.GetInsertBlock()->getModule();
723723 LLVMContext &Context = B.GetInsertBlock()->getContext();
724724 Constant *StrLen = M->getOrInsertFunction("strlen", DL.getIntPtrType(Context),
725 B.getInt8PtrTy());
725 B.getInt8PtrTy(), nullptr);
726726 inferLibFuncAttributes(*M->getFunction("strlen"), *TLI);
727727 CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), "strlen");
728728 if (const Function *F = dyn_cast(StrLen->stripPointerCasts()))
740740 Type *I8Ptr = B.getInt8PtrTy();
741741 Type *I32Ty = B.getInt32Ty();
742742 Constant *StrChr =
743 M->getOrInsertFunction("strchr", I8Ptr, I8Ptr, I32Ty);
743 M->getOrInsertFunction("strchr", I8Ptr, I8Ptr, I32Ty, nullptr);
744744 inferLibFuncAttributes(*M->getFunction("strchr"), *TLI);
745745 CallInst *CI = B.CreateCall(
746746 StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, "strchr");
758758 LLVMContext &Context = B.GetInsertBlock()->getContext();
759759 Value *StrNCmp = M->getOrInsertFunction("strncmp", B.getInt32Ty(),
760760 B.getInt8PtrTy(), B.getInt8PtrTy(),
761 DL.getIntPtrType(Context));
761 DL.getIntPtrType(Context), nullptr);
762762 inferLibFuncAttributes(*M->getFunction("strncmp"), *TLI);
763763 CallInst *CI = B.CreateCall(
764764 StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "strncmp");
776776
777777 Module *M = B.GetInsertBlock()->getModule();
778778 Type *I8Ptr = B.getInt8PtrTy();
779 Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr);
779 Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr, nullptr);
780780 inferLibFuncAttributes(*M->getFunction(Name), *TLI);
781781 CallInst *CI =
782782 B.CreateCall(StrCpy, {castToCStr(Dst, B), castToCStr(Src, B)}, Name);
793793 Module *M = B.GetInsertBlock()->getModule();
794794 Type *I8Ptr = B.getInt8PtrTy();
795795 Value *StrNCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr,
796 Len->getType());
796 Len->getType(), nullptr);
797797 inferLibFuncAttributes(*M->getFunction(Name), *TLI);
798798 CallInst *CI = B.CreateCall(
799799 StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, "strncpy");
816816 Value *MemCpy = M->getOrInsertFunction(
817817 "__memcpy_chk", AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(),
818818 B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context),
819 DL.getIntPtrType(Context));
819 DL.getIntPtrType(Context), nullptr);
820820 Dst = castToCStr(Dst, B);
821821 Src = castToCStr(Src, B);
822822 CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
834834 LLVMContext &Context = B.GetInsertBlock()->getContext();
835835 Value *MemChr = M->getOrInsertFunction("memchr", B.getInt8PtrTy(),
836836 B.getInt8PtrTy(), B.getInt32Ty(),
837 DL.getIntPtrType(Context));
837 DL.getIntPtrType(Context), nullptr);
838838 inferLibFuncAttributes(*M->getFunction("memchr"), *TLI);
839839 CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, "memchr");
840840
853853 LLVMContext &Context = B.GetInsertBlock()->getContext();
854854 Value *MemCmp = M->getOrInsertFunction("memcmp", B.getInt32Ty(),
855855 B.getInt8PtrTy(), B.getInt8PtrTy(),
856 DL.getIntPtrType(Context));
856 DL.getIntPtrType(Context), nullptr);
857857 inferLibFuncAttributes(*M->getFunction("memcmp"), *TLI);
858858 CallInst *CI = B.CreateCall(
859859 MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "memcmp");
886886
887887 Module *M = B.GetInsertBlock()->getModule();
888888 Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
889 Op->getType());
889 Op->getType(), nullptr);
890890 CallInst *CI = B.CreateCall(Callee, Op, Name);
891891 CI->setAttributes(Attrs);
892892 if (const Function *F = dyn_cast(Callee->stripPointerCasts()))
902902
903903 Module *M = B.GetInsertBlock()->getModule();
904904 Value *Callee = M->getOrInsertFunction(Name, Op1->getType(), Op1->getType(),
905 Op2->getType());
905 Op2->getType(), nullptr);
906906 CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name);
907907 CI->setAttributes(Attrs);
908908 if (const Function *F = dyn_cast(Callee->stripPointerCasts()))
917917 return nullptr;
918918
919919 Module *M = B.GetInsertBlock()->getModule();
920 Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(), B.getInt32Ty());
920 Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(),
921 B.getInt32Ty(), nullptr);
921922 inferLibFuncAttributes(*M->getFunction("putchar"), *TLI);
922923 CallInst *CI = B.CreateCall(PutChar,
923924 B.CreateIntCast(Char,
938939
939940 Module *M = B.GetInsertBlock()->getModule();
940941 Value *PutS =
941 M->getOrInsertFunction("puts", B.getInt32Ty(), B.getInt8PtrTy());
942 M->getOrInsertFunction("puts", B.getInt32Ty(), B.getInt8PtrTy(), nullptr);
942943 inferLibFuncAttributes(*M->getFunction("puts"), *TLI);
943944 CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), "puts");
944945 if (const Function *F = dyn_cast(PutS->stripPointerCasts()))
953954
954955 Module *M = B.GetInsertBlock()->getModule();
955956 Constant *F = M->getOrInsertFunction("fputc", B.getInt32Ty(), B.getInt32Ty(),
956 File->getType());
957 File->getType(), nullptr);
957958 if (File->getType()->isPointerTy())
958959 inferLibFuncAttributes(*M->getFunction("fputc"), *TLI);
959960 Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
973974 Module *M = B.GetInsertBlock()->getModule();
974975 StringRef FPutsName = TLI->getName(LibFunc_fputs);
975976 Constant *F = M->getOrInsertFunction(
976 FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType());
977 FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType(), nullptr);
977978 if (File->getType()->isPointerTy())
978979 inferLibFuncAttributes(*M->getFunction(FPutsName), *TLI);
979980 CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, "fputs");
993994 StringRef FWriteName = TLI->getName(LibFunc_fwrite);
994995 Constant *F = M->getOrInsertFunction(
995996 FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
996 DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
997
997 DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType(),
998 nullptr);
998999 if (File->getType()->isPointerTy())
9991000 inferLibFuncAttributes(*M->getFunction(FWriteName), *TLI);
10001001 CallInst *CI =
818818 const DataLayout &DL = M->getDataLayout();
819819 IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext()));
820820 Value *Calloc = M->getOrInsertFunction("calloc", Attrs, B.getInt8PtrTy(),
821 PtrType, PtrType);
821 PtrType, PtrType, nullptr);
822822 CallInst *CI = B.CreateCall(Calloc, { Num, Size }, "calloc");
823823
824824 if (const auto *F = dyn_cast(Calloc->stripPointerCasts()))
12181218 Module *M = CI->getModule();
12191219 Value *NewCallee =
12201220 M->getOrInsertFunction(TLI->getName(LdExp), Op->getType(),
1221 Op->getType(), B.getInt32Ty());
1221 Op->getType(), B.getInt32Ty(), nullptr);
12221222 CallInst *CI = B.CreateCall(NewCallee, {One, LdExpArg});
12231223 if (const Function *F = dyn_cast(Callee->stripPointerCasts()))
12241224 CI->setCallingConv(F->getCallingConv());
14421442
14431443 Module *M = OrigCallee->getParent();
14441444 Value *Callee = M->getOrInsertFunction(Name, OrigCallee->getAttributes(),
1445 ResTy, ArgTy);
1445 ResTy, ArgTy, nullptr);
14461446
14471447 if (Instruction *ArgInst = dyn_cast(Arg)) {
14481448 // If the argument is an instruction, it must dominate all uses so put our
605605 // If the program doesn't explicitly call exit, we will need the Exit
606606 // function later on to make an explicit call, so get the function now.
607607 Constant *Exit = Mod->getOrInsertFunction("exit", Type::getVoidTy(Context),
608 Type::getInt32Ty(Context));
608 Type::getInt32Ty(Context),
609 nullptr);
609610
610611 // Run static constructors.
611612 if (!ForceInterpreter) {