https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64990
Bug ID: 64990 Summary: wrong code at -O1, -O2 and -O3 on x86_64-linux-gnu Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: su at cs dot ucdavis.edu The current gcc trunk miscompiles the following code on x86_64-linux at -O1, -O2 and -O3 in both 32-bit and 64-bit modes. It also affects 4.6.x through 4.9.x. $ gcc-trunk -v Using built-in specs. COLLECT_GCC=gcc-trunk COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-trunk/configure --prefix=/usr/local/gcc-trunk --enable-languages=c,c++ --disable-werror --enable-multilib Thread model: posix gcc version 5.0.0 20150209 (experimental) [trunk revision 220527] (GCC) $ $ gcc-trunk -O0 small.c; a.out $ $ gcc-trunk -O1 small.c $ ./a.out Segmentation fault (core dumped) $ -------------------------- static int a = 770, c, f; int b, d, e = 1, h, i, j; static int fn1 () { int g[1]; c = 0; for (;;) { if (e) break; return g[(a + 1) * 6 + (f + 1) * 3 + 1]; } if (b) return d; return 0; } int main () { h = fn1 (); if (j) i = 0; return 0; }