https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123139
Bug ID: 123139
Summary: wrong coverage with aligned attribute on struct
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: jiangchangwu at smail dot nju.edu.cn
Target Milestone: ---
*******************************************************************************
gcc version:
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/compiler/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/16.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++ --prefix=/compiler/gcc-trunk --enable-coverage
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.0.0 20251204 (experimental) (GCC)
*******************************************************************************
Program:
$ cat prog.c
struct a {
int c;
} __attribute__((aligned)) a;
int c;
struct {
struct a b;
} *b = (void *)&c;
int main() {
b->b = a;
}
*******************************************************************************
Wrong coverage:
$ gcc-trunk -w -O0 -fprofile-arcs -ftest-coverage prog.c -o prog && ./prog &&
/compiler/gcc-trunk/bin/gcov prog.c && cat prog.c.gcov
File 'prog.c'
Lines executed:0.00% of 2
Creating 'prog.c.gcov'
Lines executed:0.00% of 2
-: 0:Source:prog.c
-: 0:Graph:prog.gcno
-: 0:Data:prog.gcda
-: 0:Runs:1
-: 1:struct a {
-: 2: int c;
-: 3:} __attribute__((aligned)) a;
-: 4:int c;
-: 5:struct {
-: 6: struct a b;
-: 7:} *b = (void *)&c;
#####: 8:int main() {
#####: 9: b->b = a;
-: 10:}
Line #9 was marked as not executed.
But when I used llvm-cov, the result is shown as follow:
$ clang-trunk -w -O0 -fcoverage-mapping -fprofile-instr-generate=prog.c.profraw
prog.c -o prog && ./prog && /compiler/llvm-trunk/bin/llvm-profdata merge
prog.c.profraw -o prog.c.profdata && /compiler/llvm-trunk/bin/llvm-cov sho
w prog -instr-profile=prog.c.profdata prog.c
1| |struct a {
2| | int c;
3| |} __attribute__((aligned)) a;
4| |int c;
5| |struct {
6| | struct a b;
7| |} *b = (void *)&c;
8| 1|int main() {
9| 1| b->b = a;
10| 1|}
Line #9 was marked as executed once.
I also found that after removing __attribute__((aligned)) from struct a, line
#9 was marked as executed once by gcov.