Skip to content

Wrong code at -O2/3/s on x86_64-linux_gnu since 45ecfed #69096

@shao-hua-li

Description

@shao-hua-li

clang at -O2/3/s produced the wrong code.

Bisected to 45ecfed, which was committed by @FabianWolff

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

% cat a.c
int printf(const char *, ...);
int a, b;
short c;
unsigned short e = 65535;
static short f;
static char g[10][1][4];
static long h = -10;
unsigned short *i = &e;
long j(long k, long l) {
  long d = k + l;
  return k ? d - 1 : 9;
}
void n() {
  int m = 0;
  --g[0][0][2];
  c = 0;
  for (; c >= 0; c--)
    for (; h + *i - 65525 + m >= 0; m--) {
      f = 2;
      for (; f < 4; f++)
        g[(char)j(91, *i - 65625)][*i + c - 65535][f] = 5;
    }
}
int main() {
  n();
  printf("%d\n", g[0][0][2]);
}
%
% clang -O0 a.c && ./a.out
5
% clang -O2 a.c && ./a.out
-1
%

Metadata

Metadata

Assignees

Labels

llvm:analysisIncludes value tracking, cost tables and constant foldingmiscompilation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions