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

            Bug ID: 110233
           Summary: Wrong code at -Os 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 regression since GCC-12.

Compiler explorer: https://godbolt.org/z/8ab6hz9e1

$ cat a.c
int a, b = 1691021644, c = 1790785003;
short d;
short e() {
  for (; c + 18446744073709551608UL + b - 1691021644 + 18446744073709551608UL -
             1790784987 <=
         2;) {
    int *f[2];
    int g = 0;
    for (; b + (b - 1691021644) - 1691021636 + g < 2; g++)
      f[g] = &a;
    int **h = &f[1];
    d = b;
    if (d)
      ;
    else
      **h = 0;
    return b;
  }
  return 1;
}
int main() { e(); }
$
$ gcc-tk -Os a.c && ./a.out
Segmentation fault
$ gcc-tk -O0 a.c && ./a.out
$
$ gcc-tk -O0 -fsanitize=address,undefined a.c && ./a.out
$

Reply via email to