Skip to content

Wrong code at -Os on x86_64 (recent regression since 6ed152a)  #66066

@shao-hua-li

Description

@shao-hua-li

Clang at -Os produced the wrong code.

Bisected to 6ed152a, which was committed by @caojoshua

Compiler explorer: https://godbolt.org/z/aMEWqd9dP

% cat a.c
int printf(const char *, ...);
int a, b, c;
long d;
const unsigned *e;
const unsigned **f[3];
static char(g)(unsigned h, int j) { return h > j ? h : h << j; }
static short k() {
  char l = 1;
  b = 0;
  for (; b <= 3; b++) {
    char *m = &l;
    int *n = &c;
    int i = 0;
    for (; i < 3; i++)
      f[i] = &e;
    *n = g((*m)--, 7);
    if (*n)
      ;
    else {
      for (; i < 9; i++)
        f[0] || (d = 2);
      if (0 < *n)
        ;
      else
        return 0;
    }
    printf("%d\n", *n);
  }
  return 1;
}
int main() {
  k();
}
%
% clang -O0 a.c && ./a.out
-128
0
% clang -Os a.c && ./a.out
-128
0
-128
0
%

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions