Skip to content

[clang] Miscompile at -O2/3 #129181

Closed
@cardigan1008

Description

@cardigan1008

This code prints random value at -O2/3 and 92 at -O0/1:

int printf(const char *, ...);
int a, c, d, e;
int b[0];
int f() {
  d = 7;
  for (; 4 + d; d--)
    e += 92 & 1 << d;
  return e;
}
int main() {
  int g = f();
  printf("%d\n", g);
  c = b[g];
}

Compiler Explorer: https://godbolt.org/z/9oa95vEjY

It starts from clang-13.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions