Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

llvm-cov: unused methods of template classes are not shown as uncovered #41080

Open Quuxplusone opened 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR42110
Status NEW
Importance P enhancement
Reported by Dennis Felsing (dennis.felsing@sap.com)
Reported on 2019-06-03 03:37:25 -0700
Last modified on 2019-06-04 05:20:59 -0700
Version trunk
Hardware PC Linux
CC dblaikie@gmail.com, htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
$ cat x.cpp
template<typename T>
struct C
{
    C(T x)
    : v(x)
    {
    }

    void foo(T x)
    {
        v = x;
    }

    T v;
};

int main()
{
    C<int> c(5);
}

$ clang++ -fprofile-instr-generate -fcoverage-mapping x.cpp -o x
$ ./x
$ llvm-profdata merge -sparse default.profraw -o default.profdata
$ llvm-cov show ./x -instr-profile=default.profdata
    1|       |template<typename T>
    2|       |struct C
    3|       |{
    4|       |    C(T x)
    5|       |    : v(x)
    6|      1|    {
    7|      1|    }
    8|       |
    9|       |    void foo(T x)
   10|       |    {
   11|       |        v = x;
   12|       |    }
   13|       |
   14|       |    T v;
   15|       |};
   16|       |
   17|       |int main()
   18|      1|{
   19|      1|    C<int> c(5);
   20|      1|}

I would expect foo to be considered uncovered, but since the method is inside
of a template class it is apparently not generated when it's also not used. If
the class is non-templated foo is shown correctly as being uncovered.
Quuxplusone commented 5 years ago

I'm guessing this is probably by design - member function templates that aren't called aren't instantiated & might not be valid instantiations (consider something like std::list::sort - not all Ts are sortable, so it's not necessarily reasonable to say "list::sort" is lacking coverage when it's not valid at all)

Quuxplusone commented 5 years ago

My way of considering this is that these are lines of code that could be executed, but they are not. So if your target is to know how many percent code coverage your software has, this behavior distorts it.