@@ -103,7 +103,7 @@ pub fn drop_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> block {
103
103
ty:: ty_box( _) | ty:: ty_opaque_box |
104
104
ty:: ty_evec( _, ty:: vstore_box) |
105
105
ty:: ty_estr( ty:: vstore_box) => {
106
- decr_refcnt_maybe_free ( bcx, v, t)
106
+ decr_refcnt_maybe_free ( bcx, v, None , t)
107
107
}
108
108
_ => bcx. tcx ( ) . sess . bug ( "drop_ty_immediate: non-box ty" )
109
109
}
@@ -489,7 +489,7 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
489
489
let bcx = match ty:: get ( t) . sty {
490
490
ty:: ty_box( _) | ty:: ty_opaque_box |
491
491
ty:: ty_estr( ty:: vstore_box) | ty:: ty_evec( _, ty:: vstore_box) => {
492
- decr_refcnt_maybe_free ( bcx, Load ( bcx, v0) , t)
492
+ decr_refcnt_maybe_free ( bcx, Load ( bcx, v0) , Some ( v0 ) , t)
493
493
}
494
494
ty:: ty_uniq( _) |
495
495
ty:: ty_evec( _, ty:: vstore_uniq) | ty:: ty_estr( ty:: vstore_uniq) => {
@@ -514,8 +514,10 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
514
514
closure:: make_closure_glue ( bcx, v0, t, drop_ty)
515
515
}
516
516
ty:: ty_trait( _, _, ty:: BoxTraitStore , _) => {
517
- let llbox = Load ( bcx, GEPi ( bcx, v0, [ 0 u, abi:: trt_field_box] ) ) ;
518
- decr_refcnt_maybe_free ( bcx, llbox, ty:: mk_opaque_box ( ccx. tcx ) )
517
+ let llbox_ptr = GEPi ( bcx, v0, [ 0 u, abi:: trt_field_box] ) ;
518
+ let llbox = Load ( bcx, llbox_ptr) ;
519
+ decr_refcnt_maybe_free ( bcx, llbox, Some ( llbox_ptr) ,
520
+ ty:: mk_opaque_box ( ccx. tcx ) )
519
521
}
520
522
ty:: ty_trait( _, _, ty:: UniqTraitStore , _) => {
521
523
let lluniquevalue = GEPi ( bcx, v0, [ 0 , abi:: trt_field_box] ) ;
@@ -549,7 +551,10 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
549
551
build_return ( bcx) ;
550
552
}
551
553
552
- pub fn decr_refcnt_maybe_free ( bcx : block , box_ptr : ValueRef , t : ty:: t )
554
+ // box_ptr_ptr is optional, it is constructed if not supplied.
555
+ pub fn decr_refcnt_maybe_free ( bcx : block , box_ptr : ValueRef ,
556
+ box_ptr_ptr : Option < ValueRef > ,
557
+ t : ty:: t )
553
558
-> block {
554
559
let _icx = bcx. insn_ctxt ( "decr_refcnt_maybe_free" ) ;
555
560
let ccx = bcx. ccx ( ) ;
@@ -559,7 +564,12 @@ pub fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef, t: ty::t)
559
564
let rc = Sub ( bcx, Load ( bcx, rc_ptr) , C_int ( ccx, 1 ) ) ;
560
565
Store ( bcx, rc, rc_ptr) ;
561
566
let zero_test = ICmp ( bcx, lib:: llvm:: IntEQ , C_int ( ccx, 0 ) , rc) ;
562
- with_cond ( bcx, zero_test, |bcx| free_ty_immediate ( bcx, box_ptr, t) )
567
+ do with_cond( bcx, zero_test) |bcx| {
568
+ match box_ptr_ptr {
569
+ Some ( p) => free_ty ( bcx, p, t) ,
570
+ None => free_ty_immediate ( bcx, box_ptr, t)
571
+ }
572
+ }
563
573
}
564
574
}
565
575
0 commit comments