<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62966>62966</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect AArch64 codegen for C variadic functions when compiling without float support.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
BlamKiwi
</td>
</tr>
</table>
<pre>
When compiling AArch64 targets without hard-float support e.g., `-march=armv8-a+nofp+nosimd -mgeneral-regs-only`, LLVM generates invalid assembly for C variadic functions when passed floating-point values.
When passing a floating-point value to a variadic function, it passes it as an integer register, and saves it to the integer register block. When fetching the value, it fetches it from the floating register block, which is uninitialized.
Keith Packard over at picolibc discovered the problem and provided a minimal example:
https://godbolt.org/z/5Y9qEq437
```
#include <stdarg.h>
double my_printf(const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
double d = va_arg(ap, double);
return d;
}
void foo() {
my_printf("Hello World!", 1.0);
}
```
It looks like the problem is in the method `AArch64ABIInfo::EmitAAPCSVAArg`, the check to see if a register is floating or integer only looks at the base type. The check also needs to take into account additional target information such as general-regs-only being enabled.
Additional information:
https://github.com/picolibc/picolibc/issues/467
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8Vd-P2zYM_muUFyKGIydO8pCH3KXBDu2AAhta7KmgJdrmIkuuJOd2_esHOb5L0tsKGP4hkR8_0vwoDIEbS7QTqwexOsxwiK3zuweD3Ud-5lnl9Mvua0sWlOt6Nmwb2O-9asslRPQNxQDPHFs3RGjR63ltHEYIQ987H4GyJhPyEUSZzzv0qhXFAX133sxRyAfr6n58BO40zLuGLHk0c09NmDtrXkSZJ-9Pn778DpfNSAHYntGwBgyBusq8QO08PMIZPaNmBfVgVWRnAzwn4n2y0zASY9vMe8c2whnNQCEDkR9Evr_cv76apyzxPz0gOsD3oRJLjpdQIb1hALTANlJDHjw1HCL5ZIZWQ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