Skip to content

[clang] Miscompilation at -O2/3 #128528

@cardigan1008

Description

@cardigan1008

This code prints 3333 at -O0/1 and -2147483648 at -O2/3:

int printf(const char *, ...);
int a, b, c;
long double d;
int f(int g, int i) {
  int e = g + i;
  e++;
  return e;
}
int j() {
  int h = -1;
  if (b)
    return h;
  return 0;
}
void k(int g) { a = -66 + g - 38; }
int main() {
  int l, m = j();
  l = f(m + 34, m + 80) + m - 112 + m;
  k(l + 38 - 37 + 38);
  d = 4 + a - -66;
  a = c = d * 4.16666666666666666019e02;
  printf("%d\n", c);
}

Compiler Explorer: https://godbolt.org/z/TnK1bWcGd

Bisected to 15a7de6, which was committed by @goldsteinn

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions