Skip to content

[clang] Miscompile with -O3 and -O0/1/2 since 18.1.0 #115149

@cardigan1008

Description

@cardigan1008

When I compiled this code with -O0/1/2, its output is 0. However, with -O3, it returned 143:

int printf(const char *, ...);
char a, b;
int c;
char *e = &b;
int f(char *g, int *k) {
  char *d = g + *k;
  for (; *d && *d <= ' '; d++)
    ;
  if (*d)
    return 0;
  return 1;
}
int l(int g) {
  char h[] = {a, a, a};
  int i[] = {g};
  int j = f(h, i);
  return j;
}
long m() {
  *e = 255;
  for (; l(b + 1);)
    return 0;
  for (;;)
    ;
}
int main() {
  m();
  printf("%d\n", c);
}

Details can be found here: https://godbolt.org/z/dnvvTPror

Metadata

Metadata

Labels

llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmiscompilation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions