<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78920>78920</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Weird Clang's branch coverage with macros from system headers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chapuni
</td>
</tr>
</table>
<pre>
Clang eliminates whole MACRO expr in branch coverage.
(https://godbolt.org/z/3o9MTf4eW)
```
/* header.h */
#define ISN(c) ('0' <= (c) && (c) <= '9')
```
```
#include <header.h>
int isx(int c) {
return (ISN(c) || ('A' <= c && c <= 'F'));
}
```
```
clang -fprofile-instr-generate -fcoverage-mapping -Xclang -dump-coverage-mapping -isystem .
```
The emission of the record is as below; `ISN(c)` cannot be seen nor evaluated.
Could I see the condition of `ISN(c)`?
```
isx:
File 0, 9:16 -> 11:2 = #0
File 0, 10:23 -> 10:45 = #1
File 0, 10:24 -> 10:32 = #1
Branch,File 0, 10:24 -> 10:32 = #4, (#1 - #4)
File 0, 10:36 -> 10:44 = #4
Branch,File 0, 10:36 -> 10:44 = #5, (#4 - #5)
```
WIth `-fcoverage-mcdc`, `llvm-cov` crashes. (cc: @evodius96)
A workaround is adding `-mllvm -system-headers-coverage` to `clang`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVN2O4zYPfRrmhnAgS45_LnzhyayBudjvA9oFpreyxcRqbSmQ5JndPn0h29mk89MWCJJIPOQ5EA8pvddnQ1TD4QEOjzs5h8G6uh_kZTZ611n1oz6O0pyRRj1pIwN5fB3sSPi1Of7yf6TvF4faYOek6Qfs7Qs5eaY9sEdgzfbNyyGEiwfRAG-Bt2erOjuGvXVn4O2fwFthq6_fThk9A6-2pJxtn61GC7zBgaQitx8Q-HK1xYSikzaET7_-D3jZA68QeAm8YMALBHEE8Yi3SA48vx2v0aICXnzK_7EooU0_zopilas2EF_WsDYBtf8OvIz_VrLiYY0hIjoKszNRyL3u4gjFcZPf3Mnvr8L7O8ntJplXILbKUDx-LPbvx37panK6OHvSIyXa-OCSMxlyMhAmp2srk0leLjpif9ty1Dxdkvdh7X_4QBPuP-T7NhDSpL3X1qA9YRgIHfXWKdQepceORvsK4gEhZ7f3gJxhL42xATtCT2TQWIf0IsdZBlIb2dHOo8KnCFgq99YoHTaqtwVBtB9KjL0SzbU_rR4JGfAjViCaNMcExBdMUxANx_X5BXsPTlkEiA0dD9nhCk8_g2d3cMHfwR-W4QJ-_G95WQQsBhIpJttN9Qm3yO-lZrca_8L9Sd7hxp2t3Id_HqnnpzDEDt0brld9RMVKORvHlym6bXGCk34gv1-GtwfRIGSMXqzSs6_yn0QNvlr3h3R2Nqu7lIoOjSxTLIfJatVkHVn_08yRI9gIXKwOOdvvVC1UJSq5ozot2KEsM8aL3VBzVaZVLijLsoryNBM5KSU6WZ66NM97ttM1ZzxjKeeMxZx9xkiVXcHLnJ0Kdaii9knqcR81xWW4097PVBdlxdlulB2NflnMnK9yOI872tXLk3Tz2UPGRu2Dv1UIOoxUP5N2Co9rUuHfbmd81WHASfbOejw5O-E2utt77GY31m9Wtg7D3O17OwFvI9v2k1yc_Z36ALxdxHvg7aL_rwAAAP__yEC6Ew">