Skip to content

[clang] Miscompile with -O2/3/s #124387

@cardigan1008

Description

@cardigan1008

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

int printf(const char *, ...);
int a, b;
void c(char d) { a = d; }
int e(int d) {
  if (d < 0)
    return 1;
  return 0;
}
int f() {
  if (b)
    return 0;
  return 1;
}
int g(int d) {
  int h = 0;
  if (3 + d)
    h = f() - 1 - 1;
  return e(h) + h + h;
}
int main() {
  int i = g(0);
  c(i);
  printf("%d\n", a);
}

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

It starts from x86_64 clang 19.1.0.

Metadata

Metadata

Assignees

Labels

llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmiscompilationregression:19Regression in 19 release

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions