<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/104794>104794</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
For tail calls, clang generates extra alloca for sret parameter on 32 bit targets
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang,
clang:codegen
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
kiran-isaac
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kiran-isaac
</td>
</tr>
</table>
<pre>
While running a fuzzer to verify #102896, I kept getting errors for any cases using `double _Complex` or `_BitInt(n>64)` as return types for `[[clang::musttail]]` functions on 32 bit targets. These cases would compile such that new memory is `alloca`'d for the sret parameter, rather than passing through the same sret ptr from the caller. For example
```cpp
double _Complex F11(signed short P0);
double _Complex F12(signed short P0) {
[[clang::musttail]] return F11(1000);
}
```
```bash
clang -S -emit-llvm --target=(arm/x86/any 32 bit target) -o -
```
Gives you (see #104770 for more info about weird no predecessors block):
```llvm
; Function Attrs: mustprogress noinline optnone
define dso_local arm_aapcscc void @_Z3F12s(ptr dead_on_unwind noalias writable sret({ double, double }) align 8 %agg.result, i16 noundef signext %P0) #0 {
entry:
%P0.addr = alloca i16, align 2
%tmp = alloca { double, double }, align 8
store i16 %P0, ptr %P0.addr, align 2
%0 = load i16, ptr %P0.addr, align 2
musttail call arm_aapcscc void @_Z3F11s(ptr dead_on_unwind writable sret({ double, double }) align 8 %tmp, i16 noundef signext %0)
ret void
1: ; No predecessors!
...
ret void
}
```
This is an invalid tail call. Similar behaviour can be observed when replacing `double _Complex` with `_BitInt(N>64)`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVV-P4jYQ_zTmZUTkOBDCQx6WpVT3cqp0J1XqC5rEQ-KeY0e2A8t9-spJ2GP3lp5aFBHFnv-_38yg96oxRCVb75gQ35RDs1QesWZCsPV-gUNorSvvLhaVldfyz1ZpAjcYo0wDCKfh-3dyECycyanTFZjIUi6Kbc7EM3y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