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

            Bug ID: 123983
           Summary: wrong code at -O1 -fprofile-use 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=/data/x27zhou/compiler-nightly/install/gcc/libexec/gcc/x86_64-pc-linux-gnu/16.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /data/x27zhou/compiler-nightly/src/gcc/configure
--enable-checking=yes --disable-bootstrap --disable-multilib
--enable-languages=c,c++ --prefix=/data/x27zhou/compiler-nightly/install/gcc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.0.1 20260204 (experimental) (GCC)
$
$
$ gcc-trunk -O1 -fprofile-use small.c && ./a.out
0
$ gcc-trunk -O1 small.c && ./a.out
65280
$ gcc-trunk -O0 -fprofile-use small.c && ./a.out
65280
$
$ cat small.c
int printf (const char *, ...);
int a;
unsigned char b;
unsigned short c[1];
const int *d;
const int **e(short);
static short f(int, int **);
short h() {
  e(b);
  return 0;
}
const int **e(short a) {
  int *b;
  f(0, &b);
  return &d;
}
short f(int a, int **aw) {
a:
  b--;
  c[0]--;
  if (b)
    goto a;
}
int main() {
  h();
  printf("%d\n", c[a]);
}


It actually does not need a profile to reproduce.
Compiler Explorer: https://godbolt.org/z/bj7sYW8cn

Reply via email to