<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/88709>88709</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Source-based coverage: __llvm_profile_reset_counters bug
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
m-carrasco
</td>
</tr>
</table>
<pre>
Hi :wave:
`__llvm_profile_reset_counters` is not working as expected for clang-14 and clang-17 (Ubuntu/x86-64).
I expect it to reset any coverage that happened *before* its invocation. Nevertheless it is losing track of successive lines' coverage.
Example:
```
#include <iostream>
extern "C" void __llvm_profile_reset_counters(void);
void bar(){
printf("Executing bar\n");
}
void foo(){
printf("Executing foo\n");
}
int main(int argc, char *argv[]) {
__llvm_profile_reset_counters();
bar();
foo();
return 0;
}
```
Steps:
1. `clang++ -fprofile-instr-generate -fcoverage-mapping main.cpp`
2. `./a.out`
3. `llvm-profdata merge -sparse default.profraw -o default.profdata`
4. `llvm-cov-14 show ./a.out -instr-profile=default.profdata`
Output:
```
1| |#include <iostream>
2| |
3| |extern "C" void __llvm_profile_reset_counters(void);
4| |
5| 1|void bar(){
6| 1| printf("Executing bar\n");
7| 1|}
8| |
9| 1|void foo(){
10| 1| printf("Executing foo\n");
11| 1|}
12| |
13| 0|int main(int argc, char *argv[]) {
14| 0| __llvm_profile_reset_counters();
15| 0| bar();
16| 0| foo();
17| 0| return 0;
18| 0|}
```
Lines 15, 16 and 17 are expected to have at least one counter, as it is the case for lines 6 and 10. All these lines are executed _after_ `__llvm_profile_reset_counters`.
Best regards,
Manuel
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk-PqzgM_zTpxQJBoEAPHDqdqXal_XN42nNlgoHsowlKQmfet1-FobTdmc68WW1VheLYP_9ix3bRWtkqopKtH9j6cYWj67Qpj4FAY9AKvap0_aP8RQJLts94IpZsWfTIovOaRYd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