Skip to content

Commit 09b15e9

Browse files
committed
fix dropping with vtables
1 parent e860ab2 commit 09b15e9

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/librustc_mir/interpret/terminator/drop.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,29 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
3030
) -> EvalResult<'tcx> {
3131
trace!("drop: {:?},\n {:?}, {:?}", arg, ty.sty, instance.def);
3232

33-
let instance = match ty.sty {
33+
let (instance, arg) = match ty.sty {
3434
ty::TyDynamic(..) => {
35-
if let Value::ScalarPair(_, vtable) = arg {
36-
self.read_drop_type_from_vtable(vtable.to_ptr()?)?
35+
if let Value::ScalarPair(ptr, vtable) = arg {
36+
// Figure out the specific drop function to call, and just pass along
37+
// the thin part of the pointer.
38+
let instance = self.read_drop_type_from_vtable(vtable.to_ptr()?)?;
39+
trace!("Dropping via vtable: {:?}", instance.def);
40+
(instance, Value::Scalar(ptr))
3741
} else {
3842
bug!("expected fat ptr, got {:?}", arg);
3943
}
4044
}
41-
_ => instance,
45+
_ => (instance, arg),
4246
};
4347

4448
// the drop function expects a reference to the value
49+
let fn_sig = self.tcx.fn_sig(instance.def_id()).skip_binder().clone();
4550
let arg = OpTy {
4651
op: Operand::Immediate(arg),
47-
layout: self.layout_of(self.tcx.mk_mut_ptr(ty))?,
52+
layout: self.layout_of(fn_sig.output())?,
4853
};
54+
trace!("Dropped type: {:?}", fn_sig.output());
4955

50-
let fn_sig = self.tcx.fn_sig(instance.def_id()).skip_binder().clone();
5156
// This should always be (), but getting it from the sig seems
5257
// easier than creating a layout of ().
5358
let dest = PlaceTy::null(&self, self.layout_of(fn_sig.output())?);

src/librustc_mir/interpret/terminator/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
257257
sig: ty::FnSig<'tcx>,
258258
) -> EvalResult<'tcx> {
259259
trace!("eval_fn_call: {:#?}", instance);
260+
if let Some((place, _)) = destination {
261+
assert_eq!(place.layout.ty, sig.output());
262+
}
260263
match instance.def {
261264
ty::InstanceDef::Intrinsic(..) => {
262265
let (ret, target) = match destination {

0 commit comments

Comments
 (0)