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

            Bug ID: 115492
           Summary: [15 Regression] wrong code at -O2/O3 when compiled
                    with -fPIC
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tangyixuan at mail dot dlut.edu.cn
  Target Milestone: ---

Hi, I find that GCC-15 produces the possible wrong code when compiling the
following code with "-O3 -fPIC". However, GCC-13 could get the correct output
with the same compilation flags.

$ gcc-13 -O3 -fPIC s.c; ./a.out
0
$ gcc -O3 -fPIC s.c; ./a.out
2

$ gcc --version
gcc (GCC) 15.0.0 20240602 (experimental)
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat s.c

extern int printf(const char *format, ...);
int a = 2, b=0, *c = &a, *d = &a, e=0;
void f() {}
void h(int *k) {
  int ***j;
  if (b) {
    *j = &k;
    ***j;
  }
  f(*k);
  *d = e;
  printf("%d\n",*k);
}
int main() { h(c); }

Reply via email to