45 #define DEBUG_TYPE "sancov" 48 "__sanitizer_cov_trace_pc_indir";
55 "__sanitizer_cov_trace_const_cmp1";
57 "__sanitizer_cov_trace_const_cmp2";
59 "__sanitizer_cov_trace_const_cmp4";
61 "__sanitizer_cov_trace_const_cmp8";
67 "sancov.module_ctor_trace_pc_guard";
69 "sancov.module_ctor_8bit_counters";
73 "__sanitizer_cov_trace_pc_guard";
75 "__sanitizer_cov_trace_pc_guard_init";
77 "__sanitizer_cov_8bit_counters_init";
87 "sanitizer-coverage-level",
88 cl::desc(
"Sanitizer Coverage. 0: none, 1: entry block, 2: all blocks, " 89 "3: all blocks and critical edges"),
106 cl::desc(
"create a static PC table"),
111 cl::desc(
"increments 8-bit counter for every edge"),
116 cl::desc(
"Tracing of CMP and similar instructions"),
120 cl::desc(
"Tracing of DIV instructions"),
124 cl::desc(
"Tracing of GEP instructions"),
129 cl::desc(
"Reduce the number of instrumented blocks"),
133 cl::desc(
"max stack depth tracing"),
140 switch (LegacyCoverageLevel) {
182 using PostDomTreeCallback =
185 class ModuleSanitizerCoverage {
187 ModuleSanitizerCoverage(
189 : Options(OverrideFromCL(Options)) {}
190 bool instrumentModule(
Module &M, DomTreeCallback DTCallback,
191 PostDomTreeCallback PDTCallback);
194 void instrumentFunction(
Function &
F, DomTreeCallback DTCallback,
195 PostDomTreeCallback PDTCallback);
196 void InjectCoverageForIndirectCalls(
Function &
F,
206 bool IsLeafFunc =
true);
207 GlobalVariable *CreateFunctionLocalArrayInSection(
size_t NumElements,
213 bool IsLeafFunc =
true);
214 Function *CreateInitCallsForSections(
Module &M,
const char *CtorName,
215 const char *InitFunctionName,
Type *Ty,
217 std::pair<Value *, Value *> CreateSecStartEnd(
Module &M,
const char *
Section,
225 std::string getSectionName(
const std::string &
Section)
const;
226 std::string getSectionStart(
const std::string &
Section)
const;
227 std::string getSectionEnd(
const std::string &
Section)
const;
237 Type *IntptrTy, *IntptrPtrTy, *Int64Ty, *Int64PtrTy, *
Int32Ty, *Int32PtrTy,
238 *Int16Ty, *Int8Ty, *Int8PtrTy;
240 std::string CurModuleUniqueId;
254 class ModuleSanitizerCoverageLegacyPass :
public ModulePass {
256 ModuleSanitizerCoverageLegacyPass(
262 bool runOnModule(
Module &M)
override {
263 ModuleSanitizerCoverage ModuleSancov(Options);
265 return &this->getAnalysis<DominatorTreeWrapperPass>(
F).getDomTree();
268 return &this->getAnalysis<PostDominatorTreeWrapperPass>(
F)
271 return ModuleSancov.instrumentModule(M, DTCallback, PDTCallback);
275 StringRef getPassName()
const override {
return "ModuleSanitizerCoverage"; }
290 ModuleSanitizerCoverage ModuleSancov(Options);
298 if (ModuleSancov.instrumentModule(M, DTCallback, PDTCallback))
303 std::pair<Value *, Value *>
304 ModuleSanitizerCoverage::CreateSecStartEnd(
Module &M,
const char *
Section,
308 getSectionStart(Section));
312 nullptr, getSectionEnd(Section));
315 Value *SecEndPtr = IRB.CreatePointerCast(SecEnd, Ty);
316 if (!TargetTriple.isOSBinFormatCOFF())
317 return std::make_pair(IRB.CreatePointerCast(SecStart, Ty), SecEndPtr);
321 auto SecStartI8Ptr = IRB.CreatePointerCast(SecStart, Int8PtrTy);
322 auto GEP = IRB.CreateGEP(Int8Ty, SecStartI8Ptr,
324 return std::make_pair(IRB.CreatePointerCast(
GEP, Ty), SecEndPtr);
327 Function *ModuleSanitizerCoverage::CreateInitCallsForSections(
328 Module &M,
const char *CtorName,
const char *InitFunctionName,
Type *Ty,
329 const char *Section) {
330 auto SecStartEnd = CreateSecStartEnd(M, Section, Ty);
331 auto SecStart = SecStartEnd.first;
332 auto SecEnd = SecStartEnd.second;
335 M, CtorName, InitFunctionName, {Ty, Ty}, {SecStart, SecEnd});
338 if (TargetTriple.supportsCOMDAT()) {
346 if (TargetTriple.isOSBinFormatCOFF()) {
359 bool ModuleSanitizerCoverage::instrumentModule(
360 Module &M, DomTreeCallback DTCallback, PostDomTreeCallback PDTCallback) {
368 FunctionGuardArray =
nullptr;
369 Function8bitCounterArray =
nullptr;
370 FunctionPCsArray =
nullptr;
389 SanCovTraceCmpZeroExtAL =
391 SanCovTraceCmpZeroExtAL =
395 SanCovTraceCmpFunction[0] =
398 SanCovTraceCmpFunction[1] =
401 SanCovTraceCmpFunction[2] =
404 SanCovTraceCmpFunction[3] =
408 SanCovTraceConstCmp1, SanCovTraceCmpZeroExtAL, VoidTy, Int8Ty, Int8Ty);
410 SanCovTraceConstCmp2, SanCovTraceCmpZeroExtAL, VoidTy, Int16Ty, Int16Ty);
412 SanCovTraceConstCmp4, SanCovTraceCmpZeroExtAL, VoidTy,
Int32Ty,
Int32Ty);
413 SanCovTraceConstCmpFunction[3] =
420 SanCovTraceDivFunction[0] =
423 SanCovTraceDivFunction[1] =
425 SanCovTraceGepFunction =
427 SanCovTraceSwitchFunction =
430 Constant *SanCovLowestStackConstant =
433 if (!SanCovLowestStack) {
434 C->emitError(
StringRef(
"'") + SanCovLowestStackName +
435 "' should not be declared by the user");
438 SanCovLowestStack->setThreadLocalMode(
439 GlobalValue::ThreadLocalMode::InitialExecTLSModel);
440 if (Options.
StackDepth && !SanCovLowestStack->isDeclaration())
453 instrumentFunction(
F, DTCallback, PDTCallback);
457 if (FunctionGuardArray)
458 Ctor = CreateInitCallsForSections(M, SanCovModuleCtorTracePcGuardName,
459 SanCovTracePCGuardInitName, Int32PtrTy,
460 SanCovGuardsSectionName);
461 if (Function8bitCounterArray)
462 Ctor = CreateInitCallsForSections(M, SanCovModuleCtor8bitCountersName,
463 SanCov8bitCountersInitName, Int8PtrTy,
464 SanCovCountersSectionName);
466 auto SecStartEnd = CreateSecStartEnd(M, SanCovPCsSectionName, IntptrPtrTy);
468 M, SanCovPCsInitName, {IntptrPtrTy, IntptrPtrTy});
470 IRBCtor.
CreateCall(InitFunction, {SecStartEnd.first, SecStartEnd.second});
474 if (TargetTriple.isOSBinFormatMachO())
561 if (
auto BR = dyn_cast<BranchInst>(CMP->
user_back()))
568 void ModuleSanitizerCoverage::instrumentFunction(
569 Function &
F, DomTreeCallback DTCallback, PostDomTreeCallback PDTCallback) {
572 if (F.
getName().
find(
".module_ctor") != std::string::npos)
581 if (F.
getName() ==
"__local_stdio_printf_options" ||
582 F.
getName() ==
"__local_stdio_scanf_options")
603 bool IsLeafFunc =
true;
608 for (
auto &Inst : BB) {
618 if (isa<SwitchInst>(&Inst))
623 if (BO->getOpcode() == Instruction::SDiv ||
624 BO->getOpcode() == Instruction::UDiv)
630 if (isa<InvokeInst>(Inst) ||
631 (isa<CallInst>(Inst) && !isa<IntrinsicInst>(Inst)))
636 InjectCoverage(F, BlocksToInstrument, IsLeafFunc);
637 InjectCoverageForIndirectCalls(F, IndirCalls);
638 InjectTraceForCmp(F, CmpTraceTargets);
639 InjectTraceForSwitch(F, SwitchTraceTargets);
640 InjectTraceForDiv(F, DivTraceTargets);
641 InjectTraceForGep(F, GepTraceTargets);
644 GlobalVariable *ModuleSanitizerCoverage::CreateFunctionLocalArrayInSection(
645 size_t NumElements,
Function &F,
Type *Ty,
const char *Section) {
655 Array->setSection(getSectionName(Section));
657 ? DL->getPointerSize()
659 GlobalsToAppendToUsed.push_back(Array);
660 GlobalsToAppendToCompilerUsed.push_back(Array);
662 Array->addMetadata(LLVMContext::MD_associated, *MD);
668 ModuleSanitizerCoverage::CreatePCArray(
Function &F,
670 size_t N = AllBlocks.
size();
674 for (
size_t i = 0; i <
N; i++) {
686 auto *PCArray = CreateFunctionLocalArrayInSection(N * 2, F, IntptrPtrTy,
687 SanCovPCsSectionName);
688 PCArray->setInitializer(
690 PCArray->setConstant(
true);
695 void ModuleSanitizerCoverage::CreateFunctionLocalArrays(
698 FunctionGuardArray = CreateFunctionLocalArrayInSection(
702 Function8bitCounterArray = CreateFunctionLocalArrayInSection(
706 FunctionPCsArray = CreatePCArray(F, AllBlocks);
709 bool ModuleSanitizerCoverage::InjectCoverage(
Function &F,
712 if (AllBlocks.
empty())
return false;
713 CreateFunctionLocalArrays(F, AllBlocks);
714 for (
size_t i = 0,
N = AllBlocks.
size(); i <
N; i++)
715 InjectCoverageAtBlock(F, *AllBlocks[i], i, IsLeafFunc);
726 void ModuleSanitizerCoverage::InjectCoverageForIndirectCalls(
728 if (IndirCalls.
empty())
731 for (
auto I : IndirCalls) {
735 if (isa<InlineAsm>(Callee))
745 void ModuleSanitizerCoverage::InjectTraceForSwitch(
747 for (
auto I : SwitchTraceTargets) {
751 Value *Cond =
SI->getCondition();
753 Int64Ty->getScalarSizeInBits())
759 Int64Ty->getScalarSizeInBits())
761 for (
auto It :
SI->cases()) {
764 Int64Ty->getScalarSizeInBits())
770 return cast<ConstantInt>(A)->getLimitedValue() <
771 cast<ConstantInt>(
B)->getLimitedValue();
777 "__sancov_gen_cov_switch_values");
784 void ModuleSanitizerCoverage::InjectTraceForDiv(
786 for (
auto BO : DivTraceTargets) {
788 Value *A1 = BO->getOperand(1);
789 if (isa<ConstantInt>(A1))
continue;
793 int CallbackIdx = TypeSize == 32 ? 0 :
794 TypeSize == 64 ? 1 : -1;
795 if (CallbackIdx < 0)
continue;
797 IRB.
CreateCall(SanCovTraceDivFunction[CallbackIdx],
802 void ModuleSanitizerCoverage::InjectTraceForGep(
804 for (
auto GEP : GepTraceTargets) {
806 for (
auto I =
GEP->idx_begin(); I !=
GEP->idx_end(); ++
I)
807 if (!isa<ConstantInt>(*I) && (*I)->getType()->isIntegerTy())
809 {IRB.CreateIntCast(*I, IntptrTy, true)});
813 void ModuleSanitizerCoverage::InjectTraceForCmp(
815 for (
auto I : CmpTraceTargets) {
823 int CallbackIdx = TypeSize == 8 ? 0 :
826 TypeSize == 64 ? 3 : -1;
827 if (CallbackIdx < 0)
continue;
829 auto CallbackFunc = SanCovTraceCmpFunction[CallbackIdx];
830 bool FirstIsConst = isa<ConstantInt>(A0);
831 bool SecondIsConst = isa<ConstantInt>(A1);
833 if (FirstIsConst && SecondIsConst)
continue;
835 if (FirstIsConst || SecondIsConst) {
836 CallbackFunc = SanCovTraceConstCmpFunction[CallbackIdx];
862 EntryLoc = IP->getDebugLoc();
881 Function8bitCounterArray->getValueType(), Function8bitCounterArray,
886 SetNoSanitizeMetadata(
Load);
887 SetNoSanitizeMetadata(
Store);
889 if (Options.
StackDepth && IsEntryBB && !IsLeafFunc) {
893 M, Intrinsic::frameaddress,
898 auto LowestStack = IRB.
CreateLoad(IntptrTy, SanCovLowestStack);
899 auto IsStackLower = IRB.
CreateICmpULT(FrameAddrInt, LowestStack);
903 SetNoSanitizeMetadata(LowestStack);
904 SetNoSanitizeMetadata(
Store);
909 ModuleSanitizerCoverage::getSectionName(
const std::string &Section)
const {
910 if (TargetTriple.isOSBinFormatCOFF()) {
911 if (Section == SanCovCountersSectionName)
913 if (Section == SanCovPCsSectionName)
917 if (TargetTriple.isOSBinFormatMachO())
918 return "__DATA,__" + Section;
923 ModuleSanitizerCoverage::getSectionStart(
const std::string &Section)
const {
924 if (TargetTriple.isOSBinFormatMachO())
925 return "\1section$start$__DATA$__" + Section;
930 ModuleSanitizerCoverage::getSectionEnd(
const std::string &Section)
const {
931 if (TargetTriple.isOSBinFormatMachO())
932 return "\1section$end$__DATA$__" + Section;
938 "Pass for instrumenting coverage on functions",
false,
947 return new ModuleSanitizerCoverageLegacyPass(Options);
IntegerType * getInt16Ty()
Fetch the type representing a 16-bit integer.
void setVisibility(VisibilityTypes V)
static const char *const SanCovPCsSectionName
Pass interface - Implemented by all 'passes'.
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue *> Values)
Adds global values to the llvm.compiler.used list.
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
static const uint64_t SanCtorAndDtorPriority
DILocation * get() const
Get the underlying DILocation.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static const char *const SanCovModuleCtor8bitCountersName
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class represents lattice values for constants.
static const char *const SanCovTraceConstCmp1
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
A Module instance is used to store all the information related to an LLVM module. ...
Same, but only replaced by something equivalent.
static const char *const SanCovPCsInitName
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Available for inspection, not emission.
void push_back(const T &Elt)
static bool isFullPostDominator(const BasicBlock *BB, const PostDominatorTree *PDT)
static const char *const SanCovGuardsSectionName
An efficient, type-erasing, non-owning reference to a callable.
Like Internal, but omit from symbol table.
Externally visible function.
bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time...
static cl::opt< bool > ClStackDepth("sanitizer-coverage-stack-depth", cl::desc("max stack depth tracing"), cl::Hidden, cl::init(false))
Analysis pass which computes a DominatorTree.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
unsigned SplitAllCriticalEdges(Function &F, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
Loop over all of the edges in the CFG, breaking critical edges as they are found. ...
static const char *const SanCovTracePCName
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static const char *const SanCovTraceSwitchName
INITIALIZE_PASS_BEGIN(ModuleSanitizerCoverageLegacyPass, "sancov", "Pass for instrumenting coverage on functions", false, false) INITIALIZE_PASS_END(ModuleSanitizerCoverageLegacyPass
static const char *const SanCovTraceConstCmp2
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static const char *const SanCov8bitCountersInitName
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
unsigned getAllocaAddrSpace() const
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Option class for critical edge splitting.
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
static const char *const SanCovTraceCmp2
LLVMContext & getContext() const
Get the global data context.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
bool isIntegerTy() const
True if this is an instance of IntegerType.
static const char *const SanCovLowestStackName
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
static cl::opt< int > ClCoverageLevel("sanitizer-coverage-level", cl::desc("Sanitizer Coverage. 0: none, 1: entry block, 2: all blocks, " "3: all blocks and critical edges"), cl::Hidden, cl::init(0))
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Type * getVoidTy()
Fetch the type representing void.
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
static const char *const SanCovTraceGep
const Instruction * getFirstNonPHIOrDbgOrLifetime() const
Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic...
Type * getType() const
All values are typed, get the type of this value.
void appendToUsed(Module &M, ArrayRef< GlobalValue *> Values)
Adds global values to the llvm.used list.
static cl::opt< bool > ClDIVTracing("sanitizer-coverage-trace-divs", cl::desc("Tracing of DIV instructions"), cl::Hidden, cl::init(false))
Class to represent array types.
void setComdat(Comdat *C)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static cl::opt< bool > ClCMPTracing("sanitizer-coverage-trace-compares", cl::desc("Tracing of CMP and similar instructions"), cl::Hidden, cl::init(false))
bool hasPersonalityFn() const
Check whether this function has a personality function.
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
LinkageTypes getLinkage() const
static const char *const SanCovTracePCGuardName
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Interval::succ_iterator succ_end(Interval *I)
const BasicBlock & getEntryBlock() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
static const char *const SanCovTracePCIndirName
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
initializer< Ty > init(const Ty &Val)
Control flow instructions. These all have token chains.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A set of analyses that are preserved following a run of a transformation pass.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
static const char *const SanCovTraceCmp1
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
LLVM Basic Block Representation.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool dominates(const Instruction *I1, const Instruction *I2) const
Return true if I1 dominates I2.
LLVM_NODISCARD AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
DISubprogram * getSubprogram() const
Get the attached subprogram.
static cl::opt< bool > ClCreatePCTable("sanitizer-coverage-pc-table", cl::desc("create a static PC table"), cl::Hidden, cl::init(false))
static const char *const SanCovTraceDiv4
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
size_t size() const
size - Get the array size.
This is an important base class in LLVM.
bool isPointerTy() const
True if this is an instance of PointerType.
static const char *const SanCovTraceConstCmp8
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
This instruction compares its operands according to the predicate given to the constructor.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Interval::pred_iterator pred_end(Interval *I)
static cl::opt< bool > ClPruneBlocks("sanitizer-coverage-prune-blocks", cl::desc("Reduce the number of instrumented blocks"), cl::Hidden, cl::init(true))
static cl::opt< bool > ClTracePCGuard("sanitizer-coverage-trace-pc-guard", cl::desc("pc tracing with a guard"), cl::Hidden, cl::init(false))
static const char *const SanCovTraceCmp4
static Constant * getAllOnesValue(Type *Ty)
std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module's strong...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static const char *const SanCovTraceCmp8
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Triple - Helper class for working with autoconf configuration names.
void sort(IteratorTy Start, IteratorTy End)
static const char *const SanCovModuleCtorTracePcGuardName
Value * CreateGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
BlockVerifier::State From
Align max(MaybeAlign Lhs, Align Rhs)
static bool isFullDominator(const BasicBlock *BB, const DominatorTree *DT)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Analysis pass which computes a PostDominatorTree.
Module.h This file contains the declarations for the Module class.
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
static const char *const SanCovCountersSectionName
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
enum llvm::SanitizerCoverageOptions::Type CoverageType
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
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.
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
static bool shouldInstrumentBlock(const Function &F, const BasicBlock *BB, const DominatorTree *DT, const PostDominatorTree *PDT, const SanitizerCoverageOptions &Options)
BasicBlock::iterator PrepareToSplitEntryBlock(BasicBlock &BB, BasicBlock::iterator IP)
Instrumentation passes often insert conditional checks into entry blocks.
void setLinkage(LinkageTypes LT)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
amdgpu Simplify well known AMD library false FunctionCallee Callee
Comdat * GetOrCreateFunctionComdat(Function &F, Triple &T, const std::string &ModuleId)
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
void initializeModuleSanitizerCoverageLegacyPassPass(PassRegistry &)
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
static cl::opt< bool > ClTracePC("sanitizer-coverage-trace-pc", cl::desc("Experimental pc tracing"), cl::Hidden, cl::init(false))
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type *> InitArgTypes)
static bool IsInterestingCmp(ICmpInst *CMP, const DominatorTree *DT, const SanitizerCoverageOptions &Options)
ModulePass * createModuleSanitizerCoverageLegacyPassPass(const SanitizerCoverageOptions &Options=SanitizerCoverageOptions())
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Constant * getOrInsertGlobal(StringRef Name, Type *Ty, function_ref< GlobalVariable *()> CreateGlobalCallback)
Look up the specified global in the module symbol table.
static cl::opt< bool > ClGEPTracing("sanitizer-coverage-trace-geps", cl::desc("Tracing of GEP instructions"), cl::Hidden, cl::init(false))
static const char *const SanCovTraceDiv8
StringRef getName() const
Return a constant reference to the value's name.
static bool IsBackEdge(BasicBlock *From, BasicBlock *To, const DominatorTree *DT)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Pass for instrumenting coverage on functions
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Rename collisions when linking (static functions).
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT)
InlineAsm::get - Return the specified uniqued inline asm string.
static cl::opt< bool > ClInline8bitCounters("sanitizer-coverage-inline-8bit-counters", cl::desc("increments 8-bit counter for every edge"), cl::Hidden, cl::init(false))
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
static const char *const SanCovTracePCGuardInitName
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
bool hasOneUse() const
Return true if there is exactly one user of this value.
StringRef - Represent a constant reference to a string, i.e.
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
std::pair< Function *, FunctionCallee > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type *> InitArgTypes, ArrayRef< Value *> InitArgs, StringRef VersionCheckName=StringRef())
Creates sanitizer constructor function, and calls sanitizer's init function from it.
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
static const char *const SanCovTraceConstCmp4
Instruction * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
bool empty() const
empty - Check if the array is empty.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.