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

            Bug ID: 110252
           Summary: Wrong code at -O2/3/s on x86_64-linux-gnu
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This seems to be a recent regression. 

Compiler explorer: https://godbolt.org/z/TW97cdYxv

$ cat a.c
int printf(const char *, ...);
int d, f;
const char a = 239;
short e, b, h = 2;
long g;
short *c = &e;
int *i = &f;
int(j)(int k, int l) { return k < 0 ? k : k >> l; }
int main() {
  for (;;) {
    g = (char)d + a;
    b = h && j(g, 6);
    *c = b;
    *i = e;
    break;
  }
  printf("%d\n", f);
}
$
$ gcc-tk -O0 a.c && ./a.out
1
$ gcc-tk -O1 a.c && ./a.out
1
$ gcc-tk -O2 a.c && ./a.out
-1
$ gcc-tk -O3 a.c && ./a.out
-1
$ gcc-tk -Os a.c && ./a.out
-1
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-bf470895905e9152424076d1630a9d2c60de023b/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-bf470895905e9152424076d1630a9d2c60de023b
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230612 (experimental) (GCC) 
$

Reply via email to