public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110141] New: Wrong code at -O2 on x86_64-linux-gnu
@ 2023-06-06 12:00 shaohua.li at inf dot ethz.ch
  2023-06-06 17:32 ` [Bug middle-end/110141] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-06-06 12:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110141
           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: ---

For the following code, gcc since 12 emits the wrong code at -O2.

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

$ cat a.c
int printf(const char *, ...);
int h, i = 1, m;
int *j = &i, *k = &i, *l;
short n(short b, short c, int d) {
  short e[] = {71, c, c, 40, 28, 57, 3, 8, 79, 19, c};
  int f = d, a = b;
  short *g = e;
  while (f > 1) {
    a += *g++;
    f -= 2;
  }
  a += *g -= 255;
  return a;
}
int fn2() {
  h = 0;
  for (;; h = 5) {
    int o[4];
    m = 0;
    for (; m < 4; m++)
      o[n(6, 7, 19) - 70 + m] = 6;
    if (h) {
      for (;;) {
        int p = 0;
        if (*k)
          break;
        l = &p;
      }
      *j = o[0];
      return 0;
    }
  }
}
int main() {
  fn2();
  printf("%d\n", i);
}
$
$ gcc-tk -O0 a.c && ./a.out
6
$ gcc-tk -O2 a.c && ./a.out
0
$

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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-06 12:00 [Bug c/110141] New: Wrong code at -O2 on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
2023-06-06 17:32 ` [Bug middle-end/110141] " pinskia at gcc dot gnu.org
2023-07-30 14:28 ` shaohua.li at inf dot ethz.ch
2023-12-17 23:14 ` [Bug middle-end/110141] [12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-03-08 15:35 ` law at gcc dot gnu.org
2024-03-12 13:24 ` jakub at gcc dot gnu.org
2024-06-20  9:12 ` [Bug middle-end/110141] [12/13/14/15 " rguenth 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).