Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect AArch64 codegen for C variadic functions when compiling without float support. #62966

Closed
BlamKiwi opened this issue May 27, 2023 · 2 comments

Comments

@BlamKiwi
Copy link

BlamKiwi commented May 27, 2023

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:
picolibc/picolibc#467

@llvmbot
Copy link
Member

llvmbot commented May 27, 2023

@llvm/issue-subscribers-backend-aarch64

@john-brawn-arm
Copy link
Collaborator

This has been fixed by #84146. When using -mabi=aapcs-soft (which is now required when using floating-point types without floating-point registers) the generated code for double is the same as for long: https://godbolt.org/z/s1EfPnTTs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants