llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.68k stars 11.86k forks source link

clang coverage misses member functions #60152

Open SebastianTaube opened 1 year ago

SebastianTaube commented 1 year ago

When compiling for target x86_64-pc-windows-msvc, a lot of member functions are not taken into account for coverage instrumentation. I could reproduce the occurence with the following minimal example:

struct Test
{
  void testfunction();
};

struct A
{
  ~A(){};
};

struct B
{
  B(){};
};

void Test::testfunction()
{
  A a;
  B b;
}

Steps for compiling / looking at coverage metadata:

$ clang --target=x86_64-pc-windows --coverage -c test.cpp

$ llvm-cov gcov -dump test.gcno
===== ??0B@@QEAA@XZ (0) @ test.cpp:13
Block : 0 Counter : 0
    Destination Edges : 2 (0), 
Block : 1 Counter : 0
    Source Edges : 2 (0), 
Block : 2 Counter : 0
    Source Edges : 0 (0), 
    Destination Edges : *1 (0), 
    Lines : 13,
===== ??1A@@QEAA@XZ (1) @ test.cpp:8
Block : 0 Counter : 0
    Destination Edges : 2 (0), 
Block : 1 Counter : 0
    Source Edges : 2 (0), 
Block : 2 Counter : 0
    Source Edges : 0 (0), 
    Destination Edges : *1 (0), 
    Lines : 8,
File 'test.cpp'
Lines executed:0.00% of 2
Creating 'test.cpp.gcov'

$ cat test.cpp.gcov 
        -:    0:Source:test.cpp
        -:    0:Graph:test.gcno
        -:    0:Data:-
        -:    0:Runs:0
        -:    0:Programs:0
        -:    1:struct Test
        -:    2:{
        -:    3:  void testfunction();
        -:    4:};
        -:    5:
        -:    6:struct A
        -:    7:{
    #####:    8:  ~A(){};
        -:    9:};
        -:   10:
        -:   11:struct B
        -:   12:{
    #####:   13:  B(){};
        -:   14:};
        -:   15:
        -:   16:void Test::testfunction()
        -:   17:{
        -:   18:  A a;
        -:   19:  B b;
        -:   20:}

As can be seen, the member function testfunction() is considered as non executable code. In the following cases, however, the function is considered as executable:

Behaviour was seen on:

amir-s2 commented 4 days ago

Any update?