44#define DEBUG_TYPE "sancov"
73 "sancov.module_ctor_trace_pc_guard";
75 "sancov.module_ctor_8bit_counters";
101 switch (LegacyCoverageLevel) {
128 Options.TraceCmp |= Opts.sanitizer_coverage_trace_compares;
129 Options.TraceDiv |= Opts.sanitizer_coverage_trace_divs;
130 Options.TraceGep |= Opts.sanitizer_coverage_trace_geps;
131 Options.TracePC |= Opts.sanitizer_coverage_trace_pc;
132 Options.TracePCEntryExit |= Opts.sanitizer_coverage_trace_pc_entry_exit;
133 Options.TracePCGuard |= Opts.sanitizer_coverage_trace_pc_guard;
134 Options.Inline8bitCounters |= Opts.sanitizer_coverage_inline_8bit_counters;
135 Options.InlineBoolFlag |= Opts.sanitizer_coverage_inline_bool_flag;
136 Options.PCTable |= Opts.sanitizer_coverage_pc_table;
137 Options.NoPrune |= !Opts.sanitizer_coverage_prune_blocks;
138 Options.StackDepth |= Opts.sanitizer_coverage_stack_depth;
139 Options.StackDepthCallbackMin =
140 std::max(
Options.StackDepthCallbackMin,
141 Opts.sanitizer_coverage_stack_depth_callback_min);
142 Options.TraceLoads |= Opts.sanitizer_coverage_trace_loads;
143 Options.TraceStores |= Opts.sanitizer_coverage_trace_stores;
144 Options.GatedCallbacks |= Opts.sanitizer_coverage_gated_trace_callbacks;
149 Options.CollectControlFlow |= Opts.sanitizer_coverage_control_flow;
153class ModuleSanitizerCoverage {
156 using PostDomTreeCallback =
159 ModuleSanitizerCoverage(
const InstrumentationOptions &Opts,
Module &M,
160 DomTreeCallback DTCallback,
161 PostDomTreeCallback PDTCallback,
165 : Opts(Opts), M(M), DTCallback(DTCallback), PDTCallback(PDTCallback),
168 bool instrumentModule();
171 void createFunctionControlFlow(
Function &
F);
173 void InjectCoverageForIndirectCalls(
Function &
F,
176 Value *&FunctionGateCmp);
186 Value *&FunctionGateCmp);
188 Value *&FunctionGateCmp,
bool IsLeafFunc);
189 GlobalVariable *CreateFunctionLocalArrayInSection(
size_t NumElements,
191 const char *Section);
198 Value *&FunctionGateCmp,
bool IsLeafFunc);
202 Function *CreateInitCallsForSections(
Module &M,
const char *CtorName,
203 const char *InitFunctionName,
Type *Ty,
204 const char *Section);
205 std::pair<Value *, Value *> CreateSecStartEnd(
Module &M,
const char *Section,
209 std::string getSectionStart(
const std::string &Section)
const;
210 std::string getSectionEnd(
const std::string &Section)
const;
212 const InstrumentationOptions &Opts;
214 DomTreeCallback DTCallback;
215 PostDomTreeCallback PDTCallback;
221 std::array<FunctionCallee, 4> SanCovTraceCmpFunction;
222 std::array<FunctionCallee, 4> SanCovTraceConstCmpFunction;
223 std::array<FunctionCallee, 5> SanCovLoadFunction;
224 std::array<FunctionCallee, 5> SanCovStoreFunction;
225 std::array<FunctionCallee, 2> SanCovTraceDivFunction;
230 Type *PtrTy, *IntptrTy, *Int64Ty, *Int32Ty, *Int16Ty, *Int8Ty, *Int1Ty;
256 const std::vector<std::string> &AllowlistFiles,
257 const std::vector<std::string> &BlocklistFiles)
259 VFS(VFS ?
std::
move(VFS) :
vfs::getRealFileSystem()) {
260 if (AllowlistFiles.size() > 0)
262 if (BlocklistFiles.size() > 0)
276 ModuleSanitizerCoverage ModuleSancov(Opts, M, DTCallback, PDTCallback,
277 overrideFromCL(Opts, Options),
278 Allowlist.get(), Blocklist.get());
279 if (!ModuleSancov.instrumentModule())
290std::pair<Value *, Value *>
291ModuleSanitizerCoverage::CreateSecStartEnd(
Module &M,
const char *Section,
301 getSectionStart(Section));
304 getSectionEnd(Section));
306 if (!TargetTriple.isOSBinFormatCOFF())
307 return std::make_pair(SecStart, SecEnd);
312 SecStart, ConstantInt::get(IntptrTy,
sizeof(uint64_t)));
313 return std::make_pair(
GEP, SecEnd);
316Function *ModuleSanitizerCoverage::CreateInitCallsForSections(
317 Module &M,
const char *CtorName,
const char *InitFunctionName,
Type *Ty,
318 const char *Section) {
319 if (Opts.sanitizer_coverage_drop_ctors)
321 auto SecStartEnd = CreateSecStartEnd(M, Section, Ty);
322 auto SecStart = SecStartEnd.first;
323 auto SecEnd = SecStartEnd.second;
326 M, CtorName, InitFunctionName, {PtrTy, PtrTy}, {SecStart, SecEnd});
329 if (TargetTriple.supportsCOMDAT()) {
331 CtorFunc->
setComdat(
M.getOrInsertComdat(CtorName));
337 if (TargetTriple.isOSBinFormatCOFF()) {
349bool ModuleSanitizerCoverage::instrumentModule() {
353 !Allowlist->inSection(
"coverage",
"src",
M.getSourceFileName()))
356 Blocklist->inSection(
"coverage",
"src",
M.getSourceFileName()))
358 C = &(
M.getContext());
359 DL = &
M.getDataLayout();
361 TargetTriple =
M.getTargetTriple();
362 FunctionGuardArray =
nullptr;
363 Function8bitCounterArray =
nullptr;
364 FunctionBoolArray =
nullptr;
365 FunctionPCsArray =
nullptr;
366 FunctionCFsArray =
nullptr;
371 Int64Ty = IRB.getInt64Ty();
372 Int32Ty = IRB.getInt32Ty();
373 Int16Ty = IRB.getInt16Ty();
374 Int8Ty = IRB.getInt8Ty();
375 Int1Ty = IRB.getInt1Ty();
381 AttributeList SanCovTraceCmpZeroExtAL;
382 SanCovTraceCmpZeroExtAL =
383 SanCovTraceCmpZeroExtAL.addParamAttribute(*
C, 0, Attribute::ZExt);
384 SanCovTraceCmpZeroExtAL =
385 SanCovTraceCmpZeroExtAL.addParamAttribute(*
C, 1, Attribute::ZExt);
387 SanCovTraceCmpFunction[0] =
389 IRB.getInt8Ty(), IRB.getInt8Ty());
390 SanCovTraceCmpFunction[1] =
392 IRB.getInt16Ty(), IRB.getInt16Ty());
393 SanCovTraceCmpFunction[2] =
395 IRB.getInt32Ty(), IRB.getInt32Ty());
396 SanCovTraceCmpFunction[3] =
399 SanCovTraceConstCmpFunction[0] =
M.getOrInsertFunction(
401 SanCovTraceConstCmpFunction[1] =
M.getOrInsertFunction(
403 SanCovTraceConstCmpFunction[2] =
M.getOrInsertFunction(
405 SanCovTraceConstCmpFunction[3] =
409 SanCovLoadFunction[0] =
M.getOrInsertFunction(
SanCovLoad1, VoidTy, PtrTy);
410 SanCovLoadFunction[1] =
M.getOrInsertFunction(
SanCovLoad2, VoidTy, PtrTy);
411 SanCovLoadFunction[2] =
M.getOrInsertFunction(
SanCovLoad4, VoidTy, PtrTy);
412 SanCovLoadFunction[3] =
M.getOrInsertFunction(
SanCovLoad8, VoidTy, PtrTy);
413 SanCovLoadFunction[4] =
M.getOrInsertFunction(
SanCovLoad16, VoidTy, PtrTy);
415 SanCovStoreFunction[0] =
M.getOrInsertFunction(
SanCovStore1, VoidTy, PtrTy);
416 SanCovStoreFunction[1] =
M.getOrInsertFunction(
SanCovStore2, VoidTy, PtrTy);
417 SanCovStoreFunction[2] =
M.getOrInsertFunction(
SanCovStore4, VoidTy, PtrTy);
418 SanCovStoreFunction[3] =
M.getOrInsertFunction(
SanCovStore8, VoidTy, PtrTy);
419 SanCovStoreFunction[4] =
M.getOrInsertFunction(
SanCovStore16, VoidTy, PtrTy);
423 AL =
AL.addParamAttribute(*
C, 0, Attribute::ZExt);
424 SanCovTraceDivFunction[0] =
427 SanCovTraceDivFunction[1] =
429 SanCovTraceGepFunction =
431 SanCovTraceSwitchFunction =
435 if (SanCovLowestStack->getValueType() != IntptrTy) {
437 "' should not be declared by the user");
440 SanCovLowestStack->setThreadLocalMode(
442 if (
Options.StackDepth && !SanCovLowestStack->isDeclaration())
447 C->emitError(
"'sanitizer-coverage-gated-trace-callbacks' is only "
448 "supported with trace-pc-guard or trace-cmp");
454 SanCovCallbackGate->setSection(
468 SanCovStackDepthCallback =
472 instrumentFunction(
F);
476 if (FunctionGuardArray)
480 if (Function8bitCounterArray)
484 if (FunctionBoolArray) {
494 IRBCtor.CreateCall(InitFunction, {SecStartEnd.first, SecStartEnd.second});
497 if (Ctor &&
Options.CollectControlFlow) {
502 IRBCtor.CreateCall(InitFunction, {SecStartEnd.first, SecStartEnd.second});
548 if (
Options.NoPrune || &
F.getEntryBlock() == BB)
552 &
F.getEntryBlock() != BB)
591void ModuleSanitizerCoverage::instrumentFunction(
Function &
F) {
594 if (
F.getName().contains(
".module_ctor"))
596 if (
F.getName().starts_with(
"__sanitizer_"))
603 if (
F.getName() ==
"__local_stdio_printf_options" ||
604 F.getName() ==
"__local_stdio_scanf_options")
611 if (
F.hasPersonalityFn() &&
614 if (Allowlist && !Allowlist->inSection(
"coverage",
"fun",
F.getName()))
616 if (Blocklist && Blocklist->inSection(
"coverage",
"fun",
F.getName()))
619 if (
F.hasFnAttribute(Attribute::Naked))
621 if (
F.hasFnAttribute(Attribute::NoSanitizeCoverage))
623 if (
F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation))
640 bool IsLeafFunc =
true;
645 for (
auto &Inst : BB) {
660 if (BO->getOpcode() == Instruction::SDiv ||
661 BO->getOpcode() == Instruction::UDiv)
679 if (
Options.CollectControlFlow)
680 createFunctionControlFlow(
F);
682 Value *FunctionGateCmp =
nullptr;
683 InjectCoverage(
F, BlocksToInstrument, FunctionGateCmp, IsLeafFunc);
684 InjectCoverageForIndirectCalls(
F, IndirCalls);
685 InjectTraceForCmp(
F, CmpTraceTargets, FunctionGateCmp);
686 InjectTraceForSwitch(
F, SwitchTraceTargets, FunctionGateCmp);
687 InjectTraceForDiv(
F, DivTraceTargets);
688 InjectTraceForGep(
F, GepTraceTargets);
689 InjectTraceForLoadsAndStores(
F, Loads, Stores);
693 addFuncletBundles(
F);
696 InjectTraceForExits(
F);
703 RuntimeCalls.push_back(CI);
713void ModuleSanitizerCoverage::addFuncletBundles(
Function &
F) {
714 if (RuntimeCalls.empty())
717 if (!
F.hasPersonalityFn() ||
728 if (Colors.
size() != 1) {
729 F.getContext().emitError(
"Instruction's BasicBlock is not monochromatic");
745GlobalVariable *ModuleSanitizerCoverage::CreateFunctionLocalArrayInSection(
746 size_t NumElements,
Function &
F,
Type *Ty,
const char *Section) {
758 if (TargetTriple.supportsCOMDAT() &&
759 (
F.hasComdat() || TargetTriple.isOSBinFormatELF() ||
760 !
F.isInterposable(
false)))
764 Array->setAlignment(
Align(
DL->getTypeStoreSize(Ty).getFixedValue()));
768 if (
Array->hasComdat())
769 GlobalsToAppendToCompilerUsed.push_back(Array);
771 GlobalsToAppendToUsed.push_back(Array);
777ModuleSanitizerCoverage::CreatePCArray(
Function &
F,
779 size_t N = AllBlocks.
size();
782 IRBuilder<> IRB(&*
F.getEntryBlock().getFirstInsertionPt());
783 for (
size_t i = 0; i <
N; i++) {
784 if (&
F.getEntryBlock() == AllBlocks[i]) {
796 PCArray->setInitializer(
798 PCArray->setConstant(
true);
803void ModuleSanitizerCoverage::CreateFunctionLocalArrays(
806 FunctionGuardArray = CreateFunctionLocalArrayInSection(
809 if (
Options.Inline8bitCounters)
810 Function8bitCounterArray = CreateFunctionLocalArrayInSection(
813 FunctionBoolArray = CreateFunctionLocalArrayInSection(
817 FunctionPCsArray = CreatePCArray(
F, AllBlocks);
820Value *ModuleSanitizerCoverage::CreateFunctionLocalGateCmp(
IRBuilder<> &IRB) {
822 Load->setNoSanitizeMetadata();
824 Cmp->setName(
"sancov gate cmp");
829 Value *&FunctionGateCmp,
831 if (!FunctionGateCmp) {
837 FunctionGateCmp = CreateFunctionLocalGateCmp(EntryIRB);
846bool ModuleSanitizerCoverage::InjectCoverage(
Function &
F,
848 Value *&FunctionGateCmp,
850 if (AllBlocks.
empty())
852 CreateFunctionLocalArrays(
F, AllBlocks);
853 for (
size_t i = 0,
N = AllBlocks.
size(); i <
N; i++)
854 InjectCoverageAtBlock(
F, *AllBlocks[i], i, FunctionGateCmp, IsLeafFunc);
866void ModuleSanitizerCoverage::InjectCoverageForIndirectCalls(
868 if (IndirCalls.
empty())
872 for (
auto *
I : IndirCalls) {
878 createRuntimeCall(IRB, SanCovTracePCIndir,
887void ModuleSanitizerCoverage::InjectTraceForSwitch(
889 Value *&FunctionGateCmp) {
890 for (
auto *
I : SwitchTraceTargets) {
895 if (
Cond->getType()->getScalarSizeInBits() >
896 Int64Ty->getScalarSizeInBits())
898 Initializers.
push_back(ConstantInt::get(Int64Ty,
SI->getNumCases()));
900 ConstantInt::get(Int64Ty,
Cond->getType()->getScalarSizeInBits()));
901 if (
Cond->getType()->getScalarSizeInBits() <
902 Int64Ty->getScalarSizeInBits())
904 for (
auto It :
SI->cases()) {
906 if (
C->getType()->getScalarSizeInBits() < 64)
907 C = ConstantInt::get(
C->getContext(),
C->getValue().zext(64));
919 "__sancov_gen_cov_switch_values");
921 auto GateBranch = CreateGateBranch(
F, FunctionGateCmp,
I);
923 createRuntimeCall(GateIRB, SanCovTraceSwitchFunction, {
Cond, GV});
925 createRuntimeCall(IRB, SanCovTraceSwitchFunction, {
Cond, GV});
931void ModuleSanitizerCoverage::InjectTraceForDiv(
933 for (
auto *BO : DivTraceTargets) {
935 Value *A1 = BO->getOperand(1);
945 createRuntimeCall(IRB, SanCovTraceDivFunction[CallbackIdx],
950void ModuleSanitizerCoverage::InjectTraceForGep(
952 for (
auto *
GEP : GepTraceTargets) {
954 for (
Use &Idx :
GEP->indices())
956 createRuntimeCall(IRB, SanCovTraceGepFunction,
961void ModuleSanitizerCoverage::InjectTraceForLoadsAndStores(
963 auto CallbackIdx = [&](
Type *ElementTy) ->
int {
972 for (
auto *LI : Loads) {
974 auto Ptr = LI->getPointerOperand();
975 int Idx = CallbackIdx(LI->getType());
978 createRuntimeCall(IRB, SanCovLoadFunction[Idx], Ptr);
980 for (
auto *
SI : Stores) {
982 auto Ptr =
SI->getPointerOperand();
983 int Idx = CallbackIdx(
SI->getValueOperand()->getType());
986 createRuntimeCall(IRB, SanCovStoreFunction[Idx], Ptr);
990void ModuleSanitizerCoverage::InjectTraceForExits(
Function &
F) {
994 AtExit->CreateCall(SanCovTracePCExit, {})
999void ModuleSanitizerCoverage::InjectTraceForCmp(
1001 Value *&FunctionGateCmp) {
1002 for (
auto *
I : CmpTraceTargets) {
1005 Value *A0 = ICMP->getOperand(0);
1006 Value *A1 = ICMP->getOperand(1);
1010 int CallbackIdx =
TypeSize == 8 ? 0
1015 if (CallbackIdx < 0)
1018 auto CallbackFunc = SanCovTraceCmpFunction[CallbackIdx];
1022 if (FirstIsConst && SecondIsConst)
1025 if (FirstIsConst || SecondIsConst) {
1026 CallbackFunc = SanCovTraceConstCmpFunction[CallbackIdx];
1033 auto GateBranch = CreateGateBranch(
F, FunctionGateCmp,
I);
1035 createRuntimeCall(GateIRB, CallbackFunc,
1036 {GateIRB.CreateIntCast(A0, Ty,
true),
1037 GateIRB.CreateIntCast(A1, Ty,
true)});
1049 Value *&FunctionGateCmp,
1052 bool IsEntryBB = &BB == &
F.getEntryBlock();
1055 if (
auto SP =
F.getSubprogram())
1066 if (
Options.TracePC || (IsEntryBB &&
Options.TracePCEntryExit)) {
1068 ? SanCovTracePCEntry
1070 createRuntimeCall(IRB, Callee)
1075 FunctionGuardArray->getValueType(), FunctionGuardArray, 0, Idx);
1078 auto GateBranch = CreateGateBranch(
F, FunctionGateCmp,
I);
1080 createRuntimeCall(GateIRB, SanCovTracePCGuard, GuardPtr)
1083 createRuntimeCall(IRB, SanCovTracePCGuard, GuardPtr)->setCannotMerge();
1086 if (
Options.Inline8bitCounters) {
1088 Function8bitCounterArray->getValueType(), Function8bitCounterArray,
1089 {ConstantInt::get(IntptrTy, 0), ConstantInt::get(IntptrTy, Idx)});
1091 auto Inc = IRB.
CreateAdd(
Load, ConstantInt::get(Int8Ty, 1));
1093 Load->setNoSanitizeMetadata();
1094 Store->setNoSanitizeMetadata();
1098 FunctionBoolArray->getValueType(), FunctionBoolArray,
1099 {ConstantInt::get(IntptrTy, 0), ConstantInt::get(IntptrTy, Idx)});
1107 Store->setDebugLoc(EntryLoc);
1108 Load->setNoSanitizeMetadata();
1109 Store->setNoSanitizeMetadata();
1111 if (
Options.StackDepth && IsEntryBB && !IsLeafFunc) {
1115 if (
Options.StackDepthCallbackMin) {
1117 int EstimatedStackSize = 0;
1119 bool HasDynamicAlloc =
false;
1126 for (
auto &
I : BB) {
1132 if (
auto AllocaSize = AI->getAllocationSize(
DL)) {
1133 if (AllocaSize->isFixed())
1134 EstimatedStackSize += AllocaSize->getFixedValue();
1136 HasDynamicAlloc =
true;
1138 HasDynamicAlloc =
true;
1143 if (HasDynamicAlloc ||
1144 EstimatedStackSize >=
Options.StackDepthCallbackMin) {
1147 auto Call = createRuntimeCall(IRB, SanCovStackDepthCallback);
1155 Intrinsic::frameaddress, IRB.
getPtrTy(
DL.getAllocaAddrSpace()),
1156 {Constant::getNullValue(Int32Ty)});
1158 auto LowestStack = IRB.
CreateLoad(IntptrTy, SanCovLowestStack);
1159 auto IsStackLower = IRB.
CreateICmpULT(FrameAddrInt, LowestStack);
1161 IsStackLower, &*IP,
false,
1164 auto Store = ThenIRB.CreateStore(FrameAddrInt, SanCovLowestStack);
1166 Store->setDebugLoc(EntryLoc);
1167 LowestStack->setNoSanitizeMetadata();
1168 Store->setNoSanitizeMetadata();
1174ModuleSanitizerCoverage::getSectionName(
const std::string &Section)
const {
1175 if (TargetTriple.isOSBinFormatCOFF()) {
1184 if (TargetTriple.isOSBinFormatMachO())
1190ModuleSanitizerCoverage::getSectionStart(
const std::string &Section)
const {
1191 if (TargetTriple.isOSBinFormatMachO())
1192 return "\1section$start$__DATA$__" +
Section;
1193 return "__start___" +
Section;
1197ModuleSanitizerCoverage::getSectionEnd(
const std::string &Section)
const {
1198 if (TargetTriple.isOSBinFormatMachO())
1199 return "\1section$end$__DATA$__" +
Section;
1203void ModuleSanitizerCoverage::createFunctionControlFlow(
Function &
F) {
1205 IRBuilder<> IRB(&*
F.getEntryBlock().getFirstInsertionPt());
1207 for (
auto &BB :
F) {
1209 if (&BB == &
F.getEntryBlock())
1216 assert(SuccBB != &
F.getEntryBlock());
1223 for (
auto &Inst : BB) {
1231 if (CalledF && !CalledF->isIntrinsic())
1240 FunctionCFsArray = CreateFunctionLocalArrayInSection(CFs.
size(),
F, PtrTy,
1242 FunctionCFsArray->setInitializer(
1244 FunctionCFsArray->setConstant(
true);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const IROptions & getOptions(const Module *M)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This is the interface for a simple mod/ref and alias analysis over globals.
Module.h This file contains the declarations for the Module class.
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
SmallVector< MachineOperand, 4 > Cond
const char SanCovCFsSectionName[]
static bool isFullPostDominator(const BasicBlock *BB, const PostDominatorTree &PDT)
const char SanCovTraceConstCmp4[]
const char SanCovBoolFlagSectionName[]
const char SanCov8bitCountersInitName[]
const char SanCovTracePCEntryName[]
const char SanCovTraceSwitchName[]
const char SanCovTraceCmp1[]
const char SanCovModuleCtorTracePcGuardName[]
const char SanCovCountersSectionName[]
const char SanCovPCsInitName[]
const char SanCovTracePCGuardName[]
const char SanCovModuleCtor8bitCountersName[]
const char SanCovTracePCGuardInitName[]
const char SanCovTraceDiv4[]
static const uint64_t SanCtorAndDtorPriority
const char SanCovBoolFlagInitName[]
const char SanCovTraceGep[]
const char SanCovLoad16[]
const char SanCovTraceConstCmp8[]
const char SanCovGuardsSectionName[]
const char SanCovStore1[]
const char SanCovTraceConstCmp2[]
const char SanCovTraceConstCmp1[]
static bool IsBackEdge(BasicBlock *From, BasicBlock *To, const DominatorTree &DT)
const char SanCovCallbackGateName[]
const char SanCovTraceDiv8[]
const char SanCovStackDepthCallbackName[]
const char SanCovCFsInitName[]
const char SanCovStore2[]
const char SanCovPCsSectionName[]
const char SanCovTracePCExitName[]
static bool isFullDominator(const BasicBlock *BB, const DominatorTree &DT)
const char SanCovTraceCmp8[]
const char SanCovCallbackGateSectionName[]
const char SanCovStore16[]
static bool IsInterestingCmp(ICmpInst *CMP, const DominatorTree &DT, const SanitizerCoverageOptions &Options)
static bool shouldInstrumentBlock(const Function &F, const BasicBlock *BB, const DominatorTree &DT, const PostDominatorTree &PDT, const SanitizerCoverageOptions &Options)
const char SanCovModuleCtorBoolFlagName[]
const char SanCovTraceCmp2[]
const char SanCovStore8[]
const char SanCovTracePCName[]
const char SanCovStore4[]
const char SanCovTraceCmp4[]
const char SanCovLowestStackName[]
const char SanCovTracePCIndirName[]
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
This file defines the SmallVector class.
Defines the virtual file system interface vfs::FileSystem.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM Basic Block Representation.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
LLVM_ABI const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
LLVM_ABI const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
LLVM_ABI InstListType::const_iterator getFirstNonPHIOrLifetime() const
Returns an iterator to the first instruction in this block that is not a PHINode, a lifetime intrinsi...
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
static LLVM_ABI BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
LLVM_ABI bool isIndirectCall() const
Return true if the callsite is an indirect call.
static LLVM_ABI CallBase * addOperandBundle(CallBase *CB, uint32_t ID, OperandBundleDef OB, InsertPosition InsertPt=nullptr)
Create a clone of CB with operand bundle OB added.
Value * getCalledOperand() const
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * getPtrAdd(Constant *Ptr, Constant *Offset, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReduced=nullptr)
Create a getelementptr i8, ptr, offset constant expression.
This is the shared class of boolean and integer constants.
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
This is an important base class in LLVM.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
EscapeEnumerator - This is a little algorithm to find all escape points from a function so that "fina...
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
const BasicBlock & getEntryBlock() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
LLVM_ABI void setComdat(Comdat *C)
void setLinkage(LinkageTypes LT)
@ HiddenVisibility
The GV is hidden.
void setVisibility(VisibilityTypes V)
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
Analysis pass providing a never-invalidated alias analysis result.
This instruction compares its operands according to the predicate given to the constructor.
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
void SetCurrentDebugLocation(const DebugLoc &L)
Set location information used by debugging information.
LLVM_ABI Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
LLVMContext & getContext() const
LLVM_ABI Value * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={}, function_ref< void(CallInst *)> SetFn=[](CallInst *) {})
Variant to create a possibly constant-folded intrinsic.
Value * CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Value * CreateIsNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg == 0.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Instruction * user_back()
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
LLVM_ABI void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
LLVM_ABI MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
LLVM_ABI MDNode * createUnlikelyBranchWeights()
Return metadata containing two branch weights, with significant bias towards false destination.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
A Module instance is used to store all the information related to an LLVM module.
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
Analysis pass which computes a PostDominatorTree.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
LLVM_ABI bool dominates(const Instruction *I1, const Instruction *I2) const
Return true if I1 dominates I2.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & abandon()
Mark an analysis as abandoned.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI SanitizerCoveragePass(SanitizerCoverageOptions Options=SanitizerCoverageOptions(), IntrusiveRefCntPtr< vfs::FileSystem > VFS=nullptr, const std::vector< std::string > &AllowlistFiles={}, const std::vector< std::string > &BlocklistFiles={})
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This is a utility class used to parse user-provided text files with "special case lists" for code san...
static LLVM_ABI std::unique_ptr< SpecialCaseList > createOrDie(const std::vector< std::string > &Paths, llvm::vfs::FileSystem &FS)
Parses the special case list entries from files.
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
bool hasOneUse() const
Return true if there is exactly one use of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
self_iterator getIterator()
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
@ OB
OB - OneByte - Set if this instruction has a one byte opcode.
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
const InstrumentationOptions & getInstrumentationOptions(const LLVMContext &C)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool succ_empty(const Instruction *I)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
LLVM_ABI DenseMap< BasicBlock *, ColorVector > colorEHFunclets(Function &F)
If an EH funclet personality is in use (see isFuncletEHPersonality), this will recompute which blocks...
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
LLVM_ABI FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type * > InitArgTypes, bool Weak=false)
LLVM_ABI std::pair< Function *, FunctionCallee > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, StringRef VersionCheckName=StringRef(), bool Weak=false)
Creates sanitizer constructor function, and calls sanitizer's init function from it.
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
LLVM_ABI Comdat * getOrCreateFunctionComdat(Function &F, Triple &T)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
OperandBundleDefT< Value * > OperandBundleDef
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
LLVM_ABI unsigned SplitAllCriticalEdges(Function &F, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
Loop over all of the edges in the CFG, breaking critical edges as they are found.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
TinyPtrVector< BasicBlock * > ColorVector
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto predecessors(const MachineBasicBlock *BB)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
bool pred_empty(const BasicBlock *BB)
LLVM_ABI BasicBlock::iterator PrepareToSplitEntryBlock(BasicBlock &BB, BasicBlock::iterator IP)
Instrumentation passes often insert conditional checks into entry blocks.
LLVM_ABI Instruction * SplitBlockAndInsertIfThen(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
LLVM_ABI void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Option class for critical edge splitting.
static void ensureDebugInfo(IRBuilder<> &IRB, const Function &F)
enum llvm::SanitizerCoverageOptions::Type CoverageType