Skip to content

Commit fe3f606

Browse files
committed
Add ty_fn_sig_vtable for getting adjusted signature for vtable shims.
1 parent 824315a commit fe3f606

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ pub fn codegen_instance<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, instance: Instance<'
492492
info!("codegen_instance({})", instance);
493493

494494
let fn_ty = instance.ty(cx.tcx);
495-
let sig = common::ty_fn_sig(cx, fn_ty);
495+
let sig = common::ty_fn_sig_vtable(cx, fn_ty, instance.is_vtable_shim());
496496
let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
497497

498498
let lldecl = cx.instances.borrow().get(&instance).cloned().unwrap_or_else(||

src/librustc_codegen_llvm/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn get_fn(
5656
debug!("get_fn({:?}: {:?}) => {}", instance, fn_ty, sym);
5757

5858
// Create a fn pointer with the substituted signature.
59-
let fn_ptr_ty = tcx.mk_fn_ptr(common::ty_fn_sig(cx, fn_ty));
59+
let fn_ptr_ty = tcx.mk_fn_ptr(common::ty_fn_sig_vtable(cx, fn_ty, instance.is_vtable_shim()));
6060
let llptrty = cx.layout_of(fn_ptr_ty).llvm_type(cx);
6161

6262
let llfn = if let Some(llfn) = declare::get_declared_value(cx, &sym) {

src/librustc_codegen_llvm/common.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,22 @@ pub fn ty_fn_sig<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
453453
_ => bug!("unexpected type {:?} to ty_fn_sig", ty)
454454
}
455455
}
456+
457+
pub fn ty_fn_sig_vtable<'a, 'tcx>(
458+
cx: &CodegenCx<'a, 'tcx>,
459+
ty: Ty<'tcx>,
460+
is_vtable_shim: bool
461+
) -> ty::PolyFnSig<'tcx>
462+
{
463+
let mut fn_sig = ty_fn_sig(cx, ty);
464+
if is_vtable_shim {
465+
// Modify fn(self, ...) to fn(self: *mut Self, ...)
466+
fn_sig = fn_sig.map_bound(|mut fn_sig| {
467+
let mut inputs_and_output = fn_sig.inputs_and_output.to_vec();
468+
inputs_and_output[0] = cx.tcx.mk_mut_ptr(inputs_and_output[0]);
469+
fn_sig.inputs_and_output = cx.tcx.intern_type_list(&inputs_and_output);
470+
fn_sig
471+
});
472+
}
473+
fn_sig
474+
}

0 commit comments

Comments
 (0)