[PATCH] D121390: [llvm-cov gcov] Fix calculating coverage of template functions
Igor Kudrin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 10 09:50:53 PST 2022
ikudrin created this revision.
ikudrin added reviewers: MaskRay, dblaikie, jhenderson.
ikudrin added a project: LLVM.
Herald added a subscriber: hiraditya.
Herald added a project: All.
ikudrin requested review of this revision.
Template functions share the same lines in source files, so the common container of lines' properties cannot be used to calculate the coverage of individual functions.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D121390
Files:
llvm/lib/ProfileData/GCOV.cpp
llvm/test/tools/llvm-cov/gcov/Inputs/tmpl.gcda
llvm/test/tools/llvm-cov/gcov/Inputs/tmpl.gcno
llvm/test/tools/llvm-cov/gcov/tmpl.cpp
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 N>
+int test(int k) {
+ return k * N;
+}
+
+int main() {
+ return test<1>(1) +
+ test<1>(2) +
+ test<2>(3);
+}
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<uint32_t, 16> lines;
+ llvm::SmallSet<uint32_t, 16> 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121390.414399.patch
Type: text/x-patch
Size: 1812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220310/0a8ed357/attachment.bin>
More information about the llvm-commits
mailing list