LLVM 20.0.0git
Macros | Functions | Variables
SanitizerCoverage.cpp File Reference
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/EHPersonalities.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/SpecialCaseList.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "sancov"
 

Functions

static bool isFullDominator (const BasicBlock *BB, const DominatorTree &DT)
 
static bool isFullPostDominator (const BasicBlock *BB, const PostDominatorTree &PDT)
 
static bool shouldInstrumentBlock (const Function &F, const BasicBlock *BB, const DominatorTree &DT, const PostDominatorTree &PDT, const SanitizerCoverageOptions &Options)
 
static bool IsBackEdge (BasicBlock *From, BasicBlock *To, const DominatorTree &DT)
 
static bool IsInterestingCmp (ICmpInst *CMP, const DominatorTree &DT, const SanitizerCoverageOptions &Options)
 

Variables

const char SanCovTracePCIndirName [] = "__sanitizer_cov_trace_pc_indir"
 
const char SanCovTracePCName [] = "__sanitizer_cov_trace_pc"
 
const char SanCovTraceCmp1 [] = "__sanitizer_cov_trace_cmp1"
 
const char SanCovTraceCmp2 [] = "__sanitizer_cov_trace_cmp2"
 
const char SanCovTraceCmp4 [] = "__sanitizer_cov_trace_cmp4"
 
const char SanCovTraceCmp8 [] = "__sanitizer_cov_trace_cmp8"
 
const char SanCovTraceConstCmp1 [] = "__sanitizer_cov_trace_const_cmp1"
 
const char SanCovTraceConstCmp2 [] = "__sanitizer_cov_trace_const_cmp2"
 
const char SanCovTraceConstCmp4 [] = "__sanitizer_cov_trace_const_cmp4"
 
const char SanCovTraceConstCmp8 [] = "__sanitizer_cov_trace_const_cmp8"
 
const char SanCovLoad1 [] = "__sanitizer_cov_load1"
 
const char SanCovLoad2 [] = "__sanitizer_cov_load2"
 
const char SanCovLoad4 [] = "__sanitizer_cov_load4"
 
const char SanCovLoad8 [] = "__sanitizer_cov_load8"
 
const char SanCovLoad16 [] = "__sanitizer_cov_load16"
 
const char SanCovStore1 [] = "__sanitizer_cov_store1"
 
const char SanCovStore2 [] = "__sanitizer_cov_store2"
 
const char SanCovStore4 [] = "__sanitizer_cov_store4"
 
const char SanCovStore8 [] = "__sanitizer_cov_store8"
 
const char SanCovStore16 [] = "__sanitizer_cov_store16"
 
const char SanCovTraceDiv4 [] = "__sanitizer_cov_trace_div4"
 
const char SanCovTraceDiv8 [] = "__sanitizer_cov_trace_div8"
 
const char SanCovTraceGep [] = "__sanitizer_cov_trace_gep"
 
const char SanCovTraceSwitchName [] = "__sanitizer_cov_trace_switch"
 
const char SanCovModuleCtorTracePcGuardName []
 
const char SanCovModuleCtor8bitCountersName []
 
const char SanCovModuleCtorBoolFlagName [] = "sancov.module_ctor_bool_flag"
 
static const uint64_t SanCtorAndDtorPriority = 2
 
const char SanCovTracePCGuardName [] = "__sanitizer_cov_trace_pc_guard"
 
const char SanCovTracePCGuardInitName [] = "__sanitizer_cov_trace_pc_guard_init"
 
const char SanCov8bitCountersInitName [] = "__sanitizer_cov_8bit_counters_init"
 
const char SanCovBoolFlagInitName [] = "__sanitizer_cov_bool_flag_init"
 
const char SanCovPCsInitName [] = "__sanitizer_cov_pcs_init"
 
const char SanCovCFsInitName [] = "__sanitizer_cov_cfs_init"
 
