public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111319] New: Wrong code at -O2 on x86_64-linux-gnu
@ 2023-09-07  7:38 shaohua.li at inf dot ethz.ch
  2023-09-07  7:40 ` [Bug c/111319] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-09-07  7:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111319
           Summary: Wrong code at -O2 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: ---

The executable produced by gcc -O2 would crash. Not sure if there is UB in the
code or not as `h` has not been dereferenced after `h--`.

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

$ cat a.c
int printf(const char *, ...);
int a, b = 5, c, d;
int e[2] = {0, 0};
int i() {
  int f = 0;
  int g[2] = {1, f};
  int *h = g;
  h--;
  if (!b)
    while (h >= &c == 1)
      h--;
  h++;
  d = *h;
  return d;
}
int main() {
  if (e[i()])
    e[0] = 0;
  printf("%d\n", a);
}
$
$ gcc -O2 a.c && ./a.out
Segmentation fault
$

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

end of thread, other threads:[~2023-09-07  8:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-07  7:38 [Bug c/111319] New: Wrong code at -O2 on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
2023-09-07  7:40 ` [Bug c/111319] " pinskia at gcc dot gnu.org
2023-09-07  7:59 ` pinskia at gcc dot gnu.org
2023-09-07  8:01 ` xry111 at gcc dot gnu.org
2023-09-07  8:09 ` shaohua.li at inf dot ethz.ch

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).