Skip to content

Copy byval argument to local stackslot if alignment is insufficient#1641

Merged
bjorn3 merged 5 commits intorust-lang:mainfrom
0xmuon:fix1
Apr 30, 2026
Merged

Copy byval argument to local stackslot if alignment is insufficient#1641
bjorn3 merged 5 commits intorust-lang:mainfrom
0xmuon:fix1

Conversation

@0xmuon
Copy link
Copy Markdown
Contributor

@0xmuon 0xmuon commented Apr 13, 2026

Copy the underaligned byval (indirect) arguments into a local stackslot when the incoming pointer alignment is less than the Rust ABI alignment. This avoids miscompiles from assuming stronger alignment than the ABI guarantees.

Comment thread src/abi/mod.rs
Comment thread src/abi/mod.rs Outdated
Comment thread src/abi/pass_mode.rs Outdated
Comment thread src/abi/mod.rs Outdated
Comment thread src/abi/mod.rs Outdated
Comment thread src/abi/mod.rs Outdated
@bjorn3
Copy link
Copy Markdown
Member

bjorn3 commented Apr 30, 2026

I just found out that this doesn't actually fix #1465. It fixes a similar problem, but on the other side of the ABI. This fixes a problem on the callee when the ABI uses a lower alignment than the type needs, while #1465 is about copying on the caller side when the ABI requires a higher alignment than the type. The only tests in rust-lang/rust#122212 for the callee side bug only works on 32bit x86 which cg_clif doesn't support, so I can't actually test if your PR properly fixes the ABI mismatch. I do think it is correct, so I will merge it once CI passes. Thanks for working on this!

@bjorn3 bjorn3 merged commit dbc51b3 into rust-lang:main Apr 30, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants