From 41f27d903a2f6e81fbd082235fbdaacc0d356d1e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 4 Aug 2021 11:20:31 -0700 Subject: [PATCH] Remove the `decl` arg from `FnAbi::llvm_type` We can apply the `c_variadic` fix all the time, rather than trying to distinguish between declarations and any other use. --- compiler/rustc_codegen_llvm/src/abi.rs | 12 ++++++------ compiler/rustc_codegen_llvm/src/declare.rs | 2 +- compiler/rustc_codegen_llvm/src/intrinsic.rs | 2 +- compiler/rustc_codegen_llvm/src/type_.rs | 3 +-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index 0bd50ff1ad1..abf0ea8cc0a 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -344,7 +344,7 @@ impl ArgAbiMethods<'tcx> for Builder<'a, 'll, 'tcx> { } pub trait FnAbiLlvmExt<'tcx> { - fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>, decl: bool) -> &'ll Type; + fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type; fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type; fn llvm_cconv(&self) -> llvm::CallConv; fn apply_attrs_llfn(&self, cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value); @@ -352,10 +352,10 @@ pub trait FnAbiLlvmExt<'tcx> { } impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> { - fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>, decl: bool) -> &'ll Type { - // Ignore extra args when calling C variadic functions. - let args = - if decl && self.c_variadic { &self.args[..self.fixed_count] } else { &self.args }; + fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type { + // Ignore "extra" args from the call site for C variadic functions. + // Only the "fixed" args are part of the LLVM function signature. + let args = if self.c_variadic { &self.args[..self.fixed_count] } else { &self.args }; let args_capacity: usize = args.iter().map(|arg| if arg.pad.is_some() { 1 } else { 0 } + @@ -414,7 +414,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> { fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type { unsafe { llvm::LLVMPointerType( - self.llvm_type(cx, false), + self.llvm_type(cx), cx.data_layout().instruction_address_space.0 as c_uint, ) } diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs index 6b9ab55459e..8977fa085b9 100644 --- a/compiler/rustc_codegen_llvm/src/declare.rs +++ b/compiler/rustc_codegen_llvm/src/declare.rs @@ -90,7 +90,7 @@ impl CodegenCx<'ll, 'tcx> { name, fn_abi.llvm_cconv(), llvm::UnnamedAddr::Global, - fn_abi.llvm_type(self, false), + fn_abi.llvm_type(self), ); fn_abi.apply_attrs_llfn(self, llfn); llfn diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 631602ac864..ed484185865 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -712,7 +712,7 @@ fn gen_fn<'ll, 'tcx>( codegen: &mut dyn FnMut(Builder<'_, 'll, 'tcx>), ) -> (&'ll Type, &'ll Value) { let fn_abi = FnAbi::of_fn_ptr(cx, rust_fn_sig, &[]); - let llty = fn_abi.llvm_type(cx, false); + let llty = fn_abi.llvm_type(cx); let llfn = cx.declare_fn(name, &fn_abi); cx.set_frame_pointer_type(llfn); cx.apply_target_cpu_attr(llfn); diff --git a/compiler/rustc_codegen_llvm/src/type_.rs b/compiler/rustc_codegen_llvm/src/type_.rs index 18df24d9277..69787df5e07 100644 --- a/compiler/rustc_codegen_llvm/src/type_.rs +++ b/compiler/rustc_codegen_llvm/src/type_.rs @@ -276,8 +276,7 @@ impl LayoutTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> { ty.llvm_type(self) } fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> &'ll Type { - // This does not include extra args when calling C variadic functions. - fn_abi.llvm_type(self, true) + fn_abi.llvm_type(self) } fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> &'ll Type { fn_abi.ptr_to_llvm_type(self)