public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111422] New: Wrong code at -O3 on x86_64-linux-gnu
@ 2023-09-15  7:42 shaohua.li at inf dot ethz.ch
  2023-09-15 12:20 ` [Bug tree-optimization/111422] " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-09-15  7:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111422
           Summary: Wrong code at -O3 on x86_64-linux-gnu
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -O3 produced the wrong code.

Compiler explorer: https://godbolt.org/z/3b4v478TG

$ cat a.c
int printf(const char *, ...);
int a, b;
int *c = &b;
unsigned d;
char e;
int f=1;
int i(int k, char *l) {
  if (k < 6)
    return a;
  l[0] = l[1] = l[k - 1] = 8;
  return 0;
}
int m(int k) {
  char g[11];
  int h = i(k, g);
  return h;
}
int main() {
  for (; b < 8; b = b + 1)
    ;
  int j;
  int *n[8];
  j = 0;
  for (;18446744073709551608U + m(*c) + *c + j < 2; j++){
    n[j] = &f;
  }
  for (; e <= 4; e++)
    d = *n[0] == f;
  printf("%d\n", d);
}
$
$ gcc -O0 a.c && ./a.out
1
$ gcc -O3 a.c && ./a.out
Segmentation fault
$ gcc -O3 -fwrapv a.c && ./a.out 
Segmentation fault
$ gcc -fsanitize=address,undefined a.c && ./a.out
1
$

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-06-20 13:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-15  7:42 [Bug tree-optimization/111422] New: Wrong code at -O3 on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
2023-09-15 12:20 ` [Bug tree-optimization/111422] " rguenth at gcc dot gnu.org
2023-09-15 12:26 ` rguenth at gcc dot gnu.org
2023-09-15 12:35 ` rguenth at gcc dot gnu.org
2024-01-16 10:51 ` [Bug middle-end/111422] " cvs-commit at gcc dot gnu.org
2024-03-02  0:38 ` cvs-commit at gcc dot gnu.org
2024-05-15 16:13 ` cvs-commit at gcc dot gnu.org
2024-06-11 10:36 ` cvs-commit at gcc dot gnu.org
2024-06-20 13:22 ` cvs-commit at gcc dot gnu.org
2024-06-20 13:27 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).