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

            Bug ID: 111210
           Summary: Wrong code at -Os on x86_64-linux-gnu since
                    r12-4849-gf19791565d7
           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: ---

gcc at -Os produces the wrong code.

Bisected to r12-4849-gf19791565d7

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

$ cat a.c
int printf(const char *, ...);
int a;
int *b = &a;
int c(long *d) {
  if (*d)
    return *(int *)0;
  return *(int *)(d + 1);
}
int main() {
  long e[] = {0, 100};
  int f = c(e);
  *b = f;
  printf("%d\n", a);
}
$
$ gcc -O3 a.c && ./a.out
100
$ gcc -Os a.c && ./a.out
0
$

Reply via email to