-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Closed
Labels
llvm:analysisIncludes value tracking, cost tables and constant foldingIncludes value tracking, cost tables and constant foldingmiscompilation
Description
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 foldingIncludes value tracking, cost tables and constant foldingmiscompilation