https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121901
Bug ID: 121901
Summary: Incorrect line coverage for multi-line while loop
condition
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: si1krow at outlook dot com
Target Milestone: ---
Hit the issue when measuring coverage for the following Debian code:
1. https://sources.debian.org/src/bzip2/1.0.8-5/blocksort.c#L514
2. https://sources.debian.org/src/bzip2/1.0.8-5/blocksort.c#L528
3. https://sources.debian.org/src/bzip2/1.0.8-5/blocksort.c#L542
How to reproduce it:
$ gcc --version
gcc (GCC) 16.0.0 20250907 (experimental)
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cat > test.c << 'EOF'
#include <stdlib.h>
int foo(int a) {
return 1;
}
void main() {
int* ptr = malloc(sizeof(int));
int j = 0;
while(foo(
ptr[j])) {
return;
}
}
EOF
$ gcc --coverage test.c -o test
$ ./test
$ gcov test
$ cat test.c.gcov
...
1: 2:int foo(int a) {
1: 3: return 1;
-: 4:}
1: 5:void main() {
1: 6: int* ptr = malloc(sizeof(int));
1: 7: int j = 0;
2: 8: while(foo(
1: 9: ptr[j])) {
1: 10: return;
-: 11: }
-: 12:}
...
Line coverage at line 8 should not be 2 but 1.