]> git.lizzy.rs Git - rust.git/commitdiff
Fix a bug when the same function is called with different signatures
authorbjorn3 <bjorn3@users.noreply.github.com>
Fri, 27 Jul 2018 17:01:38 +0000 (19:01 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Fri, 27 Jul 2018 17:01:38 +0000 (19:01 +0200)
example.rs
src/abi.rs
src/base.rs

index 1c67b6810ce71fd2303164133b74cf26da33b072..35e124c5d2d609b14b7bbdcdd45dd833b9b7bafb 100644 (file)
@@ -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 {
index 6e57d7ac5f7e59a0a3f7e7cbcfe764e705b3c958..251d9603aa6afec1d8baaded42f5f6de025d3423 100644 (file)
@@ -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<Ty> = sig.inputs()[0..sig.inputs().len() - 1].to_vec();
+            let mut inputs: Vec<Ty> = vec![sig.inputs()[0]];
             inputs.extend(extra_args.into_iter());
             (
                 CallConv::SystemV,
@@ -96,7 +97,10 @@ pub fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
         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)
     }
index 23dfab91f15833cfeb71cfacba23e32f72a33963..e58a8af828530503b892bb3e85bff79ba7fcd066 100644 (file)
@@ -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);