https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97493
Bug ID: 97493 Summary: generate wrong code with "-Os -fno-toplevel-reorder -frename-registers" Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: suochenyao at 163 dot com Target Milestone: --- Description: I think gcc generates wrong code with -Os -fno-toplevel-reorder -frename-registers. But no difference is found with optimization levels. No message and difference occurs with "gcc -Wall -Wextra" and "-fno-strict-aliasing -fwrapv" ******************************************************************************* OS and Platform: CentOS Linux release 7.8.2003 (Core), x86_64 GNU/Linux ******************************************************************************* Program: int printf(const char *, ...); union uuu{ short a; long b; } c={0}; long *d = &c.b; short *e = &c.a; short f=0; int main() { *d = 3; f = ++*e; printf("%d\n", c.a); } ******************************************************************************* Gcc Version: $ gcc -v Using built-in specs. COLLECT_GCC=/home/suocy/bin/gcc-dev/bin/gcc COLLECT_LTO_WRAPPER=/home/suocy/bin/gcc-dev/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../configure --prefix=/home/suocy/bin/gcc-dev --disable-multilib --enable-languages=c,c++ Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.0.0 20201018 (experimental) (GCC) ******************************************************************************* Command Line: $ gcc -Wall -Wextra -fno-strict-aliasing -fwrapv -O0 a.c -o a.out0 $ gcc -Wall -Wextra -fno-strict-aliasing -fwrapv -O1 a.c -o a.out1 $ gcc -Wall -Wextra -fno-strict-aliasing -fwrapv -O2 a.c -o a.out2 $ gcc -Wall -Wextra -fno-strict-aliasing -fwrapv -O3 a.c -o a.out3 $ gcc -Wall -Wextra -fno-strict-aliasing -fwrapv -Os a.c -o a.outs $ gcc -Wall -Wextra -fno-strict-aliasing -fwrapv -Os -fno-toplevel-reorder -frename-registers a.c -o a.outf $ ./a.out0 > out0 $ ./a.out1 > out1 $ ./a.out2 > out2 $ ./a.out3 > out3 $ ./a.outs > outs $ ./a.outf > outf $ diff out0 out1 $ diff out0 out2 $ diff out0 out3 $ diff out0 outs $ diff out0 outf 1c1 < 4 --- > 1