Open
Description
How to reproduce the bug ( Compiler explorer link: link )
cat > test.c << EOF
int main(){
int x = 0;
for (int i=0; ; i++)
{
if (x == 2){
break;
}
x++;
}
return 0;
}
EOF
clang -fprofile-instr-generate -fcoverage-mapping -isystem. test.c -o test
./test
llvm-profdata merge default.profraw -o default.profdata
llvm-cov show -instr-profile default.profdata test
which would produce:
1| 1|int main(){
2| 1| int x = 0; // N1
3| 2| for (int i=0; ; i++) // N2-N1
4| 3| { // N2
5| 3| if (x == 2){
6| 1| break;
7| 1| }
8| 2| x++;
9| 2| }
10| 1| return 0;
11| 1|}
The line before 'for' (Line number 2) has counter value N1.
The line after 'for' ( Line number 4) has counter value N2.
The line counter for 'for' ( Line number 3) is (N2-N1), which is hard to interpret.