const char SanCovGuardsSectionName [] = "sancov_guards"
 
const char SanCovCountersSectionName [] = "sancov_cntrs"
 
const char SanCovBoolFlagSectionName [] = "sancov_bools"
 
const char SanCovPCsSectionName [] = "sancov_pcs"
 
const char SanCovCFsSectionName [] = "sancov_cfs"
 
const char SanCovLowestStackName [] = "__sancov_lowest_stack"
 
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)
 
static cl::opt< boolClTracePC ("sanitizer-coverage-trace-pc", cl::desc("Experimental pc tracing"), cl::Hidden)
 
static cl::opt< boolClTracePCGuard ("sanitizer-coverage-trace-pc-guard", cl::desc("pc tracing with a guard"), cl::Hidden)
 
static cl::opt< boolClCreatePCTable ("sanitizer-coverage-pc-table", cl::desc("create a static PC table"), cl::Hidden)
 
static cl::opt< boolClInline8bitCounters ("sanitizer-coverage-inline-8bit-counters", cl::desc("increments 8-bit counter for every edge"), cl::Hidden)
 
static cl::opt< boolClInlineBoolFlag ("sanitizer-coverage-inline-bool-flag", cl::desc("sets a boolean flag for every edge"), cl::Hidden)
 
static cl::opt< boolClCMPTracing ("sanitizer-coverage-trace-compares", cl::desc("Tracing of CMP and similar instructions"), cl::Hidden)
 
static cl::opt< boolClDIVTracing ("sanitizer-coverage-trace-divs", cl::desc("Tracing of DIV instructions"), cl::Hidden)
 
static cl::opt< boolClLoadTracing ("sanitizer-coverage-trace-loads", cl::desc("Tracing of load instructions"), cl::Hidden)
 
static cl::opt< boolClStoreTracing ("sanitizer-coverage-trace-stores", cl::desc("Tracing of store instructions"), cl::Hidden)
 
static cl::opt< boolClGEPTracing ("sanitizer-coverage-trace-geps", cl::desc("Tracing of GEP instructions"), cl::Hidden)
 
static cl::opt< boolClPruneBlocks ("sanitizer-coverage-prune-blocks", cl::desc("Reduce the number of instrumented blocks"), cl::Hidden, cl::init(true))
 
static cl::opt< boolClStackDepth ("sanitizer-coverage-stack-depth", cl::desc("max stack depth tracing"), cl::Hidden)
 
static cl::opt< boolClCollectCF ("sanitizer-coverage-control-flow", cl::desc("collect control flow for each function"), cl::Hidden)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "sancov"

Definition at line 40 of file SanitizerCoverage.cpp.

Function Documentation

◆ IsBackEdge()

static bool IsBackEdge ( BasicBlock From,
BasicBlock To,
const DominatorTree DT 
)
static

◆ isFullDominator()

static bool isFullDominator ( const BasicBlock BB,
const DominatorTree DT 
)
static

◆ isFullPostDominator()

static bool isFullPostDominator ( const BasicBlock BB,
const PostDominatorTree PDT 
)
static

◆ IsInterestingCmp()

static bool IsInterestingCmp ( ICmpInst CMP,
const DominatorTree DT,
const SanitizerCoverageOptions Options 
)
static

Definition at line 594 of file SanitizerCoverage.cpp.

References B, IsBackEdge(), and Options.

◆ shouldInstrumentBlock()

static bool shouldInstrumentBlock ( const Function F,
const BasicBlock BB,
const DominatorTree DT,
const PostDominatorTree PDT,
const SanitizerCoverageOptions Options 
)
static

Variable Documentation

◆ ClCMPTracing

cl::opt< bool > ClCMPTracing("sanitizer-coverage-trace-compares", cl::desc("Tracing of CMP and similar instructions"), cl::Hidden) ( "sanitizer-coverage-trace-compares"  ,
cl::desc("Tracing of CMP and similar instructions")  ,
cl::Hidden   
)
static

