blob: 6000fd057da55d1cfa56b4c591396f62412dd0f2 [file] [log] [blame]
Kostya Serebryany29a18dc2014-11-11 22:14:37 +00001//===-- 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//
Kostya Serebryany9fdeb372014-12-23 22:32:17 +000013// We create a Guard variable with the same linkage
Kostya Serebryany29a18dc2014-11-11 22:14:37 +000014// as the function and inject this code into the entry block (CoverageLevel=1)
15// or all blocks (CoverageLevel>=2):
Kostya Serebryany9fdeb372014-12-23 22:32:17 +000016// if (Guard < 0) {
Kostya Serebryany4cadd4a2014-11-24 18:49:53 +000017// __sanitizer_cov(&Guard);
Kostya Serebryany29a18dc2014-11-11 22:14:37 +000018// }
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 CoverageLevel>=3 we also split critical edges this effectively
23// instrumenting all edges.
24//
25// CoverageLevel>=4 add indirect call profiling implented as a function call.
26//
27// This coverage implementation provides very limited data:
28// it only tells if a given function (block) was ever executed. No counters.
29// But for many use cases this is what we need and the added slowdown small.
30//
31//===----------------------------------------------------------------------===//
32
33#include "llvm/Transforms/Instrumentation.h"
34#include "llvm/ADT/ArrayRef.h"
35#include "llvm/ADT/SmallVector.h"
36#include "llvm/IR/CallSite.h"
37#include "llvm/IR/DataLayout.h"
38#include "llvm/IR/Function.h"
39#include "llvm/IR/IRBuilder.h"
Kostya Serebryany73762942014-12-16 21:24:15 +000040#include "llvm/IR/InlineAsm.h"
Kostya Serebryany29a18dc2014-11-11 22:14:37 +000041#include "llvm/IR/LLVMContext.h"
42#include "llvm/IR/MDBuilder.h"
43#include "llvm/IR/Module.h"
44#include "llvm/IR/Type.h"
45#include "llvm/Support/CommandLine.h"
46#include "llvm/Support/Debug.h"
47#include "llvm/Support/raw_ostream.h"
48#include "llvm/Transforms/Scalar.h"
49#include "llvm/Transforms/Utils/BasicBlockUtils.h"
50#include "llvm/Transforms/Utils/ModuleUtils.h"
51
52using namespace llvm;
53
54#define DEBUG_TYPE "sancov"
55
56static const char *const kSanCovModuleInitName = "__sanitizer_cov_module_init";
57static const char *const kSanCovName = "__sanitizer_cov";
Kostya Serebryany77cc7292015-02-04 01:21:45 +000058static const char *const kSanCovWithCheckName = "__sanitizer_cov_with_check";
Kostya Serebryany29a18dc2014-11-11 22:14:37 +000059static const char *const kSanCovIndirCallName = "__sanitizer_cov_indir_call16";
Kostya Serebryanycb45b122014-11-19 00:22:58 +000060static const char *const kSanCovTraceEnter = "__sanitizer_cov_trace_func_enter";
61static const char *const kSanCovTraceBB = "__sanitizer_cov_trace_basic_block";
Kostya Serebryany29a18dc2014-11-11 22:14:37 +000062static const char *const kSanCovModuleCtorName = "sancov.module_ctor";
Evgeniy Stepanov3fdfc7b2015-01-27 15:01:22 +000063static const uint64_t kSanCtorAndDtorPriority = 2;
Kostya Serebryany29a18dc2014-11-11 22:14:37 +000064
65static 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
Kostya Serebryany77cc7292015-02-04 01:21:45 +000071static cl::opt<unsigned> ClCoverageBlockThreshold(
Kostya Serebryany29a18dc2014-11-11 22:14:37 +000072 "sanitizer-coverage-block-threshold",
Kostya Serebryany77cc7292015-02-04 01:21:45 +000073 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(1000));
Kostya Serebryany29a18dc2014-11-11 22:14:37 +000076
Kostya Serebryanycb45b122014-11-19 00:22:58 +000077static 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
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +000083// Experimental 8-bit counters used as an additional search heuristic during
84// coverage-guided fuzzing.
85// The counters are not thread-friendly:
86// - contention on these counters may cause significant slowdown;
87// - the counter updates are racy and the results may be inaccurate.
88// They are also inaccurate due to 8-bit integer overflow.
89static cl::opt<bool> ClUse8bitCounters("sanitizer-coverage-8bit-counters",
90 cl::desc("Experimental 8-bit counters"),
91 cl::Hidden, cl::init(false));
92
Kostya Serebryany29a18dc2014-11-11 22:14:37 +000093namespace {
94
95class SanitizerCoverageModule : public ModulePass {
96 public:
Kostya Serebryanycb45b122014-11-19 00:22:58 +000097 SanitizerCoverageModule(int CoverageLevel = 0)
Kostya Serebryany29a18dc2014-11-11 22:14:37 +000098 : ModulePass(ID),
Kostya Serebryanycb45b122014-11-19 00:22:58 +000099 CoverageLevel(std::max(CoverageLevel, (int)ClCoverageLevel)) {}
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000100 bool runOnModule(Module &M) override;
101 bool runOnFunction(Function &F);
102 static char ID; // Pass identification, replacement for typeid
103 const char *getPassName() const override {
104 return "SanitizerCoverageModule";
105 }
106
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000107 private:
108 void InjectCoverageForIndirectCalls(Function &F,
109 ArrayRef<Instruction *> IndirCalls);
110 bool InjectCoverage(Function &F, ArrayRef<BasicBlock *> AllBlocks,
111 ArrayRef<Instruction *> IndirCalls);
Kostya Serebryany83ce8772015-03-05 01:20:05 +0000112 void SetNoSanitizeMetada(Instruction *I);
Kostya Serebryany77cc7292015-02-04 01:21:45 +0000113 void InjectCoverageAtBlock(Function &F, BasicBlock &BB, bool UseCalls);
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000114 Function *SanCovFunction;
Kostya Serebryany77cc7292015-02-04 01:21:45 +0000115 Function *SanCovWithCheckFunction;
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000116 Function *SanCovIndirCallFunction;
117 Function *SanCovModuleInit;
Kostya Serebryanycb45b122014-11-19 00:22:58 +0000118 Function *SanCovTraceEnter, *SanCovTraceBB;
Kostya Serebryany73762942014-12-16 21:24:15 +0000119 InlineAsm *EmptyAsm;
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000120 Type *IntptrTy;
121 LLVMContext *C;
122
Kostya Serebryanyaa185bf2014-12-30 19:29:28 +0000123 GlobalVariable *GuardArray;
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000124 GlobalVariable *EightBitCounterArray;
Kostya Serebryany9fdeb372014-12-23 22:32:17 +0000125
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000126 int CoverageLevel;
127};
128
129} // namespace
130
131static Function *checkInterfaceFunction(Constant *FuncOrBitcast) {
132 if (Function *F = dyn_cast<Function>(FuncOrBitcast))
133 return F;
134 std::string Err;
135 raw_string_ostream Stream(Err);
136 Stream << "SanitizerCoverage interface function redefined: "
137 << *FuncOrBitcast;
138 report_fatal_error(Err);
139}
140
141bool SanitizerCoverageModule::runOnModule(Module &M) {
142 if (!CoverageLevel) return false;
143 C = &(M.getContext());
Mehdi Amini46a43552015-03-04 18:43:29 +0000144 auto &DL = M.getDataLayout();
145 IntptrTy = Type::getIntNTy(*C, DL.getPointerSizeInBits());
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000146 Type *VoidTy = Type::getVoidTy(*C);
Kostya Serebryany4cadd4a2014-11-24 18:49:53 +0000147 IRBuilder<> IRB(*C);
Kostya Serebryany88599462015-02-20 00:30:44 +0000148 Type *Int8PtrTy = PointerType::getUnqual(IRB.getInt8Ty());
Kostya Serebryany9fdeb372014-12-23 22:32:17 +0000149 Type *Int32PtrTy = PointerType::getUnqual(IRB.getInt32Ty());
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000150
151 Function *CtorFunc =
152 Function::Create(FunctionType::get(VoidTy, false),
153 GlobalValue::InternalLinkage, kSanCovModuleCtorName, &M);
154 ReturnInst::Create(*C, BasicBlock::Create(*C, "", CtorFunc));
155 appendToGlobalCtors(M, CtorFunc, kSanCtorAndDtorPriority);
156
Kostya Serebryany4cadd4a2014-11-24 18:49:53 +0000157 SanCovFunction = checkInterfaceFunction(
Kostya Serebryany9fdeb372014-12-23 22:32:17 +0000158 M.getOrInsertFunction(kSanCovName, VoidTy, Int32PtrTy, nullptr));
Kostya Serebryany77cc7292015-02-04 01:21:45 +0000159 SanCovWithCheckFunction = checkInterfaceFunction(
160 M.getOrInsertFunction(kSanCovWithCheckName, VoidTy, Int32PtrTy, nullptr));
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000161 SanCovIndirCallFunction = checkInterfaceFunction(M.getOrInsertFunction(
Reid Kleckner971c3ea2014-11-13 22:55:19 +0000162 kSanCovIndirCallName, VoidTy, IntptrTy, IntptrTy, nullptr));
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000163 SanCovModuleInit = checkInterfaceFunction(M.getOrInsertFunction(
164 kSanCovModuleInitName, Type::getVoidTy(*C), Int32PtrTy, IntptrTy,
165 Int8PtrTy, Int8PtrTy, nullptr));
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000166 SanCovModuleInit->setLinkage(Function::ExternalLinkage);
Kostya Serebryany73762942014-12-16 21:24:15 +0000167 // We insert an empty inline asm after cov callbacks to avoid callback merge.
168 EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
169 StringRef(""), StringRef(""),
170 /*hasSideEffects=*/true);
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000171
Kostya Serebryanycb45b122014-11-19 00:22:58 +0000172 if (ClExperimentalTracing) {
173 SanCovTraceEnter = checkInterfaceFunction(
Kostya Serebryanyd421db02015-01-03 00:54:43 +0000174 M.getOrInsertFunction(kSanCovTraceEnter, VoidTy, Int32PtrTy, nullptr));
Kostya Serebryanycb45b122014-11-19 00:22:58 +0000175 SanCovTraceBB = checkInterfaceFunction(
Kostya Serebryanyd421db02015-01-03 00:54:43 +0000176 M.getOrInsertFunction(kSanCovTraceBB, VoidTy, Int32PtrTy, nullptr));
Kostya Serebryanycb45b122014-11-19 00:22:58 +0000177 }
178
Kostya Serebryanyaa185bf2014-12-30 19:29:28 +0000179 // At this point we create a dummy array of guards because we don't
180 // know how many elements we will need.
181 Type *Int32Ty = IRB.getInt32Ty();
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000182 Type *Int8Ty = IRB.getInt8Ty();
183
Kostya Serebryanyaa185bf2014-12-30 19:29:28 +0000184 GuardArray =
185 new GlobalVariable(M, Int32Ty, false, GlobalValue::ExternalLinkage,
186 nullptr, "__sancov_gen_cov_tmp");
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000187 if (ClUse8bitCounters)
188 EightBitCounterArray =
189 new GlobalVariable(M, Int8Ty, false, GlobalVariable::ExternalLinkage,
190 nullptr, "__sancov_gen_cov_tmp");
Kostya Serebryanyaa185bf2014-12-30 19:29:28 +0000191
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000192 for (auto &F : M)
193 runOnFunction(F);
194
Kostya Serebryanyaa185bf2014-12-30 19:29:28 +0000195 // Now we know how many elements we need. Create an array of guards
196 // with one extra element at the beginning for the size.
197 Type *Int32ArrayNTy =
198 ArrayType::get(Int32Ty, SanCovFunction->getNumUses() + 1);
199 GlobalVariable *RealGuardArray = new GlobalVariable(
200 M, Int32ArrayNTy, false, GlobalValue::PrivateLinkage,
201 Constant::getNullValue(Int32ArrayNTy), "__sancov_gen_cov");
202
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000203
Kostya Serebryanyaa185bf2014-12-30 19:29:28 +0000204 // Replace the dummy array with the real one.
205 GuardArray->replaceAllUsesWith(
206 IRB.CreatePointerCast(RealGuardArray, Int32PtrTy));
207 GuardArray->eraseFromParent();
208
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000209 GlobalVariable *RealEightBitCounterArray;
210 if (ClUse8bitCounters) {
211 // Make sure the array is 16-aligned.
212 static const int kCounterAlignment = 16;
213 Type *Int8ArrayNTy =
214 ArrayType::get(Int8Ty, RoundUpToAlignment(SanCovFunction->getNumUses(),
215 kCounterAlignment));
216 RealEightBitCounterArray = new GlobalVariable(
217 M, Int8ArrayNTy, false, GlobalValue::PrivateLinkage,
218 Constant::getNullValue(Int8ArrayNTy), "__sancov_gen_cov_counter");
219 RealEightBitCounterArray->setAlignment(kCounterAlignment);
220 EightBitCounterArray->replaceAllUsesWith(
221 IRB.CreatePointerCast(RealEightBitCounterArray, Int8PtrTy));
222 EightBitCounterArray->eraseFromParent();
223 }
224
Kostya Serebryany88599462015-02-20 00:30:44 +0000225 // Create variable for module (compilation unit) name
226 Constant *ModNameStrConst =
227 ConstantDataArray::getString(M.getContext(), M.getName(), true);
228 GlobalVariable *ModuleName =
229 new GlobalVariable(M, ModNameStrConst->getType(), true,
230 GlobalValue::PrivateLinkage, ModNameStrConst);
231
Kostya Serebryanyaa185bf2014-12-30 19:29:28 +0000232 // Call __sanitizer_cov_module_init
Kostya Serebryany4cadd4a2014-11-24 18:49:53 +0000233 IRB.SetInsertPoint(CtorFunc->getEntryBlock().getTerminator());
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000234 IRB.CreateCall4(
235 SanCovModuleInit, IRB.CreatePointerCast(RealGuardArray, Int32PtrTy),
236 ConstantInt::get(IntptrTy, SanCovFunction->getNumUses()),
237 ClUse8bitCounters
238 ? IRB.CreatePointerCast(RealEightBitCounterArray, Int8PtrTy)
239 : Constant::getNullValue(Int8PtrTy),
240 IRB.CreatePointerCast(ModuleName, Int8PtrTy));
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000241 return true;
242}
243
244bool SanitizerCoverageModule::runOnFunction(Function &F) {
245 if (F.empty()) return false;
Kostya Serebryanyfea4fb42014-12-17 21:50:04 +0000246 if (F.getName().find(".module_ctor") != std::string::npos)
247 return false; // Should not instrument sanitizer init functions.
Kostya Serebryanycb45b122014-11-19 00:22:58 +0000248 if (CoverageLevel >= 3)
Chandler Carruth37df2cf2015-01-19 12:09:11 +0000249 SplitAllCriticalEdges(F);
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000250 SmallVector<Instruction*, 8> IndirCalls;
251 SmallVector<BasicBlock*, 16> AllBlocks;
252 for (auto &BB : F) {
253 AllBlocks.push_back(&BB);
254 if (CoverageLevel >= 4)
255 for (auto &Inst : BB) {
256 CallSite CS(&Inst);
257 if (CS && !CS.getCalledFunction())
258 IndirCalls.push_back(&Inst);
259 }
260 }
261 InjectCoverage(F, AllBlocks, IndirCalls);
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000262 return true;
263}
264
265bool
266SanitizerCoverageModule::InjectCoverage(Function &F,
267 ArrayRef<BasicBlock *> AllBlocks,
268 ArrayRef<Instruction *> IndirCalls) {
269 if (!CoverageLevel) return false;
270
Kostya Serebryany77cc7292015-02-04 01:21:45 +0000271 if (CoverageLevel == 1) {
272 InjectCoverageAtBlock(F, F.getEntryBlock(), false);
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000273 } else {
274 for (auto BB : AllBlocks)
Kostya Serebryany77cc7292015-02-04 01:21:45 +0000275 InjectCoverageAtBlock(F, *BB,
276 ClCoverageBlockThreshold < AllBlocks.size());
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000277 }
278 InjectCoverageForIndirectCalls(F, IndirCalls);
279 return true;
280}
281
282// On every indirect call we call a run-time function
283// __sanitizer_cov_indir_call* with two parameters:
284// - callee address,
285// - global cache array that contains kCacheSize pointers (zero-initialized).
286// The cache is used to speed up recording the caller-callee pairs.
287// The address of the caller is passed implicitly via caller PC.
288// kCacheSize is encoded in the name of the run-time function.
289void SanitizerCoverageModule::InjectCoverageForIndirectCalls(
290 Function &F, ArrayRef<Instruction *> IndirCalls) {
291 if (IndirCalls.empty()) return;
292 const int kCacheSize = 16;
293 const int kCacheAlignment = 64; // Align for better performance.
294 Type *Ty = ArrayType::get(IntptrTy, kCacheSize);
295 for (auto I : IndirCalls) {
296 IRBuilder<> IRB(I);
297 CallSite CS(I);
298 Value *Callee = CS.getCalledValue();
299 if (dyn_cast<InlineAsm>(Callee)) continue;
300 GlobalVariable *CalleeCache = new GlobalVariable(
301 *F.getParent(), Ty, false, GlobalValue::PrivateLinkage,
302 Constant::getNullValue(Ty), "__sancov_gen_callee_cache");
303 CalleeCache->setAlignment(kCacheAlignment);
304 IRB.CreateCall2(SanCovIndirCallFunction,
305 IRB.CreatePointerCast(Callee, IntptrTy),
306 IRB.CreatePointerCast(CalleeCache, IntptrTy));
307 }
308}
309
Kostya Serebryany83ce8772015-03-05 01:20:05 +0000310void SanitizerCoverageModule::SetNoSanitizeMetada(Instruction *I) {
311 I->setMetadata(
312 I->getParent()->getParent()->getParent()->getMDKindID("nosanitize"),
313 MDNode::get(*C, None));
314}
315
Kostya Serebryany77cc7292015-02-04 01:21:45 +0000316void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
317 bool UseCalls) {
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000318 BasicBlock::iterator IP = BB.getFirstInsertionPt(), BE = BB.end();
319 // Skip static allocas at the top of the entry block so they don't become
320 // dynamic when we split the block. If we used our optimized stack layout,
321 // then there will only be one alloca and it will come first.
322 for (; IP != BE; ++IP) {
323 AllocaInst *AI = dyn_cast<AllocaInst>(IP);
324 if (!AI || !AI->isStaticAlloca())
325 break;
326 }
327
Kostya Serebryanyd421db02015-01-03 00:54:43 +0000328 bool IsEntryBB = &BB == &F.getEntryBlock();
329 DebugLoc EntryLoc =
330 IsEntryBB ? IP->getDebugLoc().getFnDebugLoc(*C) : IP->getDebugLoc();
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000331 IRBuilder<> IRB(IP);
332 IRB.SetCurrentDebugLocation(EntryLoc);
Kostya Serebryanyaa185bf2014-12-30 19:29:28 +0000333 SmallVector<Value *, 1> Indices;
334 Value *GuardP = IRB.CreateAdd(
335 IRB.CreatePointerCast(GuardArray, IntptrTy),
336 ConstantInt::get(IntptrTy, (1 + SanCovFunction->getNumUses()) * 4));
337 Type *Int32PtrTy = PointerType::getUnqual(IRB.getInt32Ty());
338 GuardP = IRB.CreateIntToPtr(GuardP, Int32PtrTy);
Kostya Serebryany77cc7292015-02-04 01:21:45 +0000339 if (UseCalls) {
340 IRB.CreateCall(SanCovWithCheckFunction, GuardP);
341 } else {
342 LoadInst *Load = IRB.CreateLoad(GuardP);
343 Load->setAtomic(Monotonic);
344 Load->setAlignment(4);
Kostya Serebryany83ce8772015-03-05 01:20:05 +0000345 SetNoSanitizeMetada(Load);
Kostya Serebryany77cc7292015-02-04 01:21:45 +0000346 Value *Cmp = IRB.CreateICmpSGE(Constant::getNullValue(Load->getType()), Load);
347 Instruction *Ins = SplitBlockAndInsertIfThen(
348 Cmp, IP, false, MDBuilder(*C).createBranchWeights(1, 100000));
349 IRB.SetInsertPoint(Ins);
350 IRB.SetCurrentDebugLocation(EntryLoc);
351 // __sanitizer_cov gets the PC of the instruction using GET_CALLER_PC.
352 IRB.CreateCall(SanCovFunction, GuardP);
353 IRB.CreateCall(EmptyAsm); // Avoids callback merge.
354 }
Kostya Serebryanyd421db02015-01-03 00:54:43 +0000355
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000356 if(ClUse8bitCounters) {
357 IRB.SetInsertPoint(IP);
358 Value *P = IRB.CreateAdd(
359 IRB.CreatePointerCast(EightBitCounterArray, IntptrTy),
360 ConstantInt::get(IntptrTy, SanCovFunction->getNumUses() - 1));
361 P = IRB.CreateIntToPtr(P, IRB.getInt8PtrTy());
Kostya Serebryany83ce8772015-03-05 01:20:05 +0000362 LoadInst *LI = IRB.CreateLoad(P);
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000363 Value *Inc = IRB.CreateAdd(LI, ConstantInt::get(IRB.getInt8Ty(), 1));
Kostya Serebryany83ce8772015-03-05 01:20:05 +0000364 StoreInst *SI = IRB.CreateStore(Inc, P);
365 SetNoSanitizeMetada(LI);
366 SetNoSanitizeMetada(SI);
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000367 }
368
Kostya Serebryanyd421db02015-01-03 00:54:43 +0000369 if (ClExperimentalTracing) {
370 // Experimental support for tracing.
371 // Insert a callback with the same guard variable as used for coverage.
372 IRB.SetInsertPoint(IP);
373 IRB.CreateCall(IsEntryBB ? SanCovTraceEnter : SanCovTraceBB, GuardP);
374 }
Kostya Serebryany29a18dc2014-11-11 22:14:37 +0000375}
376
377char SanitizerCoverageModule::ID = 0;
378INITIALIZE_PASS(SanitizerCoverageModule, "sancov",
379 "SanitizerCoverage: TODO."
380 "ModulePass", false, false)
381ModulePass *llvm::createSanitizerCoverageModulePass(int CoverageLevel) {
382 return new SanitizerCoverageModule(CoverageLevel);
383}