Skip to content

Commit

Permalink
Add ty_fn_sig_vtable for getting adjusted signature for vtable shims.
Browse files Browse the repository at this point in the history
  • Loading branch information
qnighy committed Oct 24, 2018
1 parent 824315a commit fe3f606
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/base.rs
Expand Up @@ -492,7 +492,7 @@ pub fn codegen_instance<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, instance: Instance<'
info!("codegen_instance({})", instance);

let fn_ty = instance.ty(cx.tcx);
let sig = common::ty_fn_sig(cx, fn_ty);
let sig = common::ty_fn_sig_vtable(cx, fn_ty, instance.is_vtable_shim());
let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);

let lldecl = cx.instances.borrow().get(&instance).cloned().unwrap_or_else(||
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/callee.rs
Expand Up @@ -56,7 +56,7 @@ pub fn get_fn(
debug!("get_fn({:?}: {:?}) => {}", instance, fn_ty, sym);

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

let llfn = if let Some(llfn) = declare::get_declared_value(cx, &sym) {
Expand Down
19 changes: 19 additions & 0 deletions src/librustc_codegen_llvm/common.rs
Expand Up @@ -453,3 +453,22 @@ pub fn ty_fn_sig<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
_ => bug!("unexpected type {:?} to ty_fn_sig", ty)
}
}

pub fn ty_fn_sig_vtable<'a, 'tcx>(
cx: &CodegenCx<'a, 'tcx>,
ty: Ty<'tcx>,
is_vtable_shim: bool
) -> ty::PolyFnSig<'tcx>
{
let mut fn_sig = ty_fn_sig(cx, ty);
if is_vtable_shim {
// Modify fn(self, ...) to fn(self: *mut Self, ...)
fn_sig = fn_sig.map_bound(|mut fn_sig| {
let mut inputs_and_output = fn_sig.inputs_and_output.to_vec();
inputs_and_output[0] = cx.tcx.mk_mut_ptr(inputs_and_output[0]);
fn_sig.inputs_and_output = cx.tcx.intern_type_list(&inputs_and_output);
fn_sig
});
}
fn_sig
}

0 comments on commit fe3f606

Please sign in to comment.