Index: lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- lib/CodeGen/CoverageMappingGen.cpp +++ lib/CodeGen/CoverageMappingGen.cpp @@ -645,6 +645,11 @@ } void VisitDecl(const Decl *D) { + // Do not visit unused functions. + if (const auto *FD = dyn_cast(D)) + if (FD->hasAttr()) + return; + Stmt *Body = D->getBody(); // Do not propagate region counts into system headers. Index: test/CoverageMapping/skip_unused_function.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/skip_unused_function.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s | count 0 + +void __attribute__((unused)) f1() {} + +template +class C1 { +public: + void __attribute__((unused)) m1() {} + + static void __attribute__((unused)) m2(T x) {} + + void __attribute__((unused)) m3(); +}; + +template +void C1::m3() { + C1 v1; + v1.m1(); + C1::m2(0.0); +}