<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/95630>95630</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
wrong code at -O1/-O2 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>
tangyixuan01
</td>
</tr>
</table>
<pre>
Hi, Clang-18 produces the wrong code when compiling the following code with "-O1" or "-O2", while outputting the correct results under the compilations "-O3".
$ clang -O2 s.c; ./a.out
0
$ clang -O3 s.c; ./a.out
1
$ gcc -O2 s.c; ./a.out
1
$ cat s.c
int printf(const char *, ...);
long a;
int b, c, e, g, i;
long *d, *h;
char f = 6;
int main() {
long j;
c = 0;
for (; c != 7; ++c) {
long k;
long **l = &d;
for (; f + i; i++)
h = &k;
g = h != (*l = &j);
int *m = &b;
*m = g;
for (; e; a = a + 1)
;
}
printf("%d\n", b);
}
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VM1yszgQfJrhMmVKDD-GAwc7Ltfe8ghbQghQVpZcSMTJ229JtgnerXyXAc30dLcGJO6cGo2ULZRHKE8JX_xk59ZzM36rr4UbliWd7b_bvxTQG75pbsZdVuN1tv0ipEM_SbzN1owobC_xNkmDwl6uSiszxupgtbY3tSKUnxCIdu8ZEKGd7wsCoqBwm5SWaBd_Xbx_Ugg7z1J4nKVbtHe4mF7Oj0qQ4l5Z4-5EORClwE7ADo9IBYrgG3fvhC4VkB8xBTrz1C7-jmG_NeS_NGT_bRiF-AP__-CC-wjdpJXxeJ2V8QNQLaxxHsXEw3gOYTBpmgI1kB_vaB1GztdlaO4CTIQgQxhDUK8NQIc-pIEO01qJKgNCfsLqhfDClQGqgRqE_SOPkedjxSGK2Mk2mSF-1DrMQSBQFur7sAI6Ah3FKyHinfOfDcMjFbd-0FEAqOpfEBuVITDHvaK6a4RRrUjE6UnxKjLG9PT0GPf6I_exnXeAh5kAHS5PQPdSXSvjbzZlCDxieHSc_djc9MD-9Hxd_4d4OsoeyjfzOCjd1h3sT0nf5n2TNzyRbbbP6oIYq5tkavO-HySVWc3LuirLrmJ1UzdNx_eM8zLvEtUSo4JVWcmoLIomlYWoBjFUVGaNqGqCgskLVzrV-vOS2nlMlHOLbJuyylmieSe1ixcIkZE3jMXgsjwlcxt6dt0yOiiYVs67HxavvJbt5vbgHuO1cA4nyRr8qqu_q2KnlVm-dqNZkmXW7eT91UF-ADoDnUflp6VLhb0AnQPz47G7zvZDCg90jn4c0Pnu97OlfwMAAP__kTdU9A">