Skip to content

Wrong code at -O1 on x86_64-linux_gnu since LLVM-13 #76789

Closed
@shao-hua-li

Description

@shao-hua-li

Clang at -O1 produces the wrong code since LLVM-13.

Bisected to 8f3d169, which was committed by @efriedma-quic

Compiler explorer: https://godbolt.org/z/35no4xxfK

% cat a.c
int printf(const char *, ...);
char a;
short b;
static short *c = &b;
static short **f = &c;
int g;
int h(char *j, long k) {
  int d = 0;
  char *e = j + k;
  for (; j < e; j++)
    d = (d << 4) + *j;
  return d;
}
int l(char j, long k) {
  int i = h(&j, k);
  return i;
}
int m(void);
void n() { m(); }
int m() {
  int o;
  char p = b = 4;
  for (;;) {
    g = 0;
    for (; g <= 4; g++) {
      p = 0;
      for (; p <= 5; p++)
        o = l(1, **f - 3);
      a = (6 || 0) & o;
    }
    break;
  }
  short ***s = &f, ***q = s;
  return &s != &q;
}
int main() {
  n();
  printf("%d\n", a);
}
%
% clang -O0 a.c && ./a.out
1
% clang -O1 a.c && ./a.out
0
%

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions