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

x86_64 ABI: pass structs indirectly if there are no more available registers #11344

Merged
merged 2 commits into from
Oct 22, 2021

Conversation

ggiraldez
Copy link
Contributor

Fixes #9519

Unix x86_64 ABI defines CPU registers rdi, rsi, rdx, rcx, r8, r9 (for integer values) and xmm0 through xmm7 (for floating point values) for passing arguments to functions. Small structures (smaller than 64 bytes, or 8 eight-bytes) can be passed using registers as well, by passing individual fields into separate registers. But if the number of arguments is larger than the available registers, the remaining values are passed through the stack. LLVM manages this for scalar values, but for aggregates it needs the byval attribute to the argument type added.

This patch is heavily inspired by the Rust implementation (from where the original ABI code was taken). The previously added spec by #9520 is enabled and I also added a new one to cover the StructRet scenario which effectively introduces an extra hidden function argument as a pointer to the caller-allocated return value.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen labels Oct 21, 2021
Copy link
Member

@beta-ziliani beta-ziliani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@straight-shoota straight-shoota added this to the 1.3.0 milestone Oct 21, 2021
@straight-shoota straight-shoota merged commit 1be4fa7 into crystal-lang:master Oct 22, 2021
@beta-ziliani beta-ziliani modified the milestones: 1.3.0, 1.2.2 Oct 29, 2021
straight-shoota pushed a commit to straight-shoota/crystal that referenced this pull request Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

C ABI: passing a struct after numerous other args works wrong
3 participants