Skip to content

Wrong code at -O1/2/3 on x86_64-linux_gnu (recent regression) #70509

@shao-hua-li

Description

@shao-hua-li

clang at -O1/2/3 miscompiled the test.

Bisected to a66051c, which was committed by @aemerson

Compiler explorer: https://godbolt.org/z/8sMj8G9z9

% cat a.c
int printf(const char *, ...);
int a, d, e = 35435;
char b;
long c;
unsigned j;
short k, l;
int m(int n) {
  char f[] = {0, 9};
  char *g = f, *i = g;
  long h = n;
  do
    *i++ = h /= 10;
  while (h);
  c = i - g;
  while (g < i)
    b = *g++;
  a = c;
  return c;
}
void o(int n) {
  k = e;
  l = (j = k) > n;
  if (l)
    d = 3;
}
void p() {
  int q = m(17);
  o(q + 65533);
}
int main() {
  p();
  printf("%d\n", d);
}
%
% clang -O0 a.c && ./a.out
3
% clang -O1 a.c && ./a.out
0
%

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions