Skip to content

Commit

Permalink
[asancov] Don't emit extra runtime calls when compiling without cover…
Browse files Browse the repository at this point in the history
…age.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209721 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
eugenis committed May 28, 2014
1 parent d8ba67b commit 0949668
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/Transforms/Instrumentation/AddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,9 +1030,11 @@ bool AddressSanitizerModule::runOnModule(Module &M) {
assert(CtorFunc);
IRBuilder<> IRB(CtorFunc->getEntryBlock().getTerminator());

Function *CovFunc = M.getFunction(kAsanCovName);
int nCov = CovFunc ? CovFunc->getNumUses() : 0;
IRB.CreateCall(AsanCovModuleInit, ConstantInt::get(IntptrTy, nCov));
if (ClCoverage > 0) {
Function *CovFunc = M.getFunction(kAsanCovName);
int nCov = CovFunc ? CovFunc->getNumUses() : 0;
IRB.CreateCall(AsanCovModuleInit, ConstantInt::get(IntptrTy, nCov));
}

size_t n = GlobalsToChange.size();
if (n == 0) return false;
Expand Down
4 changes: 4 additions & 0 deletions test/Instrumentation/AddressSanitizer/coverage.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; RUN: opt < %s -asan -asan-module -asan-coverage=0 -S | FileCheck %s --check-prefix=CHECK0
; RUN: opt < %s -asan -asan-module -asan-coverage=1 -S | FileCheck %s --check-prefix=CHECK1
; RUN: opt < %s -asan -asan-module -asan-coverage=2 -S | FileCheck %s --check-prefix=CHECK2
; RUN: opt < %s -asan -asan-module -asan-coverage=2 -asan-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK2
Expand All @@ -17,6 +18,9 @@ entry:
ret void
}

; CHECK0-NOT: call void @__sanitizer_cov(
; CHECK0-NOT: call void @__sanitizer_cov_module_init(

; CHECK1-LABEL: define void @foo
; CHECK1: %0 = load atomic i8* @__asan_gen_cov_foo monotonic, align 1
; CHECK1: %1 = icmp eq i8 0, %0
Expand Down

0 comments on commit 0949668

Please sign in to comment.