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

    <tr>
        <th>Summary</th>
        <td>
            function dynamically allocating an object is incorrectly marked as nonexecutable with clang gcov on Windows
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Hi,
I am using clang gcov to measure code coverage in a C++ project. On Windows I am facing a problem. If a function contains dynamic allocation of an object, the whole function is marked as nonexecutable. It can be replicated with this code:
```
#include <stdio.h>
class tt{
    public:
        tt(){
            puts("tt");
        }
};

void foo(){
    puts("foo");
}

int main(int argc, char **argv){
    foo();
    tt *t = new tt();
    foo();
    return 0;
}
```
I run these commands:
```
clang++.exe --coverage bad.cpp
a.exe
llvm-cov.exe gcov -t a-bad.gcno
```
and this is the result:
```
foo
tt
foo
        -:    0:Source:bad.cpp
        -:    0:Graph:a-bad.gcno
        -:    0:Data:a-bad.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include <stdio.h>
        -:    2:class tt{
        -:    3:    public:
        1:    4:        tt(){
        1:    5:            puts("tt");
        1:    6:        }
        -:    7:};
        -:    8:
        2:    9:void foo(){
        2:   10:    puts("foo");
        2:   11:}
        -:   12:
        -:   13:int main(int argc, char **argv){
        -:   14:    foo();
        -:   15:    tt *t = new tt();
        -:   16:    foo();
        -:   17:    return 0;
        -:   18:}
```
The `main` function was executed, but is marked as nonexecutable. There is still a possibility that I am doing something wrong, but following the same steps on Linux gives me expected results:
```
foo
tt
foo
        -:    0:Source:bad.cpp
        -:    0:Graph:bad.gcno
        -:    0:Data:bad.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include <stdio.h>
        -:    2:class tt{
        -:    3:    public:
        1:    4:        tt(){
        1:    5:            puts("tt");
        1:    6:        }
        -:    7:};
        -:    8:
        2:    9:void foo(){
        2:   10:    puts("foo");
        2:   11:}
        -:   12:
        1:   13:int main(int argc, char **argv){
        1:   14:    foo();
        1:   15:    tt *t = new tt();
        1:   16:    foo();
        1:   17:    return 0;
    #####:   18:}
```
Also if I create the object on the stack, the result on windows is as expected:
```
        -:    0:Source:bad.cpp
        -:    0:Graph:a-bad.gcno
        -:    0:Data:a-bad.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include <stdio.h>
        -:    2:class tt{
        -:    3:    public:
        1:    4:        tt(){
        1:    5:            puts("tt");
        1:    6:        }
        -:    7:};
        -:    8:
        2:    9:void foo(){
        2:   10:    puts("foo");
        2:   11:}
        -:   12:
        1:   13:int main(int argc, char **argv){
        1:   14:    foo();
        -:   15://    tt *t = new tt();
        1:   16:    tt t;
        1:   17:    foo();
        1:   18:    return 0;
        -:   19:}

```
I tried this with clang 12 installed from MSVS 2019 and clang 18.1.6 downloaded from https://github.com/llvm/llvm-project/releases

The source-based  code coverage also provides expected results, but I am facing different problems with it. 

Can you please help me with this?

Thank you

Pavel
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWE9v47YS_zT0ZRBDovz34IOTvLwX4BVddBfteUSOJO5SpEFSdvLtC0qyLTt24m7bWwJDYjQ_ksPhzI_DQe9VaYhWbHrPpo8jbEJl3eoLbkmvjXT03Y9yK19X_1OMP7DkkSXrZ8AaGq9MCUKjKaEUdgvBQk3oG0cgrIyPLTksCZQBhAfG7xm_h42z30mEMfxq4A9lpN15aMcrUMQBMSJyTfUYngtAKBojgrIGhDUBlfEgXw3WSgBqbQW2MlsAGrB5HJnxBwgVwa6ymo7dlYca3Q-SgB6MNfRCogmYaxrDcwCBBnICRxutBAaSsFOhglAp366GZetu7WyW9L_uX54pI3QjCVj24INUdlyx7D-dVGj0HkJg8_vuAwDApsm1EocBof8LgfEF48sT7P5v0wTfinmE8QjLzmBs_tirNH88CLvn1ioJhbU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