https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113232
Bug ID: 113232
Summary: wrong code at -fpack-struct on x86_64-pc-linux-gnu
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jwzeng at nuaa dot edu.cn
Target Milestone: ---
I compiled the following code with gcc at -fpack-struct, and it produces the
wrong code.
The correct output result should be 0, but 2048 was output under -fpack-struct.
This bug seems to be a long-standing bug that exists on almost all gcc
versions.
Compiler explorer: https://godbolt.org/z/v4sq988P9
```c
$ cat test.c
int printf(const char *, ...);
struct a {
char b;
short c;
};
union {
short b;
struct a d;
} e;
int main() {
e.b = 0;
for (e.d.c = 0; e.d.c < 8; e.d.c++)
;
printf("%d\n", e.b);
}
$
$ gcc-tk test.c -O0; ./test.c
0
$ gcc-tk test.c -fpack-struct; ./test.c
2048
$ ccomp test.c -O0; ./a.out
0
$
$ gcc-tk --version
gcc (GCC) 13.1.0
Copyright (C) 2023 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.
$
$ ccomp --version
The CompCert C verified compiler, version 3.12
```