Copy byval argument to local stackslot if alignment is insufficient#1641
Open
0xmuon wants to merge 3 commits intorust-lang:mainfrom
Open
Copy byval argument to local stackslot if alignment is insufficient#16410xmuon wants to merge 3 commits intorust-lang:mainfrom
0xmuon wants to merge 3 commits intorust-lang:mainfrom
Conversation
bjorn3
requested changes
Apr 13, 2026
bjorn3
requested changes
Apr 15, 2026
Comment on lines
+332
to
+333
| let len = ty::Const::from_target_usize(fx.tcx, arg_abi.layout.size.bytes()); | ||
| let bytes_ty = fx.tcx.mk_ty_from_kind(ty::Array(fx.tcx.types.u8, len)); |
Member
There was a problem hiding this comment.
This can use Ty::new_array().
|
|
||
| pub(super) struct ArgValue<'tcx> { | ||
| pub(super) value: Option<CValue<'tcx>>, | ||
| pub(super) underaligned_pointee_align: Option<Align>, |
Member
There was a problem hiding this comment.
This can now be a bool is_underaligned_pointee.
Comment on lines
+252
to
+253
| Normal(ArgValue<'tcx>), | ||
| Spread(Vec<ArgValue<'tcx>>), |
Member
There was a problem hiding this comment.
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.
| let arg_abi = arg_abis_iter.next().unwrap(); | ||
| fx.caller_location = | ||
| Some(cvalue_for_param(fx, None, None, arg_abi, &mut block_params_iter).unwrap()); | ||
| let arg = cvalue_for_param(fx, None, None, arg_abi, &mut block_params_iter); |
Member
There was a problem hiding this comment.
Maybe assert that arg is not underaligned?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.