https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101578
Bug ID: 101578 Summary: wrong code with "-O3 -fpack-struct" Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: suochenyao at 163 dot com Target Milestone: --- ******************************************************************************* OS and Platform: CentOS Linux release 7.8.2003 (Core), x86_64 GNU/Linux ******************************************************************************* Program: int printf(const char *, ...); struct a { short b; long c; }; union { int d; struct a c; } e = {0505355}; int main() { e.c.c = 0; printf("%d\n", e.d); } ******************************************************************************* gcc version: $ gcc -v Using built-in specs. COLLECT_GCC=/data/bin/gcc-dev/bin/gcc COLLECT_LTO_WRAPPER=/data/bin/gcc-dev/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../configure --prefix=/data/bin/gcc-dev --disable-multilib --enable-languages=c,c++ Thread model: posix Supported LTO compression algorithms: zlib gcc version 12.0.0 20210721 (experimental) (GCC) git version: e4d306cf706eef83f99d510c308eda1539d05875 ******************************************************************************* Command Lines: $ gcc -O0 a.c -o a.out0 $ gcc -O3 -fpack-struct -Wall -Wextra -fno-strict-aliasing -fwrapv a.c -o a.outf $ ./a.out0 166637 $ ./a.outf 35565