https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123310

            Bug ID: 123310
           Summary: wrong code at -O2 and above on x86_64-pc-linux-gnu
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xintong.zhou1 at uwaterloo dot ca
  Target Milestone: ---

$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/x27zhou/compilers/gcc-trunk-install/libexec/gcc/x86_64-pc-linux-gnu/16.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --enable-checking=yes --disable-bootstrap
--disable-multilib --disable-shared --enable-languages=c,c++
--prefix=/home/x27zhou/compilers/gcc-trunk-install
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.0.0 20251226 (experimental) (GCC)
$
$ gcc-trunk small.c -O0 ; ./a.out
5
$ gcc-trunk small.c -O1 ; ./a.out
5
$ gcc-trunk small.c -O2 ; ./a.out
0
$ gcc-trunk small.c -O3 ; ./a.out
0
$
$ cat small.c
int printf (const char *, ...);
struct a {
  short b;
} c[7], e;
int d;
static struct a f[3][2] = {{}, {}, 5, 5};
void g() {
  for (; e.b >= 0; e.b--) {
    c[e.b + 6] = f[2][1];
    d = c[6].b;
  }
}
int main() {
  g();
  printf("%d\n", d);
}

Compiler Explorer: https://godbolt.org/z/bz9qh57cW

Reply via email to