<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63611>63611</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong code at -Os on x86_64-linux_gnu (a 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>
This seems to be a recent regression. clang at -Os produced the wrong code.
Compiler explorer: https://godbolt.org/z/Yvo1c3efK
```console
% cat a.c
unsigned a;
unsigned *c = &a;
char g;
char *h = &g, *i;
unsigned *const *j = &c;
unsigned *const **k = &j;
unsigned *const ***l = &k;
int m(unsigned n) {
while (n << 4)
n = 4;
while (n)
;
return 1;
}
int *e;
int **f = &e;
int o() {
int b;
*h = i != &i;
ac:
if ((**l || *h) & *h - 2079077697)
;
else {
int d;
for (; *l; g++)
for (; *h <= 0;) {
*f = 0;
return m(****l) + ****l;
}
goto ac;
}
return 0;
}
int main() { o(); }
%
% clang-tk -O0 a.c && ./a.out
%
% clang-tk -Os a.c
% ./a.out
Killed
%
% clang-tk -v
clang version 17.0.0 (https://github.com/llvm/llvm-project.git 36999318f09122fa41baff838f46c753db078275)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-trunk/bin
Found candidate GCC installation: /opt/compiler-explorer/gcc-9.2.0/lib/gcc/x86_64-linux-gnu/9.2.0
Selected GCC installation: /opt/compiler-explorer/gcc-9.2.0/lib/gcc/x86_64-linux-gnu/9.2.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
"/opt/compiler/clang-trunk-20230629/bin/clang-17" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name example.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/app -resource-dir /opt/compiler/clang-trunk-20230629/lib/clang/17 -internal-isystem /opt/compiler/clang-trunk-20230629/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler/gcc-9.2.0/lib/gcc/x86_64-linux-gnu/9.2.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/app -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-329967.o -x c <source>
clang -cc1 version 17.0.0 based upon LLVM 17.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/opt/compiler≈Ω/gcc-9.2.0/lib/gcc/x86_64-linux-gnu/9.2.0/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/compiler-explorer/clang-trunk-20230629/lib/clang/17/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8V1uP6ygS_jXkpYTl4LRjP-QhnbRnRzOjkXZGM9qnFoayw2kMFuDunP31K2zn0unLOUcrTRQldtXHRxV1Abj3qjWIG3J3T-72Cz6Eg3Ubf-CWHgZOtVrUVn7d_HlQHjxi5yFYqBE4OBRoAjhsHXqvrElAaG5a4AHo7x56Z-UgUEI4ILw4a1oQVmJC0j1Jt9Pvzna90ugAj722Dh3JtnAIofck2xJWEVa1VtZWh8S6lrDqv4RV_3m2S5Fh88s1E8nT6Sus8VbjLGV3IHgAnohJMJjRXwmcZPc3IsK2Aki2B8Lyi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