Skip to content

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

Open
0xmuon wants to merge 4 commits intorust-lang:mainfrom
0xmuon:fix1
Open

Copy byval argument to local stackslot if alignment is insufficient#1641
0xmuon wants to merge 4 commits intorust-lang:mainfrom
0xmuon:fix1

Conversation

@0xmuon
Copy link
Copy Markdown
Contributor

@0xmuon 0xmuon commented Apr 13, 2026

fix: #1465

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 Outdated
Comment thread src/abi/mod.rs
Comment thread src/abi/pass_mode.rs Outdated
Comment thread src/abi/mod.rs Outdated
Comment thread src/abi/mod.rs
Comment on lines +252 to +253
Normal(ArgValue<'tcx>),
Spread(Vec<ArgValue<'tcx>>),
Copy link
Copy Markdown
Member

@bjorn3 bjorn3 Apr 15, 2026

Choose a reason for hiding this comment

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

Maybe pull out the Option around the field ty and have:

Suggested change
Normal(ArgValue<'tcx>),
Spread(Vec<ArgValue<'tcx>>),
Normal(Option<ArgValue<'tcx>>),
Spread(Vec<Option<ArgValue<'tcx>>>),

? The align field is unused when the argument is not passed at all. I don't know how much that would complicate cvalue_for_param though.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I considered that, but since cvalue_for_param now returns a single ArgValue, keeping Option outside would make the call sites and caller-location path a bit more awkward again. Since the underaligned flag is now just a bool, I kept ArgKind::{Normal,Spread} holding ArgValue directly and use value: None for PassMode::Ignore.

Comment thread src/abi/mod.rs
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.

Copy byval argument to local stackslot if alignment is insufficient

2 participants