https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121242
Bug ID: 121242
Summary: [GCOV] Wrong coverage for "break" inside
switch-structure.
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: njuwy at smail dot nju.edu.cn
Target Milestone: ---
gcc version:
gcc version 16.0.0 20250704 (experimental) (GCC)
cmd:
gcc --coverage -std=c2x -lm -O0 test.c -o test
./test
gcov ./*.gcda -t > test.c.gcov
$ cat test.c
#include <stdlib.h>
#include <assert.h>
int main(void) {
struct Point {
int x, y;
};
struct Point origin = { .y = 0 }, *p = &(struct Point){ .x = 1, .y = 2 };
for (int i = 0; i < 3; i++) {
switch (i) {
case 0:
p = &origin;
break;
case 1:
p = &(struct Point){ .x = 3, .y = 4 };
break;
default: p = &(struct Point){ .x = 5, .y = 6 };
}
}
return 0;
}
$ cat test.c.gcov
-: 1:#include <stdlib.h>
-: 2:#include <assert.h>
1: 3:int main(void) {
-: 4: struct Point {
-: 5: int x, y;
-: 6: };
1: 7: struct Point origin = { .y = 0 }, *p = &(struct Point){ .x
= 1, .y = 2 };
4: 8: for (int i = 0; i < 3; i++) {
3: 9: switch (i) {
1: 10: case 0:
1: 11: p = &origin;
2: 12: break;
1: 13: case 1:
1: 14: p = &(struct Point){ .x = 3, .y = 4 };
1: 15: break;
1: 16: default: p = &(struct Point){ .x = 5, .y = 6 };
-: 17: }
-: 18: }
1: 19: return 0;
-: 20:}
Line 12 was only executed once but its cov was wrongly marked as 2.