From f74cf39a7434c73424b9e5fddaf78996bd2b06c1 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 15 Dec 2021 16:53:35 +0100 Subject: [PATCH] Fix crash when struct argument size is not a multiple of the pointer size Fixes #1200 --- src/abi/pass_mode.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index c01ed249904..9f0bd31e95f 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -117,7 +117,9 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { PassMode::Cast(cast) => cast_target_to_abi_params(cast), PassMode::Indirect { attrs, extra_attrs: None, on_stack } => { if on_stack { - let size = u32::try_from(self.layout.size.bytes()).unwrap(); + // Abi requires aligning struct size to pointer size + let size = self.layout.size.align_to(tcx.data_layout.pointer_align.abi); + let size = u32::try_from(size.bytes()).unwrap(); smallvec![apply_arg_attrs_to_abi_param( AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructArgument(size),), attrs