<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57813>57813</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong code at -O1 and -Os on x86_64-linux_gnu
</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>
```console
% clang-tk -v
clang version 16.0.0 (https://github.com/llvm/llvm-project.git 8f19de848b968bfdd237bdb6ffb65e7412bb6a0c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/shaoli/compilers/ccbuilder-compilers
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
%
% clang-tk -w -O0 a.c && ./a.out
-2
% clang-tk -w -O1 a.c && ./a.out
-7
% clang-tk -w -O2 a.c && ./a.out
-2
% clang-tk -w -Os a.c && ./a.out
-7
%
% cat a.c
int printf(const char *, ...);
short a[2][2] = {1};
short b;
char c[] = {4};
char d;
int e;
int f(int g) {
if (g & 1)
return g + 1;
return g;
}
int *h() {
b = 0;
for (; f(b - 2) + 2 >= 0; b--) {
d = 0;
for (; d <= 0; d++) {
a[1][b + 1]--;
if (a[1][b + 1]) {
if (c[b])
break;
return &e;
}
}
}
}
int main() {
h();
printf("%d\n", b);
}
```
Compiler explorer: https://godbolt.org/z/orYej9fn4
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVUuT4yYQ_jXShZJKoIelgw47dpzKKYekKpXTFggksYPBhdDMJL8-DZI1tnZ2K0mtC5lH9_d10w0NM_yvNqqypXVGT0aJKDtF2aeIlKhTVA-Je0bJy7IYFtCLsJM0GuEqzdIMRaQenbtOUQ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