◆ ClCollectCF

cl::opt< bool > ClCollectCF("sanitizer-coverage-control-flow", cl::desc("collect control flow for each function"), cl::Hidden) ( "sanitizer-coverage-control-flow"  ,
cl::desc("collect control flow for each function")  ,
cl::Hidden   
)
static

◆ ClCoverageLevel

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) ( "sanitizer-coverage-level"  ,
cl::desc("Sanitizer Coverage. 0: none, 1: entry block, 2: all blocks, " "3: all blocks and critical edges")  ,
cl::Hidden   
)
static

◆ ClCreatePCTable

cl::opt< bool > ClCreatePCTable("sanitizer-coverage-pc-table", cl::desc("create a static PC table"), cl::Hidden) ( "sanitizer-coverage-pc-table"  ,
cl::desc("create a static PC table")  ,
cl::Hidden   
)
static

◆ ClDIVTracing

cl::opt< bool > ClDIVTracing("sanitizer-coverage-trace-divs", cl::desc("Tracing of DIV instructions"), cl::Hidden) ( "sanitizer-coverage-trace-divs"  ,
cl::desc("Tracing of DIV instructions")  ,
cl::Hidden   
)
static

◆ ClGEPTracing

cl::opt< bool > ClGEPTracing("sanitizer-coverage-trace-geps", cl::desc("Tracing of GEP instructions"), cl::Hidden) ( "sanitizer-coverage-trace-geps"  ,
cl::desc("Tracing of GEP instructions")  ,
cl::Hidden   
)
static

◆ ClInline8bitCounters

cl::opt< bool > ClInline8bitCounters("sanitizer-coverage-inline-8bit-counters", cl::desc("increments 8-bit counter for every edge"), cl::Hidden) ( "sanitizer-coverage-inline-8bit-counters"  ,
cl::desc("increments 8-bit counter for every edge")  ,
cl::Hidden   
)
static

◆ ClInlineBoolFlag

cl::opt< bool > ClInlineBoolFlag("sanitizer-coverage-inline-bool-flag", cl::desc("sets a boolean flag for every edge"), cl::Hidden) ( "sanitizer-coverage-inline-bool-flag"  ,
cl::desc("sets a boolean flag for every edge")  ,
cl::Hidden   
)
static

◆ ClLoadTracing

cl::opt< bool > ClLoadTracing("sanitizer-coverage-trace-loads", cl::desc("Tracing of load instructions"), cl::Hidden) ( "sanitizer-coverage-trace-loads"  ,
cl::desc("Tracing of load instructions")  ,
cl::Hidden   
)
static

◆ ClPruneBlocks

