Skip to content

Commit f344768

Browse files
committed
Handle PassMode::Cast in combination with #[repr(align)]
1 parent 18de1b1 commit f344768

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/abi/pass_mode.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,19 @@ pub(super) fn from_casted_value<'tcx>(
227227
cast: CastTarget,
228228
) -> CValue<'tcx> {
229229
let abi_params = cast_target_to_abi_params(cast);
230-
let size: u32 = abi_params
230+
let abi_param_size: u32 = abi_params
231231
.iter()
232232
.map(|param| param.value_type.bytes())
233233
.sum();
234-
// Stack slot size may be bigger for for example `[u8; 3]` which is packed into an `i32`.
235-
assert!(u64::from(size) >= layout.size.bytes());
234+
let layout_size = u32::try_from(layout.size.bytes()).unwrap();
236235
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
237236
kind: StackSlotKind::ExplicitSlot,
238237
// FIXME Don't force the size to a multiple of 16 bytes once Cranelift gets a way to
239238
// specify stack slot alignment.
240-
size: (size + 15) / 16 * 16,
239+
// Stack slot size may be bigger for for example `[u8; 3]` which is packed into an `i32`.
240+
// It may also be smaller for example when the type is a wrapper around an integer with a
241+
// larger alignment than the integer.
242+
size: (std::cmp::max(abi_param_size, layout_size) + 15) / 16 * 16,
241243
offset: None,
242244
});
243245
let ptr = Pointer::new(fx.bcx.ins().stack_addr(pointer_ty(fx.tcx), stack_slot, 0));

0 commit comments

Comments
 (0)