<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68260>68260</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong code at -O2 on x86_64-linux_gnu since 3ddd1ff
</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 produced the wrong code.
Bisected to 3ddd1ffb721dd0ac3faa4a53c76b6904e862b7ab, which was committed by @nikic
Compiler explorer: https://godbolt.org/z/rEv69ovMj
```console
% cat a.c
int printf(const char *, ...);
char *a;
long b, c, d, m;
int e, f, j, l;
short g;
int *k = &j;
int main() {
int *n[] = {&f, &f, &f, &f, &f, &e};
d = 0;
for (; d <= 1; d++) {
g = 0;
for (; g <= 4; g++) {
char h[] = {0, 0, 4};
char *i = h;
a = i;
do {
a++;
b /= 10;
} while (b);
c = a - i;
while (i < a){
*i = *(i+1);
i++;
}
*k ^= c;
k = n[d + g];
l ^= m;
}
}
printf("%d\n", e);
}
%
% clang -O0 a.c && ./a.out
0
% clang -O2 a.c && ./a.out
1
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVM2O4ygQfprKpRQLFzaODz7kZ3JbzXGPIwzEpoeYyMbTPfv0K0jiTtK7q5WsMtTf9xUUJafJdoMxDZQ7KA8rOYfej83US7_uZ7l2dtV6_btRTg4dyoDr74SX0etZGY2hN_g--qFD5bXJgB2Aba9yZyejQvTxyLXW-enUVpRrzaTiJykLWXJViVbUrDAbQW0lW6A9vvdW9fguJ1T-fLYhpmh_IxRssD-twkeMvT9frDMjmo-L86MZgW-xD-EyAd8CHYGOndetdyHzYwd0_AvoOH77JWr_64-3x0wg2PVTfpi8MzctlahkQJmpq8IOAS-jHcIJaBNdA6pejgi0jdyzLAOqge-u3neTXDQuHlUqU0Whozgv1pjdRNUpirco3GKcej8G7J6cgbY_EfgBgcTbk-Us7QC0AaoRqpse8RYzXO_6GlntgEQC_B9_A9VhwUHUKQV70Jx8rHgDfJeM-2jP0w5ol74nQojdlxRPSbp7kiLt_iUJXm-hf66LRdJJFM-0lwCgrU3e_adVJoV9cdf-FRFR3tjwF32LsfVi4ezFBtUh9rczsbz2sVVupBK2xPUX_CUq8t1H6PoLn6Wa1I0bC7TLnzDsPxKOZ_O4TT1VfouJ1Ivrtdli-2gEivdRvp6ru8eenwwPIA_L5SkBEVCpodwPabmP7-CT-RICVD68zDSS1t9ZfJ-xO4EEZkBHmfk5XP3YV3f6D_f8FeY-Fla64brmtVyZJhe1KEpeklj1jW7NJufcCMHbXLKK1SdZ6arIW13UJS9WtiFGPGesoJyVVGRaauKiNEJpfioFQcHMWVqXOffrHOfUyk7TbBqxIcFWTrbGTWk6Ew3mHZMxHlJ5WI1NjFm3czdBwZydwvSZJdjgTPPnMp3vw9sP-LERP0SxdnaYP350w4yTHZS5j-nVPLrmZYra0M9tpvwZ6BgRbr_1ZfRvRgWgY-I1AR0T778DAAD__7bsnzk">