Skip to content

Commit

Permalink
Remove the decl arg from FnAbi::llvm_type
Browse files Browse the repository at this point in the history
We can apply the `c_variadic` fix all the time, rather than trying to
distinguish between declarations and any other use.
  • Loading branch information
cuviper committed Aug 5, 2021
1 parent 183d79c commit 41f27d9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_codegen_llvm/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,18 @@ 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);
fn apply_attrs_callsite(&self, bx: &mut Builder<'a, 'll, 'tcx>, callsite: &'ll Value);
}

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 } +
Expand Down Expand Up @@ -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,
)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 41f27d9

Please sign in to comment.