@@ -103,7 +103,7 @@ pub fn drop_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> block {
103103 ty:: ty_box( _) | ty:: ty_opaque_box |
104104 ty:: ty_evec( _, ty:: vstore_box) |
105105 ty:: ty_estr( ty:: vstore_box) => {
106- decr_refcnt_maybe_free ( bcx, v, t)
106+ decr_refcnt_maybe_free ( bcx, v, None , t)
107107 }
108108 _ => bcx. tcx ( ) . sess . bug ( "drop_ty_immediate: non-box ty" )
109109 }
@@ -520,7 +520,7 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
520520 let bcx = match ty:: get ( t) . sty {
521521 ty:: ty_box( _) | ty:: ty_opaque_box |
522522 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)
524524 }
525525 ty:: ty_uniq( _) |
526526 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) {
545545 closure:: make_closure_glue ( bcx, v0, t, drop_ty)
546546 }
547547 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 ) )
550552 }
551553 ty:: ty_trait( _, _, ty:: UniqTraitStore , _) => {
552554 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) {
580582 build_return ( bcx) ;
581583}
582584
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 )
584589 -> block {
585590 let _icx = bcx. insn_ctxt ( "decr_refcnt_maybe_free" ) ;
586591 let ccx = bcx. ccx ( ) ;
@@ -590,7 +595,12 @@ pub fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef, t: ty::t)
590595 let rc = Sub ( bcx, Load ( bcx, rc_ptr) , C_int ( ccx, 1 ) ) ;
591596 Store ( bcx, rc, rc_ptr) ;
592597 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+ }
594604 }
595605}
596606
0 commit comments