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

            Bug ID: 111383
           Summary: Wrong code at -Os on x86_64-linux-gnu since
                    r12-5138-ge82c382971
           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
                CC: aldyh at redhat dot com
  Target Milestone: ---

gcc at -Os produced the wrong code.

Bisected to r12-5138-ge82c382971

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

$ cat a.c
int printf(const char *, ...);
int a, d = 1625015426;
char e;
short b;
short *f = &b, *g = &b;
void h(char *k) {
  char c = *k;
  for (; c;)
    ;
}
int main() {
  *g = 25330;
  int i, j;
  i = 0;
  for (; *f + d - 1625040257 < 7;)
    ;
  for (; i < 4; i++) {
    j = 0;
    for (; (d - 1625015511) + (d - 1625015341) + j < 1; j++)
      h(&e);
  }
  printf("%d\n", a);
}
$
$ gcc -O0 a.c && ./a.out
0
$ gcc -Os a.c && ./a.out
(Timeout)
$
$ gcc -fsanitize=address,undefined a.c && ./a.out
0
$

Reply via email to