summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2015-06-30 23:11:45 +0000
committerAlexey Samsonov <vonosmas@gmail.com>2015-06-30 23:11:45 +0000
commit342b1e8053ef493d174aa9227df8a82ed022ee68 (patch)
treec139a27c79edf0d4a9a60325acbd0ed24e1159c7
parent3e32a4e717c054275dd2062fc3b2551ac56e0c49 (diff)
downloadbcm5719-llvm-342b1e8053ef493d174aa9227df8a82ed022ee68.tar.gz
bcm5719-llvm-342b1e8053ef493d174aa9227df8a82ed022ee68.zip
[SanitizerCoverage] Don't add instrumentation to unreachable blocks.
llvm-svn: 241127
-rw-r--r--llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp7
-rw-r--r--llvm/test/Instrumentation/SanitizerCoverage/coverage.ll9
2 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index dff39efa5b9..7a5b4cb0178 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -375,6 +375,13 @@ void SanitizerCoverageModule::SetNoSanitizeMetadata(Instruction *I) {
void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
bool UseCalls) {
+ // Don't insert coverage for unreachable blocks: we will never call
+ // __sanitizer_cov() for them, so counting them in
+ // NumberOfInstrumentedBlocks() might complicate calculation of code coverage
+ // percentage. Also, unreachable instructions frequently have no debug
+ // locations.
+ if (isa<UnreachableInst>(BB.getTerminator()))
+ return;
BasicBlock::iterator IP = BB.getFirstInsertionPt(), BE = BB.end();
// Skip static allocas at the top of the entry block so they don't become
// dynamic when we split the block. If we used our optimized stack layout,
diff --git a/llvm/test/Instrumentation/SanitizerCoverage/coverage.ll b/llvm/test/Instrumentation/SanitizerCoverage/coverage.ll
index b2f0ab0680b..659c03040f2 100644
--- a/llvm/test/Instrumentation/SanitizerCoverage/coverage.ll
+++ b/llvm/test/Instrumentation/SanitizerCoverage/coverage.ll
@@ -119,3 +119,12 @@ entry:
; CHECK4: call void @__sanitizer_cov_indir_call16({{.*}},[[CACHE:.*]])
; CHECK4-NOT: call void @__sanitizer_cov_indir_call16({{.*}},[[CACHE]])
; CHECK4: ret void
+
+define void @call_unreachable() uwtable sanitize_address {
+entry:
+ unreachable
+}
+
+; CHECK4-LABEL: define void @call_unreachable
+; CHECK4-NOT: __sanitizer_cov
+; CHECK4: unreachable
OpenPOWER on IntegriCloud