<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63121>63121</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Possible wrong-code on -O2 and above (affecting LLVM 12.0.1 downward versions)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
haoxintu
</td>
</tr>
</table>
<pre>
Hi, the following code makes LLVM 12.0.1 downward versions behave differently. It might be an issue in LLVM's optimization, can you take a look, please?
```
#include <stdint.h>
#include <stdio.h>
int8_t a = 0, j=0, b=0;
int ids = 0;
void __attribute__((noinline)) marker_1() {
printf(" b%db ", 1);
ids ++;
}
int8_t *c(uint32_t, uint16_t);
void d();
int16_t e(uint8_t, int8_t *, uint32_t);
uint32_t f() {
int8_t g[1][10] = {0,0,0,0,0,0,0,0,0,0};
d();
c(g[0][2], g[0][8]);
return 0;
}
int8_t *c(uint32_t h, uint16_t i) {
marker_1();
return &b;
}
void d() {
int m = 0;
for (; m <= 5; m++)
e(0, &a, 0);
}
int16_t e(uint8_t k, int8_t *l, uint32_t o) {
for (; j;)
n:;
goto n;
}
int main() {
f();
printf("%d\n", ids);
}
```
$clang-trunk -w -O2 test.c ; ./a.out
(output nothing)
$clang-12.0.1 -w -O2 test.c ; ./a.out
b1b 1
$clang-12.0.1 -w -O1 test.c ; ./a.out
(hang)
$clang-trunk -v
clang version 16.0.0 (https://github.com/llvm/llvm-project bf6f82a9df6a1693a5399039dcadd7fc00dab65e)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/haoxin-data/compilers/llvm-project/build/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
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
Found CUDA installation: /usr/lib/cuda, version
Code on GodBolt: https://godbolt.org/z/Wsh6Thd5v
Thanks,
Haoxin
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vl2vmzgT_jXOzSgIhu-LXJwkL22lvtqVtrt7GRlswI2xI2xyTvvrVwaSkJzuOVqplUhs5vOZGc9gaoxoFOcbEm9JvF_Rwba637RUvwhlh1Wp2bfNR0FwB7blUGsp9bNQDVSacejokRv4_Pmv_0OAnu8FwPSzeqY9gzPvjdDKQMlbeubARF3znisrv3nwyUInmtZCyYEqEMYMHIQaLRFMDeiTFZ34Tq3QyvmuqIJvegBLjxwoSK2PjnySnBpOwoL4e-I_zf-JPz_TK4ZCVXJgHEi4M5YJZb2WhP_7N7ZecIWy2cECBRLuwXcuv5JwP27KcRNur4IgmJnlLtSzFgwOB2ptL8rB8sOBYEYwU1ooKRQnmBPMoaP9kfeHYGTmQNJZHQDg1Atl65GDUBKMWQkE0SEInHq4kB0B4NY9FzJJ93eREHyqCGaDUDbEg3Vm3D5I3D6_B84mPMsYnRzw2UA26d8sX6xNlm-KFxrUryOctRsSbwMS793ik3g_JpKkW5fq93_pfpGHR9gALmLnwJ8coFtwBwtSNpKWOj23Q68WtXwnk9AucwniIcz7Er_2QzApX7taluEhadA9nDWAWvfgZMPtyNw5fjy-zYcC89tZcUUczzHBhLrVX-JaBvtYczjeV10uyw76AeoC1Fdn_oZBkfDp7vg22mpH_QEG6KhQtzzATam-ZvRCXHaM6xcS79TcMYKZO9mri1czI6okVc3a9oM6wvoZ1r8hWG6sV4FT9wgW1NODvchnerCnwYLSthWquYZ5tTTPx3dNQRmUELyhHLyNo6VL7z-M5jyRR9plTkOQeL7nu1K11p6Mqw0WB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