Skip to content

Commit 898e089

Browse files
committed
Fix and re-enable destructors
There was some confusion on whether the destructors took their argument by pointer or direct value. They now take it directly, just like other methods. You no longer get a segfault when a constructor actually does something with its self value.
1 parent cdb6822 commit 898e089

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/comp/middle/trans.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,9 +1971,7 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v0, ty.t t) {
19711971
C_int(abi.obj_body_elt_tydesc)));
19721972
auto tydesc = cx.build.Load(tydescptr);
19731973

1974-
// FIXME: disabled for now.
1975-
// auto cx_ = maybe_call_dtor(cx, o);
1976-
auto cx_ = cx;
1974+
auto cx_ = maybe_call_dtor(cx, o);
19771975

19781976
// Call through the obj's own fields-drop glue first.
19791977
call_tydesc_glue_full(cx_, body, tydesc,
@@ -2771,18 +2769,19 @@ fn maybe_call_dtor(@block_ctxt cx, ValueRef v) -> @block_ctxt {
27712769
vtbl = cx.build.Load(vtbl);
27722770
auto dtor_ptr = cx.build.GEP(vtbl, vec(C_int(0), C_int(0)));
27732771
dtor_ptr = cx.build.Load(dtor_ptr);
2772+
auto self_t = llvm.LLVMGetElementType(val_ty(v));
27742773
dtor_ptr = cx.build.BitCast(dtor_ptr,
2775-
T_ptr(T_dtor(cx.fcx.lcx.ccx, val_ty(v))));
2774+
T_ptr(T_dtor(cx.fcx.lcx.ccx, self_t)));
27762775

27772776
auto dtor_cx = new_sub_block_ctxt(cx, "dtor");
27782777
auto after_cx = new_sub_block_ctxt(cx, "after_dtor");
27792778
auto test = cx.build.ICmp(lib.llvm.LLVMIntNE, dtor_ptr,
27802779
C_null(val_ty(dtor_ptr)));
27812780
cx.build.CondBr(test, dtor_cx.llbb, after_cx.llbb);
27822781

2783-
// FIXME need to pass type params (?)
2782+
auto me = dtor_cx.build.Load(v);
27842783
dtor_cx.build.FastCall(dtor_ptr, vec(C_null(T_ptr(T_nil())),
2785-
cx.fcx.lltaskptr, v));
2784+
cx.fcx.lltaskptr, me));
27862785
dtor_cx.build.Br(after_cx.llbb);
27872786
ret after_cx;
27882787
}
@@ -6357,6 +6356,8 @@ fn trans_obj(@local_ctxt cx, &ast._obj ob, ast.def_id oid,
63576356

63586357
let TypeRef llbox_ty = T_opaque_obj_ptr(ccx.tn);
63596358

6359+
// FIXME we should probably also allocate a box for empty objs that have a
6360+
// dtor, since otherwise they are never dropped, and the dtor never runs
63606361
if (_vec.len[ast.ty_param](ty_params) == 0u &&
63616362
_vec.len[ty.arg](arg_tys) == 0u) {
63626363
// Store null into pair, if no args or typarams.

0 commit comments

Comments
 (0)