[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
Sun Mar 13 07:13:45 PDT 2022
ikudrin updated this revision to Diff 414932.
ikudrin marked an inline comment as done.
ikudrin retitled this revision from "[llvm-cov gcov] Fix calculating coverage of template functions" to "[llvm-cov gcov] Fix calculating coverage statistics of template functions".
ikudrin edited the summary of this revision.
ikudrin added a subscriber: jhenderson.
ikudrin added a comment.
- Fixed a formatting issue
- Updated the test
In D121390#3374554 <https://reviews.llvm.org/D121390#3374554>, @jhenderson wrote:
> FYI, there's a pre-merge test failure
That is probably because `tmpl.gcda` and `tmpl.gcno` are binaries and I do not know how to upload them to the review. I have tried `git diff --binary` for this patch, but with little success.
> and clang-format issue.
Thanks! Fixed.
In D121390#3374685 <https://reviews.llvm.org/D121390#3374685>, @MaskRay wrote:
> `curl -L 'https://reviews.llvm.org/D121390?download=1'` does not include the contents for tmpl.gcno and tmpl.gcda.
>
> So I just run:
>
> clang++ --coverage tmpl.cpp -o tmpl
> ./tmpl
> llvm-cov gcov tmpl.cpp -t
>
> I do not see a difference with and w/o the patch.
The patch fixes `-f`, not `-t`.
>> 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.
>
> Suppose there is indeed a difference. It's useful to attach a C++ program and line execution counts before and after this patch, for the relevant lines.
Added an example into the description.
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.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,13 @@
+// Check that the coverage statistics for a template function is calculated.
+
+// RUN: llvm-cov gcov %s --gcno=%p/Inputs/tmpl.gcno --gcda=%p/Inputs/tmpl.gcda -f | FileCheck %s
+
+// CHECK: Function '_Z4testILi1EEiv'
+// CHECK-NEXT: Lines executed:100.00% of 1
+// CHECK: Function '_Z4testILi2EEiv'
+// CHECK-NEXT: Lines executed:100.00% of 1
+
+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);
+ 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.414932.patch
Type: text/x-patch
Size: 1811 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220313/0b1e289e/attachment.bin>
More information about the llvm-commits
mailing list