Skip to content

Commit 04af24d

Browse files
committed
Don't use codegen_call_inner in codegen_drop
1 parent 40cdcf0 commit 04af24d

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/abi/mod.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -655,19 +655,18 @@ pub(crate) fn codegen_drop<'tcx>(
655655
// we don't actually need to drop anything
656656
} else {
657657
let drop_fn_ty = drop_fn.monomorphic_ty(fx.tcx);
658+
let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(
659+
ParamEnv::reveal_all(),
660+
&drop_fn_ty.fn_sig(fx.tcx),
661+
);
662+
assert_eq!(fn_sig.output(), fx.tcx.mk_unit());
663+
658664
match ty.kind {
659665
ty::Dynamic(..) => {
660666
let (ptr, vtable) = drop_place.to_ptr_maybe_unsized();
661667
let ptr = ptr.get_addr(fx);
662668
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable.unwrap());
663669

664-
let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(
665-
ParamEnv::reveal_all(),
666-
&drop_fn_ty.fn_sig(fx.tcx),
667-
);
668-
669-
assert_eq!(fn_sig.output(), fx.tcx.mk_unit());
670-
671670
let sig = clif_sig_from_fn_sig(
672671
fx.tcx,
673672
fx.triple(),
@@ -679,6 +678,15 @@ pub(crate) fn codegen_drop<'tcx>(
679678
fx.bcx.ins().call_indirect(sig, drop_fn, &[ptr]);
680679
}
681680
_ => {
681+
let instance = match drop_fn_ty.kind {
682+
ty::FnDef(def_id, substs) => {
683+
Instance::resolve(fx.tcx, ParamEnv::reveal_all(), def_id, substs).unwrap()
684+
}
685+
_ => unreachable!("{:?}", drop_fn_ty),
686+
};
687+
688+
assert!(!matches!(instance.def, InstanceDef::Virtual(_, _)));
689+
682690
let arg_place = CPlace::new_stack_slot(
683691
fx,
684692
fx.layout_of(fx.tcx.mk_ref(
@@ -691,7 +699,18 @@ pub(crate) fn codegen_drop<'tcx>(
691699
);
692700
drop_place.write_place_ref(fx, arg_place);
693701
let arg_value = arg_place.to_cvalue(fx);
694-
codegen_call_inner(fx, span, None, drop_fn_ty, vec![arg_value], None);
702+
let arg_value = adjust_arg_for_abi(fx, arg_value);
703+
704+
let mut call_args: Vec<Value> = arg_value.into_iter().collect::<Vec<_>>();
705+
706+
if instance.def.requires_caller_location(fx.tcx) {
707+
// Pass the caller location for `#[track_caller]`.
708+
let caller_location = fx.get_caller_location(span);
709+
call_args.extend(adjust_arg_for_abi(fx, caller_location).into_iter());
710+
}
711+
712+
let func_ref = fx.get_function_ref(instance);
713+
fx.bcx.ins().call(func_ref, &call_args);
695714
}
696715
}
697716
}

0 commit comments

Comments
 (0)