[llvm-cov gcov] Fix calculating coverage of template functions
authorIgor Kudrin <ikudrin@accesssoftek.com>
Tue, 15 Mar 2022 16:46:22 +0000 (20:46 +0400)
committerIgor Kudrin <ikudrin@accesssoftek.com>
Tue, 15 Mar 2022 16:46:22 +0000 (20:46 +0400)
commit1c99f650a7ac90c80ffd4830e05cd3408e64f42c
tree76ec36934d404272cd65a39bab7bd345eca6cdc8
parent6583f01707211ed14d8e35f2183a8805a301b6f9
[llvm-cov gcov] Fix calculating coverage of template functions

Template functions share the same lines in source files, so the common
container of lines' properties cannot be used to calculate the coverage
statistics of individual functions.

> cat tmpl.cpp
template <int N> int test() { return N; }
int main() { return test<1>() + test<2>(); }
> clang++ --coverage tmpl.cpp -o tmpl
> ./tmpl
> llvm-cov gcov tmpl.cpp -f
...
Function '_Z4testILi1EEiv'
Lines executed:100.00% of 1

Function '_Z4testILi2EEiv'
Lines executed:-nan% of 0
...
> llvm-cov-patched gcov tmpl.cpp -f
...
Function '_Z4testILi1EEiv'
Lines executed:100.00% of 1

Function '_Z4testILi2EEiv'
Lines executed:100.00% of 1
...

Differential Revision: https://reviews.llvm.org/D121390
llvm/lib/ProfileData/GCOV.cpp
llvm/test/tools/llvm-cov/gcov/Inputs/tmpl.cpp [new file with mode: 0644]
llvm/test/tools/llvm-cov/gcov/Inputs/tmpl.gcda [new file with mode: 0644]
llvm/test/tools/llvm-cov/gcov/Inputs/tmpl.gcno [new file with mode: 0644]
llvm/test/tools/llvm-cov/gcov/tmpl.test [new file with mode: 0644]