Fix and cleanup callee shims
This commit is contained in:
parent
f9f1406eef
commit
6e3d8cda2c
|
@ -502,15 +502,15 @@ fn trans_fn_pointer_shim<'a, 'tcx>(
|
||||||
let fcx = FunctionContext::new(ccx, llfn, fn_ty);
|
let fcx = FunctionContext::new(ccx, llfn, fn_ty);
|
||||||
let bcx = fcx.get_entry_block();
|
let bcx = fcx.get_entry_block();
|
||||||
|
|
||||||
let llargs = get_params(fcx.llfn);
|
let mut llargs = get_params(fcx.llfn);
|
||||||
|
|
||||||
let self_idx = fcx.fn_ty.ret.is_indirect() as usize;
|
let self_arg = llargs.remove(fcx.fn_ty.ret.is_indirect() as usize);
|
||||||
let llfnpointer = llfnpointer.unwrap_or_else(|| {
|
let llfnpointer = llfnpointer.unwrap_or_else(|| {
|
||||||
// the first argument (`self`) will be ptr to the fn pointer
|
// the first argument (`self`) will be ptr to the fn pointer
|
||||||
if is_by_ref {
|
if is_by_ref {
|
||||||
bcx.load(llargs[self_idx])
|
bcx.load(self_arg)
|
||||||
} else {
|
} else {
|
||||||
llargs[self_idx]
|
self_arg
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -522,16 +522,7 @@ fn trans_fn_pointer_shim<'a, 'tcx>(
|
||||||
let fn_ret = callee.ty.fn_ret();
|
let fn_ret = callee.ty.fn_ret();
|
||||||
let fn_ty = callee.direct_fn_type(ccx, &[]);
|
let fn_ty = callee.direct_fn_type(ccx, &[]);
|
||||||
|
|
||||||
let mut args = Vec::new();
|
let llret = bcx.call(llfnpointer, &llargs, None);
|
||||||
|
|
||||||
if fn_ty.ret.is_indirect() {
|
|
||||||
if !fn_ty.ret.is_ignore() {
|
|
||||||
args.push(get_param(fcx.llfn, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
args.extend_from_slice(&llargs[(self_idx + 1)..]);
|
|
||||||
|
|
||||||
let llret = bcx.call(llfnpointer, &args, None);
|
|
||||||
fn_ty.apply_attrs_callsite(llret);
|
fn_ty.apply_attrs_callsite(llret);
|
||||||
|
|
||||||
if fn_ret.0.is_never() {
|
if fn_ret.0.is_never() {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use attributes;
|
||||||
use llvm::{ValueRef, get_params};
|
use llvm::{ValueRef, get_params};
|
||||||
use rustc::traits;
|
use rustc::traits;
|
||||||
use abi::FnType;
|
use abi::FnType;
|
||||||
use callee::Callee;
|
use callee::{Callee, CalleeData};
|
||||||
use common::*;
|
use common::*;
|
||||||
use consts;
|
use consts;
|
||||||
use declare;
|
use declare;
|
||||||
|
@ -84,14 +84,20 @@ pub fn trans_object_shim<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
|
||||||
let fcx = FunctionContext::new(ccx, llfn, fn_ty);
|
let fcx = FunctionContext::new(ccx, llfn, fn_ty);
|
||||||
let bcx = fcx.get_entry_block();
|
let bcx = fcx.get_entry_block();
|
||||||
|
|
||||||
let llargs = get_params(fcx.llfn);
|
let mut llargs = get_params(fcx.llfn);
|
||||||
let fn_ret = callee.ty.fn_ret();
|
let fn_ret = callee.ty.fn_ret();
|
||||||
let fn_ty = callee.direct_fn_type(ccx, &[]);
|
let fn_ty = callee.direct_fn_type(ccx, &[]);
|
||||||
|
|
||||||
let mut args = Vec::new();
|
let fn_ptr = match callee.data {
|
||||||
|
CalleeData::Virtual(idx) => {
|
||||||
args.extend_from_slice(&llargs);
|
let fn_ptr = get_virtual_method(&bcx,
|
||||||
let llret = bcx.call(callee.reify(ccx), &args, None);
|
llargs.remove(fn_ty.ret.is_indirect() as usize + 1), idx);
|
||||||
|
let llty = fn_ty.llvm_type(bcx.ccx()).ptr_to();
|
||||||
|
bcx.pointercast(fn_ptr, llty)
|
||||||
|
},
|
||||||
|
_ => bug!("trans_object_shim called with non-virtual callee"),
|
||||||
|
};
|
||||||
|
let llret = bcx.call(fn_ptr, &llargs, None);
|
||||||
fn_ty.apply_attrs_callsite(llret);
|
fn_ty.apply_attrs_callsite(llret);
|
||||||
|
|
||||||
if fn_ret.0.is_never() {
|
if fn_ret.0.is_never() {
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
assert_eq!((ToString::to_string as fn(&(ToString+'static)) -> String)(&"foo"),
|
||||||
|
String::from("foo"));
|
||||||
|
}
|
Loading…
Reference in New Issue