diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2021-12-15 16:53:35 +0100 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2021-12-15 16:53:35 +0100 |
| commit | f74cf39a7434c73424b9e5fddaf78996bd2b06c1 (patch) | |
| tree | b2a720dfa691b24978984aa6d78e62fac989b4ad | |
| parent | 057635b9da3ba96bcaed96d7f882e171811dc4d6 (diff) | |
| download | rust-f74cf39a7434c73424b9e5fddaf78996bd2b06c1.tar.gz rust-f74cf39a7434c73424b9e5fddaf78996bd2b06c1.zip | |
Fix crash when struct argument size is not a multiple of the pointer size
Fixes #1200
| -rw-r--r-- | src/abi/pass_mode.rs | 4 |
1 files changed, 3 insertions, 1 deletions
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