Fix a bug when the same function is called with different signatures
This commit is contained in:
parent
ab00acfb55
commit
3a0f5dc9ec
10
example.rs
10
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 {
|
||||
|
@ -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 @@ 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)
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user