<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69096>69096</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong code at -O2/3/s on x86_64-linux_gnu since 45ecfed
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shao-hua-li
</td>
</tr>
</table>
<pre>
clang at -O2/3/s produced the wrong code.
Bisected to 45ecfed6c636d06f76bca0a44803e945cdae9506, which was committed by @FabianWolff
Compiler explorer: https://godbolt.org/z/jT73jv5aG
```console
% 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
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VMGOozgQ_ZriUgKZAhs4cOgkyx7nstIcR8aY4B4HR2Cme_brV3bSSTrqWQnFlfKr8qt6dsl1NcdZ6xb4DvghkZuf3NKuk3TptMnUmqR3w-9WWTkfUXpMvxFQVwB1K54XN2xKD-gnjW-Lm4-o3KAzYAdgL5ffnVm18gHjsORajXoQShRiYGKsRK8kk2VZs0I3JVeD1A1nAmiPb5NRE77JFZU7nYwPKfrfCCXrZG_k_N3ZccTHk_budDZWL6jfz9YteoHiBSfvzysUL0AdUHd0Q--sz9xyBOr-Bepe_6mK119c_v2YCQS7fMrNq7P66iWOSnqUmbo4zOzxvJjZj0B1gHpUk1w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