<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/115149>115149</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Miscompile with -O3 and -O0/1/2 since 18.1.0
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cardigan1008
</td>
</tr>
</table>
<pre>
When I compiled this code with -O0/1/2, its output is 0. However, with -O3, it returned 143:
```c
int printf(const char *, ...);
char a, b;
int c;
char *e = &b;
int f(char *g, int *k) {
char *d = g + *k;
for (; *d && *d <= ' '; d++)
;
if (*d)
return 0;
return 1;
}
int l(int g) {
char h[] = {a, a, a};
int i[] = {g};
int j = f(h, i);
return j;
}
long m() {
*e = 255;
for (; l(b + 1);)
return 0;
for (;;)
;
}
int main() {
m();
printf("%d\n", c);
}
```
Details can be found here: https://godbolt.org/z/MKW3535W6
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyElE1vvDYQxj_NcBkF2QPm5cBhX7RqVf3VY87G9oJT1qywSdR--spAyG4TqRILrP2bmcePzUjvbeeMaUAcQZwTOYd-nBolJ2076ThjVdKO-u_mtTcOf0c13u52MBpDbz2qURv8sKHHlz8Z0IUDXQjohDZ4HOdwnwNajyzF38YP826mOLfx2crhZMI8OaOR5xlkB2BnYJ_3gq2XWv9bF_A-WReuQJUanQ-oejkh0CEmS9MUqIbsuNLLlIwT7T4WM6hnAuhgELIzAhXP4FJlQ7pFrQvx_S-gGqHcSNw16CVNh0DHFct25DpGooLsuIFUABWfQae1fBl_EdFAx-WqP-MRH5LZ65KLDvqJWI1E9kBuQ3wfgvL8tb4BqIrP7qf19OuBWJ0pj4uP2608P4pxAe0z230n3pa5aGi_GPm4T7vMt-8yh9F1eFtW-yRx3zQS4meb4-LaZSv4Vux_vPqKfYJ_tu4mrfuuahP6kHQ_rUAEJDSIk1teT6geyT35fuQfv4OzCdIOHpV02Bq8jrPT2JvJQHbAPoS7jx8OXYAu3ajbcQjpOHVAl3-ALr_-eM1EJl6LRDeZrrNaJqbhZcaqmrgQSd8wzXh5bYXkuRKkr0Urq7oQZVHltVbXPLENMco5ZwXnRJlIBb-WmpdKyaKtTM4hZ-Ym7ZAOw_st1k6s97NpOBc8r5NBtmbwS4shUoN0XfRAnJOpiQEv7dx5yNlgffBfKYINw9KX1ghxxl_Wb_1nbyIonX5sPuitUwZ5lfKUJfM0NP_xx4Z-blM13oAusdT2eLlP45tRAeiySPcx4ar-vaF_AwAA__9bKFv_">