<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/70510>70510</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong code at -O2/3 on x86_64-linux_gnu (recent regression)
</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 produced the wrong code.
Bisected to 98e016d99732dc8fef8cfd61d6ce1edd042309a1, which was committed y @fhahn
Compiler explorer: https://godbolt.org/z/6W5ExaWPM
```console
% cat a.c
int printf(const char *, ...);
int a, b, c;
long d;
unsigned short e;
short f = 5;
int *g = &a;
short(h)(short j, short k) { return j % k; }
int *l() {
long m = 0;
int i = 0;
for (; i < 1; --d)
for (; m <= 7; m++) {
int n;
for (; i < 6; i++)
;
e = h(f++, 4);
*g = !e;
n = m == e;
if (n)
return &c;
}
return &b;
}
int main() {
l();
printf("%d\n", a);
}
%
% clang -O0 a.c && ./a.out
1
% clang -O2 a.c && ./a.out
0
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VE2TozgM_TXiogpli4_AgUM-Nret2dscpxzbgHuInTJmu2d__ZYhQ5P01qYoYktP7wnJlhhH01mtGyiOUJwTMYXe-Wbshdv1k9gNJrk69auRg7AdioC7bwR0yfDunZqkVhh6je_e2Q6lUzoFdgZ2WN5HM2oZIsZhXWnGS1XX-4yUrFrdVrJVJVel1FwrxXLKWC040AnfeyN7fBcjSne7mRApfiHkrO1Fb3ErcXK3uxm0R_1xH5zXHrID9iHcR8gOQBegS-fU1Q0hdb4DuvwDdCm_F398iO9__bllgpItj3R2dIN-WKlAKQKKVD50jQ1498aGFqiK2ICyFx6BDjH3NE2BasiOn2gR7df4kqt9iAVT63aycxsUjr3zAfXqWPYtQnbG4okV6NDNZqBSPOOBqj4mQdUS_ha1l-VPoBphf0Svw-QtvmH8wp-QHRH25yf2Aah6oBc74pz1bVZlqyRiDDBfrK2LRakidXSekMflbqdiag_MEyoSnyLLft4BHefnKYP4i3J2I_RCs4iV83Ll2GIRX4L1nHsPVLW_A06Yb9v4CPssOdcvPjs75trExavbtDE9-yWTRxuASvkUsTZjC7mukKde3YSx_9GrxbRhXU8tEAEVCoqTnZeneETrr-RAxeYWzBNg940td4FKoBJToItI3RQWHP8Kp_-Bs1eZ31cwUU2m6qwWiW54WVd5zuqKJ31TFXu6Zmyvi30r67xoZS6K_MqrTHLecp6YhhhlnNGeOKtznlZZwUnXmVQl41K3kDN9E2ZIh-HvW5wJiRnHSTd7VnCWDOKqh3EehkRWv-PsjEUqzolvYszuOnUj5GwwYxg_WYIJg26-r4NwOyudxY-q_FHmu8HY6eNHZ6d4GryW2gb0uvN6HI2LpyOZ_NC8zC8T-umaSncDukS9x9_u7t2blgHoMmc5Al3mr_g3AAD__4mhjII">