LLVM  3.7.0
SanitizerCoverage.cpp
Go to the documentation of this file.
1 //===-- SanitizerCoverage.cpp - coverage instrumentation for sanitizers ---===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Coverage instrumentation that works with AddressSanitizer
11 // and potentially with other Sanitizers.
12 //
13 // We create a Guard variable with the same linkage
14 // as the function and inject this code into the entry block (SCK_Function)
15 // or all blocks (SCK_BB):
16 // if (Guard < 0) {
17 // __sanitizer_cov(&Guard);
18 // }
19 // The accesses to Guard are atomic. The rest of the logic is
20 // in __sanitizer_cov (it's fine to call it more than once).
21 //
22 // With SCK_Edge we also split critical edges this effectively
23 // instrumenting all edges.
24 //
25 // This coverage implementation provides very limited data:
26 // it only tells if a given function (block) was ever executed. No counters.
27 // But for many use cases this is what we need and the added slowdown small.
28 //
29 //===----------------------------------------------------------------------===//
30 
32 #include "llvm/ADT/ArrayRef.h"
33 #include "llvm/ADT/SmallVector.h"
34 #include "llvm/IR/CallSite.h"
35 #include "llvm/IR/DataLayout.h"
36 #include "llvm/IR/DebugInfo.h"
37 #include "llvm/IR/Function.h"
38 #include "llvm/IR/IRBuilder.h"
39 #include "llvm/IR/InlineAsm.h"
40 #include "llvm/IR/LLVMContext.h"
41 #include "llvm/IR/MDBuilder.h"
42 #include "llvm/IR/Module.h"
43 #include "llvm/IR/Type.h"
45 #include "llvm/Support/Debug.h"
47 #include "llvm/Transforms/Scalar.h"
50 
51 using namespace llvm;
52 
53 #define DEBUG_TYPE "sancov"
54 
55 static const char *const kSanCovModuleInitName = "__sanitizer_cov_module_init";
56 static const char *const kSanCovName = "__sanitizer_cov";
57 static const char *const kSanCovWithCheckName = "__sanitizer_cov_with_check";
58 static const char *const kSanCovIndirCallName = "__sanitizer_cov_indir_call16";
59 static const char *const kSanCovTraceEnter = "__sanitizer_cov_trace_func_enter";
60 static const char *const kSanCovTraceBB = "__sanitizer_cov_trace_basic_block";
61 static const char *const kSanCovTraceCmp = "__sanitizer_cov_trace_cmp";
62 static const char *const kSanCovModuleCtorName = "sancov.module_ctor";
63 static const uint64_t kSanCtorAndDtorPriority = 2;
64 
65 static cl::opt<int> ClCoverageLevel("sanitizer-coverage-level",
66  cl::desc("Sanitizer Coverage. 0: none, 1: entry block, 2: all blocks, "
67  "3: all blocks and critical edges, "
68  "4: above plus indirect calls"),
69  cl::Hidden, cl::init(0));
70 
72  "sanitizer-coverage-block-threshold",
73  cl::desc("Use a callback with a guard check inside it if there are"
74  " more than this number of blocks."),
75  cl::Hidden, cl::init(500));
76 
77 static cl::opt<bool>
78  ClExperimentalTracing("sanitizer-coverage-experimental-tracing",
79  cl::desc("Experimental basic-block tracing: insert "
80  "callbacks at every basic block"),
81  cl::Hidden, cl::init(false));
82 
83 static cl::opt<bool>
84  ClExperimentalCMPTracing("sanitizer-coverage-experimental-trace-compares",
85  cl::desc("Experimental tracing of CMP and similar "
86  "instructions"),
87  cl::Hidden, cl::init(false));
88 
89 // Experimental 8-bit counters used as an additional search heuristic during
90 // coverage-guided fuzzing.
91 // The counters are not thread-friendly:
92 // - contention on these counters may cause significant slowdown;
93 // - the counter updates are racy and the results may be inaccurate.
94 // They are also inaccurate due to 8-bit integer overflow.
95 static cl::opt<bool> ClUse8bitCounters("sanitizer-coverage-8bit-counters",
96  cl::desc("Experimental 8-bit counters"),
97  cl::Hidden, cl::init(false));
98 
99 namespace {
100 
101 SanitizerCoverageOptions getOptions(int LegacyCoverageLevel) {
103  switch (LegacyCoverageLevel) {
104  case 0:
106  break;
107  case 1:
109  break;
110  case 2:
112  break;
113  case 3:
115  break;
116  case 4:
118  Res.IndirectCalls = true;
119  break;
120  }
121  return Res;
122 }
123 
124 SanitizerCoverageOptions OverrideFromCL(SanitizerCoverageOptions Options) {
125  // Sets CoverageType and IndirectCalls.
126  SanitizerCoverageOptions CLOpts = getOptions(ClCoverageLevel);
127  Options.CoverageType = std::max(Options.CoverageType, CLOpts.CoverageType);
128  Options.IndirectCalls |= CLOpts.IndirectCalls;
129  Options.TraceBB |= ClExperimentalTracing;
132  return Options;
133 }
134 
135 class SanitizerCoverageModule : public ModulePass {
136  public:
137  SanitizerCoverageModule(
139  : ModulePass(ID), Options(OverrideFromCL(Options)) {}
140  bool runOnModule(Module &M) override;
141  bool runOnFunction(Function &F);
142  static char ID; // Pass identification, replacement for typeid
143  const char *getPassName() const override {
144  return "SanitizerCoverageModule";
145  }
146 
147  private:
148  void InjectCoverageForIndirectCalls(Function &F,
149  ArrayRef<Instruction *> IndirCalls);
150  void InjectTraceForCmp(Function &F, ArrayRef<Instruction *> CmpTraceTargets);
151  bool InjectCoverage(Function &F, ArrayRef<BasicBlock *> AllBlocks);
152  void SetNoSanitizeMetadata(Instruction *I);
153  void InjectCoverageAtBlock(Function &F, BasicBlock &BB, bool UseCalls);
154  unsigned NumberOfInstrumentedBlocks() {
155  return SanCovFunction->getNumUses() + SanCovWithCheckFunction->getNumUses();
156  }
157  Function *SanCovFunction;
158  Function *SanCovWithCheckFunction;
159  Function *SanCovIndirCallFunction;
160  Function *SanCovTraceEnter, *SanCovTraceBB;
161  Function *SanCovTraceCmpFunction;
162  InlineAsm *EmptyAsm;
163  Type *IntptrTy, *Int64Ty;
164  LLVMContext *C;
165  const DataLayout *DL;
166 
167  GlobalVariable *GuardArray;
168  GlobalVariable *EightBitCounterArray;
169 
170  SanitizerCoverageOptions Options;
171 };
172 
173 } // namespace
174 
175 bool SanitizerCoverageModule::runOnModule(Module &M) {
176  if (Options.CoverageType == SanitizerCoverageOptions::SCK_None)
177  return false;
178  C = &(M.getContext());
179  DL = &M.getDataLayout();
180  IntptrTy = Type::getIntNTy(*C, DL->getPointerSizeInBits());
181  Type *VoidTy = Type::getVoidTy(*C);
182  IRBuilder<> IRB(*C);
183  Type *Int8PtrTy = PointerType::getUnqual(IRB.getInt8Ty());
184  Type *Int32PtrTy = PointerType::getUnqual(IRB.getInt32Ty());
185  Int64Ty = IRB.getInt64Ty();
186 
187  SanCovFunction = checkSanitizerInterfaceFunction(
188  M.getOrInsertFunction(kSanCovName, VoidTy, Int32PtrTy, nullptr));
189  SanCovWithCheckFunction = checkSanitizerInterfaceFunction(
190  M.getOrInsertFunction(kSanCovWithCheckName, VoidTy, Int32PtrTy, nullptr));
191  SanCovIndirCallFunction =
193  kSanCovIndirCallName, VoidTy, IntptrTy, IntptrTy, nullptr));
194  SanCovTraceCmpFunction =
196  kSanCovTraceCmp, VoidTy, Int64Ty, Int64Ty, Int64Ty, nullptr));
197 
198  // We insert an empty inline asm after cov callbacks to avoid callback merge.
199  EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
200  StringRef(""), StringRef(""),
201  /*hasSideEffects=*/true);
202 
203  if (Options.TraceBB) {
204  SanCovTraceEnter = checkSanitizerInterfaceFunction(
205  M.getOrInsertFunction(kSanCovTraceEnter, VoidTy, Int32PtrTy, nullptr));
206  SanCovTraceBB = checkSanitizerInterfaceFunction(
207  M.getOrInsertFunction(kSanCovTraceBB, VoidTy, Int32PtrTy, nullptr));
208  }
209 
210  // At this point we create a dummy array of guards because we don't
211  // know how many elements we will need.
212  Type *Int32Ty = IRB.getInt32Ty();
213  Type *Int8Ty = IRB.getInt8Ty();
214 
215  GuardArray =
216  new GlobalVariable(M, Int32Ty, false, GlobalValue::ExternalLinkage,
217  nullptr, "__sancov_gen_cov_tmp");
218  if (Options.Use8bitCounters)
219  EightBitCounterArray =
220  new GlobalVariable(M, Int8Ty, false, GlobalVariable::ExternalLinkage,
221  nullptr, "__sancov_gen_cov_tmp");
222 
223  for (auto &F : M)
224  runOnFunction(F);
225 
226  auto N = NumberOfInstrumentedBlocks();
227 
228  // Now we know how many elements we need. Create an array of guards
229  // with one extra element at the beginning for the size.
230  Type *Int32ArrayNTy = ArrayType::get(Int32Ty, N + 1);
231  GlobalVariable *RealGuardArray = new GlobalVariable(
232  M, Int32ArrayNTy, false, GlobalValue::PrivateLinkage,
233  Constant::getNullValue(Int32ArrayNTy), "__sancov_gen_cov");
234 
235 
236  // Replace the dummy array with the real one.
237  GuardArray->replaceAllUsesWith(
238  IRB.CreatePointerCast(RealGuardArray, Int32PtrTy));
239  GuardArray->eraseFromParent();
240 
241  GlobalVariable *RealEightBitCounterArray;
242  if (Options.Use8bitCounters) {
243  // Make sure the array is 16-aligned.
244  static const int kCounterAlignment = 16;
245  Type *Int8ArrayNTy =
246  ArrayType::get(Int8Ty, RoundUpToAlignment(N, kCounterAlignment));
247  RealEightBitCounterArray = new GlobalVariable(
248  M, Int8ArrayNTy, false, GlobalValue::PrivateLinkage,
249  Constant::getNullValue(Int8ArrayNTy), "__sancov_gen_cov_counter");
250  RealEightBitCounterArray->setAlignment(kCounterAlignment);
251  EightBitCounterArray->replaceAllUsesWith(
252  IRB.CreatePointerCast(RealEightBitCounterArray, Int8PtrTy));
253  EightBitCounterArray->eraseFromParent();
254  }
255 
256  // Create variable for module (compilation unit) name
257  Constant *ModNameStrConst =
258  ConstantDataArray::getString(M.getContext(), M.getName(), true);
259  GlobalVariable *ModuleName =
260  new GlobalVariable(M, ModNameStrConst->getType(), true,
261  GlobalValue::PrivateLinkage, ModNameStrConst);
262 
263  Function *CtorFunc;
264  std::tie(CtorFunc, std::ignore) = createSanitizerCtorAndInitFunctions(
266  {Int32PtrTy, IntptrTy, Int8PtrTy, Int8PtrTy},
267  {IRB.CreatePointerCast(RealGuardArray, Int32PtrTy),
268  ConstantInt::get(IntptrTy, N),
269  Options.Use8bitCounters
270  ? IRB.CreatePointerCast(RealEightBitCounterArray, Int8PtrTy)
271  : Constant::getNullValue(Int8PtrTy),
272  IRB.CreatePointerCast(ModuleName, Int8PtrTy)});
273 
275 
276  return true;
277 }
278 
279 bool SanitizerCoverageModule::runOnFunction(Function &F) {
280  if (F.empty()) return false;
281  if (F.getName().find(".module_ctor") != std::string::npos)
282  return false; // Should not instrument sanitizer init functions.
283  if (Options.CoverageType >= SanitizerCoverageOptions::SCK_Edge)
285  SmallVector<Instruction*, 8> IndirCalls;
287  SmallVector<Instruction*, 8> CmpTraceTargets;
288  for (auto &BB : F) {
289  AllBlocks.push_back(&BB);
290  for (auto &Inst : BB) {
291  if (Options.IndirectCalls) {
292  CallSite CS(&Inst);
293  if (CS && !CS.getCalledFunction())
294  IndirCalls.push_back(&Inst);
295  }
296  if (Options.TraceCmp && isa<ICmpInst>(&Inst))
297  CmpTraceTargets.push_back(&Inst);
298  }
299  }
300  InjectCoverage(F, AllBlocks);
301  InjectCoverageForIndirectCalls(F, IndirCalls);
302  InjectTraceForCmp(F, CmpTraceTargets);
303  return true;
304 }
305 
306 bool SanitizerCoverageModule::InjectCoverage(Function &F,
307  ArrayRef<BasicBlock *> AllBlocks) {
308  switch (Options.CoverageType) {
310  return false;
312  InjectCoverageAtBlock(F, F.getEntryBlock(), false);
313  return true;
314  default: {
315  bool UseCalls = ClCoverageBlockThreshold < AllBlocks.size();
316  for (auto BB : AllBlocks)
317  InjectCoverageAtBlock(F, *BB, UseCalls);
318  return true;
319  }
320  }
321 }
322 
323 // On every indirect call we call a run-time function
324 // __sanitizer_cov_indir_call* with two parameters:
325 // - callee address,
326 // - global cache array that contains kCacheSize pointers (zero-initialized).
327 // The cache is used to speed up recording the caller-callee pairs.
328 // The address of the caller is passed implicitly via caller PC.
329 // kCacheSize is encoded in the name of the run-time function.
330 void SanitizerCoverageModule::InjectCoverageForIndirectCalls(
331  Function &F, ArrayRef<Instruction *> IndirCalls) {
332  if (IndirCalls.empty()) return;
333  const int kCacheSize = 16;
334  const int kCacheAlignment = 64; // Align for better performance.
335  Type *Ty = ArrayType::get(IntptrTy, kCacheSize);
336  for (auto I : IndirCalls) {
337  IRBuilder<> IRB(I);
338  CallSite CS(I);
339  Value *Callee = CS.getCalledValue();
340  if (isa<InlineAsm>(Callee)) continue;
341  GlobalVariable *CalleeCache = new GlobalVariable(
342  *F.getParent(), Ty, false, GlobalValue::PrivateLinkage,
343  Constant::getNullValue(Ty), "__sancov_gen_callee_cache");
344  CalleeCache->setAlignment(kCacheAlignment);
345  IRB.CreateCall(SanCovIndirCallFunction,
346  {IRB.CreatePointerCast(Callee, IntptrTy),
347  IRB.CreatePointerCast(CalleeCache, IntptrTy)});
348  }
349 }
350 
351 void SanitizerCoverageModule::InjectTraceForCmp(
352  Function &F, ArrayRef<Instruction *> CmpTraceTargets) {
353  for (auto I : CmpTraceTargets) {
354  if (ICmpInst *ICMP = dyn_cast<ICmpInst>(I)) {
355  IRBuilder<> IRB(ICMP);
356  Value *A0 = ICMP->getOperand(0);
357  Value *A1 = ICMP->getOperand(1);
358  if (!A0->getType()->isIntegerTy()) continue;
359  uint64_t TypeSize = DL->getTypeStoreSizeInBits(A0->getType());
360  // __sanitizer_cov_trace_cmp((type_size << 32) | predicate, A0, A1);
361  IRB.CreateCall(
362  SanCovTraceCmpFunction,
363  {ConstantInt::get(Int64Ty, (TypeSize << 32) | ICMP->getPredicate()),
364  IRB.CreateIntCast(A0, Int64Ty, true),
365  IRB.CreateIntCast(A1, Int64Ty, true)});
366  }
367  }
368 }
369 
370 void SanitizerCoverageModule::SetNoSanitizeMetadata(Instruction *I) {
371  I->setMetadata(
372  I->getParent()->getParent()->getParent()->getMDKindID("nosanitize"),
373  MDNode::get(*C, None));
374 }
375 
376 void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
377  bool UseCalls) {
378  // Don't insert coverage for unreachable blocks: we will never call
379  // __sanitizer_cov() for them, so counting them in
380  // NumberOfInstrumentedBlocks() might complicate calculation of code coverage
381  // percentage. Also, unreachable instructions frequently have no debug
382  // locations.
383  if (isa<UnreachableInst>(BB.getTerminator()))
384  return;
386  // Skip static allocas at the top of the entry block so they don't become
387  // dynamic when we split the block. If we used our optimized stack layout,
388  // then there will only be one alloca and it will come first.
389  for (; IP != BE; ++IP) {
390  AllocaInst *AI = dyn_cast<AllocaInst>(IP);
391  if (!AI || !AI->isStaticAlloca())
392  break;
393  }
394 
395  bool IsEntryBB = &BB == &F.getEntryBlock();
396  DebugLoc EntryLoc;
397  if (IsEntryBB) {
398  if (auto SP = getDISubprogram(&F))
399  EntryLoc = DebugLoc::get(SP->getScopeLine(), 0, SP);
400  } else {
401  EntryLoc = IP->getDebugLoc();
402  }
403 
404  IRBuilder<> IRB(IP);
405  IRB.SetCurrentDebugLocation(EntryLoc);
406  SmallVector<Value *, 1> Indices;
407  Value *GuardP = IRB.CreateAdd(
408  IRB.CreatePointerCast(GuardArray, IntptrTy),
409  ConstantInt::get(IntptrTy, (1 + NumberOfInstrumentedBlocks()) * 4));
410  Type *Int32PtrTy = PointerType::getUnqual(IRB.getInt32Ty());
411  GuardP = IRB.CreateIntToPtr(GuardP, Int32PtrTy);
412  if (UseCalls) {
413  IRB.CreateCall(SanCovWithCheckFunction, GuardP);
414  } else {
415  LoadInst *Load = IRB.CreateLoad(GuardP);
416  Load->setAtomic(Monotonic);
417  Load->setAlignment(4);
418  SetNoSanitizeMetadata(Load);
419  Value *Cmp = IRB.CreateICmpSGE(Constant::getNullValue(Load->getType()), Load);
421  Cmp, IP, false, MDBuilder(*C).createBranchWeights(1, 100000));
422  IRB.SetInsertPoint(Ins);
423  IRB.SetCurrentDebugLocation(EntryLoc);
424  // __sanitizer_cov gets the PC of the instruction using GET_CALLER_PC.
425  IRB.CreateCall(SanCovFunction, GuardP);
426  IRB.CreateCall(EmptyAsm, {}); // Avoids callback merge.
427  }
428 
429  if (Options.Use8bitCounters) {
430  IRB.SetInsertPoint(IP);
431  Value *P = IRB.CreateAdd(
432  IRB.CreatePointerCast(EightBitCounterArray, IntptrTy),
433  ConstantInt::get(IntptrTy, NumberOfInstrumentedBlocks() - 1));
434  P = IRB.CreateIntToPtr(P, IRB.getInt8PtrTy());
435  LoadInst *LI = IRB.CreateLoad(P);
436  Value *Inc = IRB.CreateAdd(LI, ConstantInt::get(IRB.getInt8Ty(), 1));
437  StoreInst *SI = IRB.CreateStore(Inc, P);
438  SetNoSanitizeMetadata(LI);
439  SetNoSanitizeMetadata(SI);
440  }
441 
442  if (Options.TraceBB) {
443  // Experimental support for tracing.
444  // Insert a callback with the same guard variable as used for coverage.
445  IRB.SetInsertPoint(IP);
446  IRB.CreateCall(IsEntryBB ? SanCovTraceEnter : SanCovTraceBB, GuardP);
447  }
448 }
449 
451 INITIALIZE_PASS(SanitizerCoverageModule, "sancov",
452  "SanitizerCoverage: TODO."
453  "ModulePass", false, false)
455  const SanitizerCoverageOptions &Options) {
456  return new SanitizerCoverageModule(Options);
457 }
const NoneType None
Definition: None.h:23
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
getString - This method constructs a CDS and initializes it with a text string.
Definition: Constants.cpp:2612
Function * checkSanitizerInterfaceFunction(Constant *FuncOrBitcast)
Definition: ModuleUtils.cpp:98
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
static cl::opt< unsigned > ClCoverageBlockThreshold("sanitizer-coverage-block-threshold", cl::desc("Use a callback with a guard check inside it if there are"" more than this number of blocks."), cl::Hidden, cl::init(500))
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:240
void appendToGlobalCtors(Module &M, Function *F, int Priority)
Append F to the list of global ctors of module M with the given Priority.
Definition: ModuleUtils.cpp:73
TerminatorInst * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DominatorTree *DT=nullptr)
SplitBlockAndInsertIfThen - Split the containing block at the specified instruction - everything befo...
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:48
Externally visible function.
Definition: GlobalValue.h:40
static const uint64_t kSanCtorAndDtorPriority
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:111
A debug info location.
Definition: DebugLoc.h:34
F(f)
LoadInst - an instruction for reading from memory.
Definition: Instructions.h:177
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:240
unsigned SplitAllCriticalEdges(Function &F, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
void setAlignment(unsigned Align)
Definition: Globals.cpp:77
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, ""4: above plus indirect calls"), cl::Hidden, cl::init(0))
static Constant * getNullValue(Type *Ty)
Definition: Constants.cpp:178
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:188
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:22
static const char *const kSanCovIndirCallName
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:517
static const char *const kSanCovName
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:36
void setAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread)
Definition: Instructions.h:273
static cl::opt< bool > ClExperimentalCMPTracing("sanitizer-coverage-experimental-trace-compares", cl::desc("Experimental tracing of CMP and similar ""instructions"), cl::Hidden, cl::init(false))
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
FunctionType::get - This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:361
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
StoreInst - an instruction for storing to memory.
Definition: Instructions.h:316
static const char *const kSanCovTraceEnter
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:134
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:325
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:115
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:41
static cl::opt< bool > ClExperimentalTracing("sanitizer-coverage-experimental-tracing", cl::desc("Experimental basic-block tracing: insert ""callbacks at every basic block"), cl::Hidden, cl::init(false))
This is an important base class in LLVM.
Definition: Constant.h:41
static const char *const kSanCovTraceBB
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:225
static const char *const kSanCovModuleCtorName
This instruction compares its operands according to the predicate given to the constructor.
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:129
void setAlignment(unsigned Align)
static const char *const kSanCovWithCheckName
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight)
Return metadata containing two branch weights.
Definition: MDBuilder.cpp:37
void setMetadata(unsigned KindID, MDNode *Node)
setMetadata - Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1083
static PointerType * getUnqual(Type *ElementType)
PointerType::getUnqual - This constructs a pointer to an object of the specified type in the generic ...
Definition: DerivedTypes.h:460
iterator end()
Definition: BasicBlock.h:233
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
bool isStaticAlloca() const
isStaticAlloca - Return true if this alloca is in the entry block of the function and is a constant s...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:222
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:243
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.
Definition: Constants.cpp:582
const BasicBlock & getEntryBlock() const
Definition: Function.h:442
INITIALIZE_PASS(SanitizerCoverageModule,"sancov","SanitizerCoverage: TODO.""ModulePass", false, false) ModulePass *llvm
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
Definition: Type.h:193
static cl::opt< bool > ClUse8bitCounters("sanitizer-coverage-8bit-counters", cl::desc("Experimental 8-bit counters"), cl::Hidden, cl::init(false))
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:285
bool empty() const
Definition: Function.h:463
uint64_t RoundUpToAlignment(uint64_t Value, uint64_t Align)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:609
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1030
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:372
static const char *const kSanCovModuleInitName
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:239
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:124
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:236
static const char *const kSanCovTraceCmp
static ArrayType * get(Type *ElementType, uint64_t NumElements)
ArrayType::get - This static method is the primary way to construct an ArrayType. ...
Definition: Type.cpp:686
std::pair< Function *, Function * > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs)
Creates sanitizer constructor function, and calls sanitizer's init function from it.
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.
Definition: InlineAsm.cpp:28
aarch64 promote const
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:365
LLVM Value Representation.
Definition: Value.h:69
C - The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
iterator getFirstInsertionPt()
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Definition: BasicBlock.cpp:194
ModulePass * createSanitizerCoverageModulePass(const SanitizerCoverageOptions &Options=SanitizerCoverageOptions())
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
Definition: Module.cpp:94
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:237
const BasicBlock * getParent() const
Definition: Instruction.h:72
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:265
AllocaInst - an instruction to allocate memory on the stack.
Definition: Instructions.h:76