Index: llvm/lib/ProfileData/GCOV.cpp =================================================================== --- llvm/lib/ProfileData/GCOV.cpp +++ llvm/lib/ProfileData/GCOV.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ProfileData/GCOV.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Config/llvm-config.h" #include "llvm/Demangle/Demangle.h" @@ -662,6 +663,8 @@ if (f.startLine >= si.startLineToFunctions.size()) si.startLineToFunctions.resize(f.startLine + 1); si.startLineToFunctions[f.startLine].push_back(&f); + llvm::SmallSet lines; + llvm::SmallSet linesExec; for (const GCOVBlock &b : f.blocksRange()) { if (b.lines.empty()) continue; @@ -670,9 +673,9 @@ si.lines.resize(maxLineNum + 1); for (uint32_t lineNum : b.lines) { LineInfo &line = si.lines[lineNum]; - if (!line.exists) + if (lines.insert(lineNum).second) ++summary.lines; - if (line.count == 0 && b.count) + if (b.count && linesExec.insert(lineNum).second) ++summary.linesExec; line.exists = true; line.count += b.count; Index: llvm/test/tools/llvm-cov/gcov/tmpl.cpp =================================================================== --- /dev/null +++ llvm/test/tools/llvm-cov/gcov/tmpl.cpp @@ -0,0 +1,17 @@ +// RUN: llvm-cov gcov %p/Inputs/tmpl.gcda --gcno=%p/Inputs/tmpl.gcno -f | FileCheck %s + +// CHECK: Function '_Z4testILi1EEii' +// CHECK-NEXT: Lines executed:100.00% of 2 +// CHECK: Function '_Z4testILi2EEii' +// CHECK-NEXT: Lines executed:100.00% of 2 + +template +int test(int k) { + return k * N; +} + +int main() { + return test<1>(1) + + test<1>(2) + + test<2>(3); +}