@@ -388,18 +388,25 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
388388 }
389389
390390 pub ( crate ) fn create_stack_slot ( & mut self , size : u32 , align : u32 ) -> Pointer {
391- if align <= 16 {
391+ let abi_align = if self . tcx . sess . target . arch == "s390x" { 8 } else { 16 } ;
392+ if align <= abi_align {
392393 let stack_slot = self . bcx . create_sized_stack_slot ( StackSlotData {
393394 kind : StackSlotKind :: ExplicitSlot ,
394- // FIXME Don't force the size to a multiple of 16 bytes once Cranelift gets a way to
395- // specify stack slot alignment.
396- size : ( size + 15 ) / 16 * 16 ,
395+ // FIXME Don't force the size to a multiple of <abi_align> bytes once Cranelift gets
396+ // a way to specify stack slot alignment.
397+ size : ( size + abi_align - 1 ) / abi_align * abi_align ,
397398 } ) ;
398399 Pointer :: stack_slot ( stack_slot)
399400 } else {
400401 // Alignment is too big to handle using the above hack. Dynamically realign a stack slot
401402 // instead. This wastes some space for the realignment.
402- let base_ptr = self . create_stack_slot ( size + align, 16 ) . get_addr ( self ) ;
403+ let stack_slot = self . bcx . create_sized_stack_slot ( StackSlotData {
404+ kind : StackSlotKind :: ExplicitSlot ,
405+ // FIXME Don't force the size to a multiple of <abi_align> bytes once Cranelift gets
406+ // a way to specify stack slot alignment.
407+ size : ( size + align) / abi_align * abi_align,
408+ } ) ;
409+ let base_ptr = self . bcx . ins ( ) . stack_addr ( self . pointer_type , stack_slot, 0 ) ;
403410 let misalign_offset = self . bcx . ins ( ) . urem_imm ( base_ptr, i64:: from ( align) ) ;
404411 let realign_offset = self . bcx . ins ( ) . irsub_imm ( misalign_offset, i64:: from ( align) ) ;
405412 Pointer :: new ( self . bcx . ins ( ) . iadd ( base_ptr, realign_offset) )
0 commit comments