https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128558
Bug ID: 128558
Summary: [GCOV] "case" label in switch-case with do-while is
wrongly counted
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: iamanonymous.cs at gmail dot com
Target Milestone: ---
This appears to be a regression of PR gcov-profile/85332, which was
previously closed as fixed but whose symptom reappears on current trunk.
Filed as a new report per the developer's request.
See also PR gcov-profile/85332.
$ gcc --version
gcc (GCC) 17.0.0 20261101 (experimental)
$ cat small.c
#include <stdlib.h>
int doit(int sel, int n, void *p)
{
int * const p0 = p;
switch (sel)
{
case 0:
do {*p0 += *p0;} while (--n);
return *p0 == 0;
default:
abort ();
}
}
int main()
{
int v0;
v0 = 1; doit(0, 3, &v0);
exit (0);
}
$ gcc -w --coverage small.c && ./a.out && gcov small.c
Actual (buggy) output:
1: 2:int doit(int sel, int n, void *p)
1: 4: int * const p0 = p;
1: 6: switch (sel)
3: 8: case 0: <- wrongly counted as 3
3: 9: do {*p0 += *p0;} while (--n);
1: 10: return *p0 == 0;
#####: 12: default:
#####: 13: abort ();
Line 8 ("case 0:") is entered only once from the switch dispatch, but it is
reported with count 3 (the same count as the do-while body, which
legitimately
runs 3 times). The case label itself should be reported as executed once.
Reproduced on gcc 11.4.0, 13.1.0 and 17.0.0 trunk.