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.
This commit is contained in:
Josh Stone 2021-08-04 11:20:31 -07:00
parent 183d79cc09
commit 41f27d903a
4 changed files with 9 additions and 10 deletions

View file

@ -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,
)
}

View file

@ -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

View file

@ -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);

View file

@ -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)