Skip to content

Commit 4a4a434

Browse files
committed
Fix translation of unboxing shim for rust-call ABI methods
When translating the unboxing shim, account for the fact that the shim translation has already performed the necessary unboxing of input types and values when forwarding to the shimmed function. This prevents ICEing or generating incorrect code. Closes #16739
1 parent 1600e0b commit 4a4a434

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/librustc/middle/trans/callee.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,32 @@ pub fn trans_unboxing_shim(bcx: Block,
281281
};
282282
let boxed_function_type =
283283
ty::mk_bare_fn(tcx, boxed_function_type).subst(tcx, &substs);
284-
let function_type =
285-
ty::mk_bare_fn(tcx, (*fty).clone()).subst(tcx, &substs);
284+
let function_type = match fty.abi {
285+
synabi::RustCall => {
286+
// We're passing through to a RustCall ABI function, but
287+
// because the shim will already perform untupling, we
288+
// need to pretend the shimmed function does not use
289+
// RustCall so the untupled arguments can be passed
290+
// through verbatim. This is kind of ugly.
291+
let fake_ty = ty::FnSig {
292+
binder_id: fty.sig.binder_id,
293+
inputs: type_of::untuple_arguments_if_necessary(ccx,
294+
fty.sig.inputs.as_slice(),
295+
fty.abi),
296+
output: fty.sig.output,
297+
variadic: false,
298+
};
299+
let fake_ty = ty::BareFnTy {
300+
fn_style: fty.fn_style,
301+
abi: synabi::Rust,
302+
sig: fake_ty,
303+
};
304+
ty::mk_bare_fn(tcx, fake_ty).subst(tcx, &substs)
305+
}
306+
_ => {
307+
ty::mk_bare_fn(tcx, (*fty).clone()).subst(tcx, &substs)
308+
}
309+
};
286310

287311
let function_name = ty::with_path(tcx, method_id, |path| {
288312
link::mangle_internal_name_by_path_and_seq(path, "unboxing_shim")

src/librustc/middle/trans/type_of.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ pub fn type_of_explicit_arg(ccx: &CrateContext, arg_ty: ty::t) -> Type {
4444
/// Yields the types of the "real" arguments for this function. For most
4545
/// functions, these are simply the types of the arguments. For functions with
4646
/// the `RustCall` ABI, however, this untuples the arguments of the function.
47-
fn untuple_arguments_if_necessary(ccx: &CrateContext,
48-
inputs: &[ty::t],
49-
abi: abi::Abi)
50-
-> Vec<ty::t> {
47+
pub fn untuple_arguments_if_necessary(ccx: &CrateContext,
48+
inputs: &[ty::t],
49+
abi: abi::Abi)
50+
-> Vec<ty::t> {
5151
if abi != abi::RustCall {
5252
return inputs.iter().map(|x| (*x).clone()).collect()
5353
}

0 commit comments

Comments
 (0)