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

            Bug ID: 123067
           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 20251202 (experimental) (GCC)
$
$
$ gcc-trunk small.c -O0 ; ./a.out
0
$ gcc-trunk small.c -O1 ; ./a.out
0
$ gcc-trunk small.c -O2 ; ./a.out
1
$ gcc-trunk small.c -O3 ; ./a.out
1
$
$ cat small.c
int printf (const char *, ...);

int a[6] = {0, 0, 1, 2, 0, 0};
unsigned char i, j;

int main() {
    for (i = 1; i != 0; ++i) {
        for (j = 1; j <= 4; j++) {
            a[j] = a[j + 1];
        }
    }
    printf("%d\n", a[1]);
}


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

Reply via email to