@@ -1971,9 +1971,7 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v0, ty.t t) {
1971
1971
C_int ( abi. obj_body_elt_tydesc ) ) ) ;
1972
1972
auto tydesc = cx. build . Load ( tydescptr) ;
1973
1973
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) ;
1977
1975
1978
1976
// Call through the obj's own fields-drop glue first.
1979
1977
call_tydesc_glue_full ( cx_, body, tydesc,
@@ -2771,18 +2769,19 @@ fn maybe_call_dtor(@block_ctxt cx, ValueRef v) -> @block_ctxt {
2771
2769
vtbl = cx. build. Load ( vtbl) ;
2772
2770
auto dtor_ptr = cx. build. GEP ( vtbl, vec( C_int ( 0 ) , C_int ( 0 ) ) ) ;
2773
2771
dtor_ptr = cx. build. Load ( dtor_ptr) ;
2772
+ auto self_t = llvm. LLVMGetElementType ( val_ty( v) ) ;
2774
2773
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 ) ) ) ;
2776
2775
2777
2776
auto dtor_cx = new_sub_block_ctxt( cx, "dtor") ;
2778
2777
auto after_cx = new_sub_block_ctxt( cx, "after_dtor") ;
2779
2778
auto test = cx. build. ICmp ( lib. llvm. LLVMIntNE , dtor_ptr,
2780
2779
C_null ( val_ty( dtor_ptr) ) ) ;
2781
2780
cx. build. CondBr ( test, dtor_cx. llbb, after_cx. llbb) ;
2782
2781
2783
- // FIXME need to pass type params (?)
2782
+ auto me = dtor_cx . build . Load ( v ) ;
2784
2783
dtor_cx. build. FastCall ( dtor_ptr, vec( C_null ( T_ptr ( T_nil ( ) ) ) ,
2785
- cx. fcx. lltaskptr, v ) ) ;
2784
+ cx. fcx. lltaskptr, me ) ) ;
2786
2785
dtor_cx. build. Br ( after_cx. llbb) ;
2787
2786
ret after_cx;
2788
2787
}
@@ -6357,6 +6356,8 @@ fn trans_obj(@local_ctxt cx, &ast._obj ob, ast.def_id oid,
6357
6356
6358
6357
let TypeRef llbox_ty = T_opaque_obj_ptr ( ccx. tn) ;
6359
6358
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
6360
6361
if ( _vec. len[ ast. ty_param] ( ty_params) == 0 u &&
6361
6362
_vec. len[ ty. arg] ( arg_tys) == 0 u) {
6362
6363
// Store null into pair, if no args or typarams.
0 commit comments