<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/70509>70509</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong code at -O2 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 -O1/2/3 miscompiled the test.
Bisected to a66051c68a43af39f9fd962f71d58ae0efcf860d, which was committed by @aemerson
Compiler explorer: https://godbolt.org/z/8sMj8G9z9
```console
% cat a.c
int printf(const char *, ...);
int a, d, e = 35435;
char b;
long c;
unsigned j;
short k, l;
int m(int n) {
char f[] = {0, 9};
char *g = f, *i = g;
long h = n;
do
*i++ = h /= 10;
while (h);
c = i - g;
while (g < i)
b = *g++;
a = c;
return c;
}
void o(int n) {
k = e;
l = (j = k) > n;
if (l)
d = 3;
}
void p() {
int q = m(17);
o(q + 65533);
}
int main() {
p();
printf("%d\n", d);
}
%
% clang -O0 a.c && ./a.out
3
% clang -O1 a.c && ./a.out
0
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VE-TpKgT_TTpJaMMTPx78FDV9fN32pjjHidQUemmpEZwumc-_QbYY1s9OxtRUULy8r1HkiCsVeMsZQ3ZBbJrJFY3maW2kzCnaRUnraLW9D_qTot5ROHw9CUBagio4XhTtjO3u9KyRzdJdNK6GNgV2Hn7vygrO-dXDYo8Z1nS5aVIuRh4NVRDX-U0FEmflUIyOXRDmbMe6AlfJ9VN-CosduZ2U85TtD8QUibkTS7WzHiUedpMLCjf7toscgF-xsm5uwV-BmqAmtH0rdEuNssI1PwEakr713P5_-pndWSCnG2_zszWaPkepQw74VDE3RZQs8P7omY3AJUe6rCbxIJAZ28_jmOgCvjlAy18POxNIvAr8izl2Y4Iye0-1WYesdun6xzOqMfnPWQnszh88Xz6QecGVPrvDFQhFO8ruNkbtkMOBqC4MJ9eQXHdGXDfxhhAg0cAnVWYjQdcsDiF8HwI9-bXCEMe0AXoEmAT-pPgV0zYIeF1UloiUDkdK4bYhRyFpwfVHe3tPaHyObteu-2LzuOm-pEnwkp3IFqkW5f5EPJVCIPvRvVo_lDFl0Akj3V4Fy2fw-AlJPD_PRRFDR6gH8z2Wxf8Qf8OVH6S9na-hSR_xEnxWC5v-Bv6UudZxvlxcWcO7SHU_Dv3u9yBb29uIALKesie5jAMTfwv5EDZ4a6Ex-L0hfkbg0A5UI4xUCNis7oNx3-HJ_8BZ59lfl3UqK95X_FKRLJO8qpMU5ZXFE11UVRpz7kss5JlVZG2pehSKURVtElLQxupmhjxhFFBCUszimVZsZa6LOci6UtOkDJ5E0rHWn-_-ZcjUtausi5YxqpIi1ZqG95Nolm-Ylj0Rcqu0VL7nFO7jhZSppV19oPFKadl_fcSbrnp5fasEpoZ38r8a56etJrXt6_jvPrGWWQnZ4eLHBdprTK-KaN10fWnF065aW3jztyAGq_1_jndF_MsOwfUBIcWqAk7-CcAAP__eNqV4A">