@@ -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
}
@@ -520,7 +520,7 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
520
520
let bcx = match ty:: get ( t) . sty {
521
521
ty:: ty_box( _) | ty:: ty_opaque_box |
522
522
ty:: ty_estr( ty:: vstore_box) | ty:: ty_evec( _, ty:: vstore_box) => {
523
- decr_refcnt_maybe_free ( bcx, Load ( bcx, v0) , t)
523
+ decr_refcnt_maybe_free ( bcx, Load ( bcx, v0) , Some ( v0 ) , t)
524
524
}
525
525
ty:: ty_uniq( _) |
526
526
ty:: ty_evec( _, ty:: vstore_uniq) | ty:: ty_estr( ty:: vstore_uniq) => {
@@ -545,8 +545,10 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
545
545
closure:: make_closure_glue ( bcx, v0, t, drop_ty)
546
546
}
547
547
ty:: ty_trait( _, _, ty:: BoxTraitStore , _) => {
548
- let llbox = Load ( bcx, GEPi ( bcx, v0, [ 0 u, abi:: trt_field_box] ) ) ;
549
- decr_refcnt_maybe_free ( bcx, llbox, ty:: mk_opaque_box ( ccx. tcx ) )
548
+ let llbox_ptr = GEPi ( bcx, v0, [ 0 u, abi:: trt_field_box] ) ;
549
+ let llbox = Load ( bcx, llbox_ptr) ;
550
+ decr_refcnt_maybe_free ( bcx, llbox, Some ( llbox_ptr) ,
551
+ ty:: mk_opaque_box ( ccx. tcx ) )
550
552
}
551
553
ty:: ty_trait( _, _, ty:: UniqTraitStore , _) => {
552
554
let lluniquevalue = GEPi ( bcx, v0, [ 0 , abi:: trt_field_box] ) ;
@@ -580,7 +582,10 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
580
582
build_return ( bcx) ;
581
583
}
582
584
583
- pub fn decr_refcnt_maybe_free ( bcx : block , box_ptr : ValueRef , t : ty:: t )
585
+ // box_ptr_ptr is optional, it is constructed if not supplied.
586
+ pub fn decr_refcnt_maybe_free ( bcx : block , box_ptr : ValueRef ,
587
+ box_ptr_ptr : Option < ValueRef > ,
588
+ t : ty:: t )
584
589
-> block {
585
590
let _icx = bcx. insn_ctxt ( "decr_refcnt_maybe_free" ) ;
586
591
let ccx = bcx. ccx ( ) ;
@@ -590,7 +595,12 @@ pub fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef, t: ty::t)
590
595
let rc = Sub ( bcx, Load ( bcx, rc_ptr) , C_int ( ccx, 1 ) ) ;
591
596
Store ( bcx, rc, rc_ptr) ;
592
597
let zero_test = ICmp ( bcx, lib:: llvm:: IntEQ , C_int ( ccx, 0 ) , rc) ;
593
- with_cond ( bcx, zero_test, |bcx| free_ty_immediate ( bcx, box_ptr, t) )
598
+ do with_cond( bcx, zero_test) |bcx| {
599
+ match box_ptr_ptr {
600
+ Some ( p) => free_ty ( bcx, p, t) ,
601
+ None => free_ty_immediate ( bcx, box_ptr, t)
602
+ }
603
+ }
594
604
}
595
605
}
596
606
0 commit comments