https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120478
Bug ID: 120478
Summary: Line coverage gets multiplied by a factor when
invoking inline functions
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: wentaoz5 at illinois dot edu
Target Milestone: ---
Hit the issue when measuring
https://sources.debian.org/src/lz4/1.9.4-1/lib/lz4.c/#L985
https://sources.debian.org/src/lzo2/2.10-3/src/lzo1x_c.ch/#L176
etc.
How to reproduce:
$ gcc --version
gcc (GCC) 16.0.0 20250511 (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'
__inline__ __attribute__((__always_inline__))
int foo() { return 0; }
int main(void) {
int x = 0, y = 0;
for (int i = 0; i < 42; i++) {
x++; y += foo();
// x++;
}
}
EOF
$ gcc --coverage test.c -o test
$ ./test
$ gcov test
$ cat test.c.gcov
-: 0:Source:test.c
-: 0:Graph:test.gcno
-: 0:Data:test.gcda
-: 0:Runs:1
-: 1:__inline__ __attribute__((__always_inline__))
42: 2:int foo() { return 0; }
-: 3:
1: 4:int main(void) {
1: 5: int x = 0, y = 0;
43: 6: for (int i = 0; i < 42; i++) {
84: 7: x++; y += foo();
-: 8: // x++;
-: 9: }
-: 10:}
Line coverage for line 7 gets multiplied by 2 from its ground truth.
Uncommenting the statement that follows, or cancelling inline reverts
the behavior:
43: 6: for (int i = 0; i < 42; i++) {
42: 7: x++; y += foo();
42: 8: x++;
-: 9: }
43: 6: for (int i = 0; i < 42; i++) {
42: 7: x++; y += foo_noinline();
-: 8: // x++;
-: 9: }