Skip to content

Wrong code at -O2 on x86_64 (recent regression in GVN pass) #64598

@shao-hua-li

Description

@shao-hua-li

Clang at -O2 emits the wrong code.

Bisected to 84bcfa0, which was committed by @weiguozhi

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

% cat a.c
int printf(const char *, ...);
int a, d, e, f, h, j, t, q;
char c, s;
signed char g;
signed char *i = &g;
int *k = &h;
int **l = &k;
signed char **m = &i;
signed char ***r = &m;
static signed char ****n = &r;
long o, u;
int p[7];
void v() {
  t = 0;
  for (; t < 9; t++) {
    q = 0;
    for (; c + q; q++)
      p[q] = 3;
  }
}
void w(long x, char y) {
  for (; o;) {
    v();
    s = x;
    u = y;
  }
}
int main() {
  for (; d <= 3; d++) {
    e = 0;
    for (; e <= 3; e++) {
      int *b;
      f = 3;
      for (; f; f--) {
        w(****n, **l);
        b = &j;
        *b = **l + ***r;
      }
    }
  }
  for (; **l;)
    ;
  printf("%X\n", a);
}
%
% clang -O0 a.c  && ./a.out
0
% clang -O2 a.c && ./a.out
Segmentation fault
%

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions