Bug 110141 - [12/13/14/15 Regression] Wrong code at -O2 on x86_64-linux-gnu
Summary: [12/13/14/15 Regression] Wrong code at -O2 on x86_64-linux-gnu
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 14.0
: P2 normal
Target Milestone: 12.5
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on: 111843
Blocks:
  Show dependency treegraph
 
Reported: 2023-06-06 12:00 UTC by Shaohua Li
Modified: 2024-06-20 09:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-12-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shaohua Li 2023-06-06 12:00:34 UTC
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
$
Comment 1 Andrew Pinski 2023-06-06 17:32:41 UTC
Another -fstack-reuse= issue.
Comment 2 Shaohua Li 2023-07-30 14:28:39 UTC
I tried to bisect this case and I bisected it to r12-4790-g4b3a325f07a
Comment 3 Andrew Pinski 2023-12-17 23:14:21 UTC
Confirmed.
Comment 4 Jakub Jelinek 2024-03-12 13:24:40 UTC
GCC 12-13 has been released with this bug, so P2.
Comment 5 Richard Biener 2024-06-20 09:12:51 UTC
GCC 12.4 is being released, retargeting bugs to GCC 12.5.