X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_codegen_llvm%2Fva_arg.rs;h=9bc3eec60ae044702770bc6642e7a68b173c2b26;hb=bfac73c0a6786644d0a58a12347839d442be26ac;hp=86b0ad761af6aa3b4c0135bf006d759745d718c3;hpb=b9ea653aee231114acbe6d4b3c7b1d692772d060;p=rust.git diff --git a/src/librustc_codegen_llvm/va_arg.rs b/src/librustc_codegen_llvm/va_arg.rs index 86b0ad761af..9bc3eec60ae 100644 --- a/src/librustc_codegen_llvm/va_arg.rs +++ b/src/librustc_codegen_llvm/va_arg.rs @@ -2,17 +2,19 @@ use crate::type_::Type; use crate::type_of::LayoutLlvmExt; use crate::value::Value; -use rustc_codegen_ssa::mir::operand::OperandRef; -use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods, ConstMethods, DerivedTypeMethods}; use rustc::ty::layout::{Align, HasDataLayout, HasTyCtxt, LayoutOf, Size}; use rustc::ty::Ty; +use rustc_codegen_ssa::mir::operand::OperandRef; +use rustc_codegen_ssa::traits::{ + BaseTypeMethods, BuilderMethods, ConstMethods, DerivedTypeMethods, +}; #[allow(dead_code)] fn round_pointer_up_to_alignment( bx: &mut Builder<'a, 'll, 'tcx>, addr: &'ll Value, align: Align, - ptr_ty: &'ll Type + ptr_ty: &'ll Type, ) -> &'ll Value { let mut ptr_as_int = bx.ptrtoint(addr, bx.cx().type_isize()); ptr_as_int = bx.add(ptr_as_int, bx.cx().const_i32(align.bytes() as i32 - 1)); @@ -27,7 +29,7 @@ fn emit_direct_ptr_va_arg( size: Size, align: Align, slot_size: Align, - allow_higher_align: bool + allow_higher_align: bool, ) -> (&'ll Value, Align) { let va_list_ptr_ty = bx.cx().type_ptr_to(bx.cx.type_i8p()); let va_list_addr = if list.layout.llvm_type(bx.cx) != va_list_ptr_ty { @@ -44,14 +46,12 @@ fn emit_direct_ptr_va_arg( (ptr, slot_size) }; - let aligned_size = size.align_to(slot_size).bytes() as i32; let full_direct_size = bx.cx().const_i32(aligned_size); let next = bx.inbounds_gep(addr, &[full_direct_size]); bx.store(next, va_list_addr, bx.tcx().data_layout.pointer_align.abi); - if size.bytes() < slot_size.bytes() && - &*bx.tcx().sess.target.target.target_endian == "big" { + if size.bytes() < slot_size.bytes() && &*bx.tcx().sess.target.target.target_endian == "big" { let adjusted_size = bx.cx().const_i32((slot_size.bytes() - size.bytes()) as i32); let adjusted = bx.inbounds_gep(addr, &[adjusted_size]); (bx.bitcast(adjusted, bx.cx().type_ptr_to(llty)), addr_align) @@ -66,20 +66,20 @@ fn emit_ptr_va_arg( target_ty: Ty<'tcx>, indirect: bool, slot_size: Align, - allow_higher_align: bool + allow_higher_align: bool, ) -> &'ll Value { let layout = bx.cx.layout_of(target_ty); let (llty, size, align) = if indirect { - (bx.cx.layout_of(bx.cx.tcx.mk_imm_ptr(target_ty)).llvm_type(bx.cx), - bx.cx.data_layout().pointer_size, - bx.cx.data_layout().pointer_align) + ( + bx.cx.layout_of(bx.cx.tcx.mk_imm_ptr(target_ty)).llvm_type(bx.cx), + bx.cx.data_layout().pointer_size, + bx.cx.data_layout().pointer_align, + ) } else { - (layout.llvm_type(bx.cx), - layout.size, - layout.align) + (layout.llvm_type(bx.cx), layout.size, layout.align) }; - let (addr, addr_align) = emit_direct_ptr_va_arg(bx, list, llty, size, align.abi, - slot_size, allow_higher_align); + let (addr, addr_align) = + emit_direct_ptr_va_arg(bx, list, llty, size, align.abi, slot_size, allow_higher_align); if indirect { let tmp_ret = bx.load(addr, addr_align); bx.load(tmp_ret, align.abi) @@ -100,38 +100,30 @@ pub(super) fn emit_va_arg( match (&**arch, target.options.is_like_windows) { // Windows x86 ("x86", true) => { - emit_ptr_va_arg(bx, addr, target_ty, false, - Align::from_bytes(4).unwrap(), false) + emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(4).unwrap(), false) } // Generic x86 ("x86", _) => { - emit_ptr_va_arg(bx, addr, target_ty, false, - Align::from_bytes(4).unwrap(), true) + emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(4).unwrap(), true) } // Windows AArch64 ("aarch64", true) => { - emit_ptr_va_arg(bx, addr, target_ty, false, - Align::from_bytes(8).unwrap(), false) + emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), false) } // iOS AArch64 ("aarch64", _) if target.target_os == "ios" => { - emit_ptr_va_arg(bx, addr, target_ty, false, - Align::from_bytes(8).unwrap(), true) + emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), true) } // Windows x86_64 ("x86_64", true) => { let target_ty_size = bx.cx.size_of(target_ty).bytes(); - let indirect = if target_ty_size > 8 || !target_ty_size.is_power_of_two() { - true - } else { - false - }; - emit_ptr_va_arg(bx, addr, target_ty, indirect, - Align::from_bytes(8).unwrap(), false) + let indirect = + if target_ty_size > 8 || !target_ty_size.is_power_of_two() { true } else { false }; + emit_ptr_va_arg(bx, addr, target_ty, indirect, Align::from_bytes(8).unwrap(), false) } // For all other architecture/OS combinations fall back to using // the LLVM va_arg instruction. // https://llvm.org/docs/LangRef.html#va-arg-instruction - _ => bx.va_arg(addr.immediate(), bx.cx.layout_of(target_ty).llvm_type(bx.cx)) + _ => bx.va_arg(addr.immediate(), bx.cx.layout_of(target_ty).llvm_type(bx.cx)), } }