Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,26 +377,26 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
size.is_multiple_of(align),
"size must be a multiple of alignment (size={size}, align={align})"
);
assert!(align.is_power_of_two(), "alignment must be a power of two (align={align})");

let abi_align = if self.tcx.sess.target.arch == Arch::S390x { 8 } else { 16 };
// Cranelift can only guarantee alignment up to the ABI alignment provided by the target.
// If the requested alignment is less than the abi_align it can be used directly.
if align <= abi_align {
let stack_slot = self.bcx.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
// FIXME Don't force the size to a multiple of <abi_align> bytes once Cranelift gets
// a way to specify stack slot alignment.
size: size.div_ceil(abi_align) * abi_align,
align_shift: 4,
size,
// The maximum value of ilog2 is 31 which will always fit in a u8.
align_shift: align.ilog2().try_into().unwrap(),
});
Pointer::stack_slot(stack_slot)
} else {
// Alignment is too big to handle using the above hack. Dynamically realign a stack slot
// instead. This wastes some space for the realignment.
let stack_slot = self.bcx.create_sized_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
// FIXME Don't force the size to a multiple of <abi_align> bytes once Cranelift gets
// a way to specify stack slot alignment.
size: (size + align) / abi_align * abi_align,
align_shift: 4,
size: size + align,
align_shift: abi_align.ilog2().try_into().unwrap(),
});
let base_ptr = self.bcx.ins().stack_addr(self.pointer_type, stack_slot, 0);
let misalign_offset = self.bcx.ins().band_imm(base_ptr, i64::from(align - 1));
Expand Down