<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60152>60152</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang coverage misses member functions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          SebastianTaube
      </td>
    </tr>
</table>

<pre>
    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:

- Swap lines 18 and 19, so B is constructed before A
- Remove destructor from class A
- Remove constructor from class B
- Set option `--target=x86_64-linux-gnu` when compiling on Windows
- Do not set option `--target=x86_64-pc-windows` when compiling on Linux

Behaviour was seen on:
- `Ubuntu clang version 14.0.0-1ubuntu1`
- `clang version 13.0.0 ` shipped by Visual Studio 17.1.0
- `clang version 15.0.6 ` downloaded from github



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV92uozYQfhrnZgSyDfm7yAU52VQr7UW7Z9utelMZM0ncBRvZJjl702evDIEkJNk9D9AIYYI_fzP-bM8Mwjm114grMl2T6WYiGn8wdvWKuXBeCf1FNDlOclN8X309oAZpqlqVSu9hZyx4Yffo4W0x-3uWRrWMTkoX5uSiyh0l4S8goDQezA4qrHK0sGu09MpoB8IiaOPBi2-oQWlvQEhpGu1bZmmOaMUeQWnnbVOh9iIMjOEjSNOUBVisrSkaieAPCEbKxqKWCCflD-2rnSlLcwquVkqrSpSAb6KqSyRJRuiG0P4-o-er_RvMSQ9f0Plz_3zdPQAcjSrAo_P9PAhfEL4kybqHbi7P12zZHdW_2XnsfH0z6hnD-o5h_U6C1ul2OklGkuyB-2PmDMTAAWvIb8gfadbdXz3W7rx6_S4hfAulMd_Cs_CXZa3Qi0J4cVmLESNPQZZC7yGKul1Gks3dPoMoGhgj2a5MLOv6ZnV5CmV5rAIQ9uEWFU1Vd9i91OYMSzbXF5BkS5ItXZOUkpT-9iHLSEr__AsIX1DCl0BSejGXZCzpaNalkd-AJBlQeAmbGW33r3dpuUHnlW73Mnwo9ujaft4Th0MzpmJPqF5NYyW-l4W_l4Xeszz1m_CMPYR_UvoMYQnhLz8SmWUPRGYPRF78r_ETjReDxFtVIhA-H2Tj866jA-MbysZjQZKMxpQSPg3BmXeQF4vCd4d2GB-HIzOQXJ1N4eEGA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