fix dropping with vtables
This commit is contained in:
parent
e860ab2dab
commit
09b15e9856
2 changed files with 14 additions and 6 deletions
|
@ -30,24 +30,29 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
|
||||||
) -> EvalResult<'tcx> {
|
) -> EvalResult<'tcx> {
|
||||||
trace!("drop: {:?},\n {:?}, {:?}", arg, ty.sty, instance.def);
|
trace!("drop: {:?},\n {:?}, {:?}", arg, ty.sty, instance.def);
|
||||||
|
|
||||||
let instance = match ty.sty {
|
let (instance, arg) = match ty.sty {
|
||||||
ty::TyDynamic(..) => {
|
ty::TyDynamic(..) => {
|
||||||
if let Value::ScalarPair(_, vtable) = arg {
|
if let Value::ScalarPair(ptr, vtable) = arg {
|
||||||
self.read_drop_type_from_vtable(vtable.to_ptr()?)?
|
// Figure out the specific drop function to call, and just pass along
|
||||||
|
// the thin part of the pointer.
|
||||||
|
let instance = self.read_drop_type_from_vtable(vtable.to_ptr()?)?;
|
||||||
|
trace!("Dropping via vtable: {:?}", instance.def);
|
||||||
|
(instance, Value::Scalar(ptr))
|
||||||
} else {
|
} else {
|
||||||
bug!("expected fat ptr, got {:?}", arg);
|
bug!("expected fat ptr, got {:?}", arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => instance,
|
_ => (instance, arg),
|
||||||
};
|
};
|
||||||
|
|
||||||
// the drop function expects a reference to the value
|
// the drop function expects a reference to the value
|
||||||
|
let fn_sig = self.tcx.fn_sig(instance.def_id()).skip_binder().clone();
|
||||||
let arg = OpTy {
|
let arg = OpTy {
|
||||||
op: Operand::Immediate(arg),
|
op: Operand::Immediate(arg),
|
||||||
layout: self.layout_of(self.tcx.mk_mut_ptr(ty))?,
|
layout: self.layout_of(fn_sig.output())?,
|
||||||
};
|
};
|
||||||
|
trace!("Dropped type: {:?}", fn_sig.output());
|
||||||
|
|
||||||
let fn_sig = self.tcx.fn_sig(instance.def_id()).skip_binder().clone();
|
|
||||||
// This should always be (), but getting it from the sig seems
|
// This should always be (), but getting it from the sig seems
|
||||||
// easier than creating a layout of ().
|
// easier than creating a layout of ().
|
||||||
let dest = PlaceTy::null(&self, self.layout_of(fn_sig.output())?);
|
let dest = PlaceTy::null(&self, self.layout_of(fn_sig.output())?);
|
||||||
|
|
|
@ -257,6 +257,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
|
||||||
sig: ty::FnSig<'tcx>,
|
sig: ty::FnSig<'tcx>,
|
||||||
) -> EvalResult<'tcx> {
|
) -> EvalResult<'tcx> {
|
||||||
trace!("eval_fn_call: {:#?}", instance);
|
trace!("eval_fn_call: {:#?}", instance);
|
||||||
|
if let Some((place, _)) = destination {
|
||||||
|
assert_eq!(place.layout.ty, sig.output());
|
||||||
|
}
|
||||||
match instance.def {
|
match instance.def {
|
||||||
ty::InstanceDef::Intrinsic(..) => {
|
ty::InstanceDef::Intrinsic(..) => {
|
||||||
let (ret, target) = match destination {
|
let (ret, target) = match destination {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue