[PATCH] D121390: [llvm-cov gcov] Fix calculating coverage statistics of template functions

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 15 09:48:25 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1c99f650a7ac: [llvm-cov gcov] Fix calculating coverage of template functions (authored by ikudrin).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121390/new/

https://reviews.llvm.org/D121390

Files:
  llvm/lib/ProfileData/GCOV.cpp
  llvm/test/tools/llvm-cov/gcov/Inputs/tmpl.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.test


Index: llvm/test/tools/llvm-cov/gcov/tmpl.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-cov/gcov/tmpl.test
@@ -0,0 +1,19 @@
+# Check that the coverage statistics for template functions are calculated as expected.
+
+RUN: rm -rf %t
+RUN: mkdir %t
+RUN: cd %t
+RUN: cp %p/Inputs/tmpl* .
+
+RUN: llvm-cov gcov tmpl.cpp -f | FileCheck %s --check-prefix=F
+RUN: llvm-cov gcov tmpl.cpp -t | FileCheck %s --check-prefix=T
+
+F:      Function '_Z4testILi1EEiv'
+F-NEXT: Lines executed:100.00% of 1
+F:      Function '_Z4testILi2EEiv'
+F-NEXT: Lines executed:100.00% of 1
+
+T:      -: 1:template <int N>
+T-NEXT: 2: 2:int test() { return N; }
+T-NEXT: -: 3:
+T-NEXT: 1: 4:int main() { return test<1>() + test<2>(); }
Index: llvm/test/tools/llvm-cov/gcov/Inputs/tmpl.cpp
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-cov/gcov/Inputs/tmpl.cpp
@@ -0,0 +1,4 @@
+template <int N>
+int test() { return N; }
+
+int main() { return test<1>() + test<2>(); }
Index: llvm/lib/ProfileData/GCOV.cpp
===================================================================
--- llvm/lib/ProfileData/GCOV.cpp
+++ llvm/lib/ProfileData/GCOV.cpp
@@ -13,6 +13,7 @@
 
 #include "llvm/ProfileData/GCOV.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Demangle/Demangle.h"
 #include "llvm/Support/Debug.h"
@@ -662,6 +663,8 @@
   if (f.startLine >= si.startLineToFunctions.size())
     si.startLineToFunctions.resize(f.startLine + 1);
   si.startLineToFunctions[f.startLine].push_back(&f);
+  SmallSet<uint32_t, 16> lines;
+  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.415481.patch
Type: text/x-patch
Size: 2231 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220315/f2870425/attachment.bin>


More information about the llvm-commits mailing list