Avoid temporary stack slot in drop codegen

cc #322
This commit is contained in:
bjorn3
2020-08-25 18:31:59 +02:00
parent a9a262ad5a
commit 5dec38e94c
3 changed files with 18 additions and 20 deletions
+7 -12
View File
@@ -700,18 +700,13 @@ pub(crate) fn codegen_drop<'tcx>(
_ => {
assert!(!matches!(drop_fn.def, InstanceDef::Virtual(_, _)));
let arg_place = CPlace::new_stack_slot(
fx,
fx.layout_of(fx.tcx.mk_ref(
&ty::RegionKind::ReErased,
TypeAndMut {
ty,
mutbl: crate::rustc_hir::Mutability::Mut,
},
)),
);
drop_place.write_place_ref(fx, arg_place);
let arg_value = arg_place.to_cvalue(fx);
let arg_value = drop_place.place_ref(fx, fx.layout_of(fx.tcx.mk_ref(
&ty::RegionKind::ReErased,
TypeAndMut {
ty,
mutbl: crate::rustc_hir::Mutability::Mut,
},
)));
let arg_value = adjust_arg_for_abi(fx, arg_value);
let mut call_args: Vec<Value> = arg_value.into_iter().collect::<Vec<_>>();
+2 -1
View File
@@ -405,7 +405,8 @@ fn trans_stmt<'tcx>(
}
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
let place = trans_place(fx, *place);
place.write_place_ref(fx, lval);
let ref_ = place.place_ref(fx, lval.layout());
lval.write_cvalue(fx, ref_);
}
Rvalue::ThreadLocalRef(def_id) => {
let val = crate::constant::codegen_tls_ref(fx, *def_id, lval.layout());
+9 -7
View File
@@ -681,18 +681,20 @@ pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) ->
}
}
pub(crate) fn write_place_ref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, dest: CPlace<'tcx>) {
pub(crate) fn place_ref(
self,
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
layout: TyAndLayout<'tcx>,
) -> CValue<'tcx> {
if has_ptr_meta(fx.tcx, self.layout().ty) {
let (ptr, extra) = self.to_ptr_maybe_unsized();
let ptr = CValue::by_val_pair(
CValue::by_val_pair(
ptr.get_addr(fx),
extra.expect("unsized type without metadata"),
dest.layout(),
);
dest.write_cvalue(fx, ptr);
layout,
)
} else {
let ptr = CValue::by_val(self.to_ptr().get_addr(fx), dest.layout());
dest.write_cvalue(fx, ptr);
CValue::by_val(self.to_ptr().get_addr(fx), layout)
}
}