This is an archive of the discontinued LLVM Phabricator instance.

[Clang][AArch64] Fix va_arg with -mgeneral-regs-only
Needs ReviewPublic

Authored by Amanieu on Sep 27 2022, 1:27 AM.

Details

Reviewers
MaskRay
Summary

With -mgeneral-regs-only, all arguments are passed in GPRs, so we should use gr_top/gr_offs in va_list even for floating-point types.

Diff Detail

Event Timeline

Amanieu created this revision.Sep 27 2022, 1:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2022, 1:27 AM
Amanieu requested review of this revision.Sep 27 2022, 1:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2022, 1:27 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

It seems that the intention of -mgeneral-regs-only is to prevent FP and SIMD register use.

aarch64-linux-gnu-gcc has such an error

error: ‘-mgeneral-regs-only’ is incompatible with the use of floating-point types

Clang doesn't reject FP in Sema yet, but I think changing CodeGen is incorrect.

Currently using Clang with -mgeneral-regs-only generates perfectly fine soft-float AArch64, with the except of the va_arg() implementation which is fixed here. In fact Rust even has a aarch64-unknown-none-softfloat which relies on this behavior in LLVM. I believe this behavior is *more* useful than GCC's which simply rejects float/double types, and it makes sense to keep it and fix it.

With -mgeneral-regs-only, all arguments are passed in GPRs, so we should use gr_top/gr_offs in va_list even for floating-point types.

I don't believe that -mgeneral-regs-only was intended to define an ABI passing floats in GPRs for AArch64. If it has that is likely a mistake, I don't recall any such ABI being defined.

I fully agree that this likely wasn't intentional, but this is still very useful for code that can't use FP registers for whatever reason (e.g. kernels). Regarding the ABI, it doesn't need to be officially defined: it just needs to be compatible with other code compiled with -mgeneral-regs-only.