From 3a0f5dc9ec47f7295a534b2aca7795591ce4a3a0 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 27 Jul 2018 19:01:38 +0200 Subject: [PATCH] Fix a bug when the same function is called with different signatures --- example.rs | 10 ++++++++-- src/abi.rs | 8 ++++++-- src/base.rs | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/example.rs b/example.rs index 1c67b6810ce..35e124c5d2d 100644 --- a/example.rs +++ b/example.rs @@ -110,10 +110,16 @@ fn use_const() -> u8 { Abc } -fn call_closure() { +fn call_closure_3arg() { (|_, _, _| { - })(0u8, 42u8, 0u8) + })(0u8, 42u16, 0u8) +} + +fn call_closure_2arg() { + (|_, _| { + + })(0u8, 42u16) } fn eq_char(a: char, b: char) -> bool { diff --git a/src/abi.rs b/src/abi.rs index 6e57d7ac5f7..251d9603aa6 100644 --- a/src/abi.rs +++ b/src/abi.rs @@ -12,11 +12,12 @@ pub fn cton_sig_from_fn_ty<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn_ty: Ty< Abi::Rust => (CallConv::SystemV, sig.inputs().to_vec(), sig.output()), Abi::RustCall => { println!("rust-call sig: {:?} inputs: {:?} output: {:?}", sig, sig.inputs(), sig.output()); + assert_eq!(sig.inputs().len(), 2); let extra_args = match sig.inputs().last().unwrap().sty { ty::TyTuple(ref tupled_arguments) => tupled_arguments, _ => bug!("argument to function with \"rust-call\" ABI is not a tuple"), }; - let mut inputs: Vec = sig.inputs()[0..sig.inputs().len() - 1].to_vec(); + let mut inputs: Vec = vec![sig.inputs()[0]]; inputs.extend(extra_args.into_iter()); ( CallConv::SystemV, @@ -96,7 +97,10 @@ impl<'a, 'tcx: 'a> FunctionCx<'a, 'tcx> { let func_id = *self.def_id_fn_id_map.entry(inst).or_insert_with(|| { let fn_ty = inst.ty(tcx); let sig = cton_sig_from_fn_ty(tcx, fn_ty); - module.declare_function(&tcx.absolute_item_path_str(inst.def_id()), Linkage::Local, &sig).unwrap() + let def_path_based_names = ::rustc_mir::monomorphize::item::DefPathBasedNames::new(tcx, false, false); + let mut name = String::new(); + def_path_based_names.push_instance_as_string(inst, &mut name); + module.declare_function(&name, Linkage::Local, &sig).unwrap() }); module.declare_func_in_func(func_id, &mut self.bcx.func) } diff --git a/src/base.rs b/src/base.rs index 23dfab91f15..e58a8af8285 100644 --- a/src/base.rs +++ b/src/base.rs @@ -23,6 +23,7 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(cx: &mut CodegenCx<'a, 'tcx, CurrentBackend let func_id = { let module = &mut cx.module; *cx.def_id_fn_id_map.entry(inst).or_insert_with(|| { + // WARNING: keep in sync with FunctionCx::get_function_ref let def_path_based_names = ::rustc_mir::monomorphize::item::DefPathBasedNames::new(tcx, false, false); let mut name = String::new(); def_path_based_names.push_instance_as_string(inst, &mut name);