cl::opt< bool > ClPruneBlocks("sanitizer-coverage-prune-blocks", cl::desc("Reduce the number of instrumented blocks"), cl::Hidden, cl::init(true)) ( "sanitizer-coverage-prune-blocks"  ,
cl::desc("Reduce the number of instrumented blocks")  ,
cl::Hidden  ,
cl::init(true  
)
static

◆ ClStackDepth

cl::opt< bool > ClStackDepth("sanitizer-coverage-stack-depth", cl::desc("max stack depth tracing"), cl::Hidden) ( "sanitizer-coverage-stack-depth"  ,
cl::desc("max stack depth tracing")  ,
cl::Hidden   
)
static

◆ ClStoreTracing

cl::opt< bool > ClStoreTracing("sanitizer-coverage-trace-stores", cl::desc("Tracing of store instructions"), cl::Hidden) ( "sanitizer-coverage-trace-stores"  ,
cl::desc("Tracing of store instructions")  ,
cl::Hidden   
)
static

◆ ClTracePC

cl::opt< bool > ClTracePC("sanitizer-coverage-trace-pc", cl::desc("Experimental pc tracing"), cl::Hidden) ( "sanitizer-coverage-trace-pc"  ,
cl::desc("Experimental pc tracing")  ,
cl::Hidden   
)
static

◆ ClTracePCGuard

cl::opt< bool > ClTracePCGuard("sanitizer-coverage-trace-pc-guard", cl::desc("pc tracing with a guard"), cl::Hidden) ( "sanitizer-coverage-trace-pc-guard"  ,
cl::desc("pc tracing with a guard")  ,
cl::Hidden   
)
static

◆ SanCov8bitCountersInitName

const char SanCov8bitCountersInitName[] = "__sanitizer_cov_8bit_counters_init"

Definition at line 75 of file SanitizerCoverage.cpp.

◆ SanCovBoolFlagInitName

const char SanCovBoolFlagInitName[] = "__sanitizer_cov_bool_flag_init"

Definition at line 76 of file SanitizerCoverage.cpp.

◆ SanCovBoolFlagSectionName

const char SanCovBoolFlagSectionName[] = "sancov_bools"

Definition at line 82 of file SanitizerCoverage.cpp.

◆ SanCovCFsInitName

const char SanCovCFsInitName[] = "__sanitizer_cov_cfs_init"

Definition at line 78 of file SanitizerCoverage.cpp.

◆ SanCovCFsSectionName

const char SanCovCFsSectionName[] = "sancov_cfs"

Definition at line 84 of file SanitizerCoverage.cpp.

◆ SanCovCountersSectionName

const char SanCovCountersSectionName[] = "sancov_cntrs"

Definition at line 81 of file SanitizerCoverage.cpp.

◆ SanCovGuardsSectionName

const char SanCovGuardsSectionName[] = "sancov_guards"

Definition at line 80 of file SanitizerCoverage.cpp.

◆ SanCovLoad1

const char SanCovLoad1[] = "__sanitizer_cov_load1"

Definition at line 52 of file SanitizerCoverage.cpp.

◆ SanCovLoad16

const char SanCovLoad16[] = "__sanitizer_cov_load16"

Definition at line 56 of file SanitizerCoverage.cpp.

◆ SanCovLoad2

const char SanCovLoad2[] = "__sanitizer_cov_load2"

Definition at line 53 of file SanitizerCoverage.cpp.

◆ SanCovLoad4

const char SanCovLoad4[] = "__sanitizer_cov_load4"

Definition at line 54 of file SanitizerCoverage.cpp.

◆ SanCovLoad8

const char SanCovLoad8[] = "__sanitizer_cov_load8"

Definition at line 55 of file SanitizerCoverage.cpp.

◆ SanCovLowestStackName

const char SanCovLowestStackName[] = "__sancov_lowest_stack"

Definition at line 86 of file SanitizerCoverage.cpp.

◆ SanCovModuleCtor8bitCountersName

const char SanCovModuleCtor8bitCountersName[]
Initial value:
=
"sancov.module_ctor_8bit_counters"

Definition at line 68 of file SanitizerCoverage.cpp.

◆ SanCovModuleCtorBoolFlagName

const char SanCovModuleCtorBoolFlagName[] = "sancov.module_ctor_bool_flag"

Definition at line 70 of file SanitizerCoverage.cpp.

◆ SanCovModuleCtorTracePcGuardName

const char SanCovModuleCtorTracePcGuardName[]
Initial value:
=
"sancov.module_ctor_trace_pc_guard"

Definition at line 66 of file SanitizerCoverage.cpp.

◆ SanCovPCsInitName

const char SanCovPCsInitName[] = "__sanitizer_cov_pcs_init"

Definition at line 77 of file SanitizerCoverage.cpp.

◆ SanCovPCsSectionName

const char SanCovPCsSectionName[] = "sancov_pcs"

Definition at line 83 of file SanitizerCoverage.cpp.

◆ SanCovStore1

const char SanCovStore1[] = "__sanitizer_cov_store1"

Definition at line 57 of file SanitizerCoverage.cpp.

◆ SanCovStore16

const char SanCovStore16[] = "__sanitizer_cov_store16"

Definition at line 61 of file SanitizerCoverage.cpp.

◆ SanCovStore2

const char SanCovStore2[] = "__sanitizer_cov_store2"

Definition at line 58 of file SanitizerCoverage.cpp.

◆ SanCovStore4

const char SanCovStore4[] = "__sanitizer_cov_store4"

Definition at line 59 of file SanitizerCoverage.cpp.

◆ SanCovStore8

const char SanCovStore8[] = "__sanitizer_cov_store8"

Definition at line 60 of file SanitizerCoverage.cpp.

◆ SanCovTraceCmp1

const char SanCovTraceCmp1[] = "__sanitizer_cov_trace_cmp1"

Definition at line 44 of file SanitizerCoverage.cpp.

◆ SanCovTraceCmp2

const char SanCovTraceCmp2[] = "__sanitizer_cov_trace_cmp2"

Definition at line 45 of file SanitizerCoverage.cpp.

◆ SanCovTraceCmp4

const char SanCovTraceCmp4[] = "__sanitizer_cov_trace_cmp4"

Definition at line 46 of file SanitizerCoverage.cpp.

◆ SanCovTraceCmp8

const char SanCovTraceCmp8[] = "__sanitizer_cov_trace_cmp8"

Definition at line 47 of file SanitizerCoverage.cpp.

◆ SanCovTraceConstCmp1

const char SanCovTraceConstCmp1[] = "__sanitizer_cov_trace_const_cmp1"

Definition at line 48 of file SanitizerCoverage.cpp.

◆ SanCovTraceConstCmp2

const char SanCovTraceConstCmp2[] = "__sanitizer_cov_trace_const_cmp2"

Definition at line 49 of file SanitizerCoverage.cpp.

◆ SanCovTraceConstCmp4

const char SanCovTraceConstCmp4[] = "__sanitizer_cov_trace_const_cmp4"

Definition at line 50 of file SanitizerCoverage.cpp.

◆ SanCovTraceConstCmp8

const char SanCovTraceConstCmp8[] = "__sanitizer_cov_trace_const_cmp8"

Definition at line 51 of file SanitizerCoverage.cpp.

◆ SanCovTraceDiv4

const char SanCovTraceDiv4[] = "__sanitizer_cov_trace_div4"

Definition at line 62 of file SanitizerCoverage.cpp.

◆ SanCovTraceDiv8

const char SanCovTraceDiv8[] = "__sanitizer_cov_trace_div8"

Definition at line 63 of file SanitizerCoverage.cpp.

◆ SanCovTraceGep

const char SanCovTraceGep[] = "__sanitizer_cov_trace_gep"

Definition at line 64 of file SanitizerCoverage.cpp.

◆ SanCovTracePCGuardInitName

const char SanCovTracePCGuardInitName[] = "__sanitizer_cov_trace_pc_guard_init"

Definition at line 74 of file SanitizerCoverage.cpp.

◆ SanCovTracePCGuardName

const char SanCovTracePCGuardName[] = "__sanitizer_cov_trace_pc_guard"

Definition at line 73 of file SanitizerCoverage.cpp.

◆ SanCovTracePCIndirName

const char SanCovTracePCIndirName[] = "__sanitizer_cov_trace_pc_indir"

Definition at line 42 of file SanitizerCoverage.cpp.

◆ SanCovTracePCName

const char SanCovTracePCName[] = "__sanitizer_cov_trace_pc"

Definition at line 43 of file SanitizerCoverage.cpp.

◆ SanCovTraceSwitchName

const char SanCovTraceSwitchName[] = "__sanitizer_cov_trace_switch"

Definition at line 65 of file SanitizerCoverage.cpp.

◆ SanCtorAndDtorPriority

const uint64_t SanCtorAndDtorPriority = 2
static

Definition at line 71 of file SanitizerCoverage.cpp.