Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f74cf39

Browse files
committed
Fix crash when struct argument size is not a multiple of the pointer size
Fixes rust-lang#1200
1 parent 057635b commit f74cf39

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/abi/pass_mode.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
117117
PassMode::Cast(cast) => cast_target_to_abi_params(cast),
118118
PassMode::Indirect { attrs, extra_attrs: None, on_stack } => {
119119
if on_stack {
120-
let size = u32::try_from(self.layout.size.bytes()).unwrap();
120+
// Abi requires aligning struct size to pointer size
121+
let size = self.layout.size.align_to(tcx.data_layout.pointer_align.abi);
122+
let size = u32::try_from(size.bytes()).unwrap();
121123
smallvec![apply_arg_attrs_to_abi_param(
122124
AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructArgument(size),),
123125
attrs

0 commit comments

Comments
 (0)