@@ -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 }
@@ -489,7 +489,7 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
489489 let bcx = match ty:: get ( t) . sty {
490490 ty:: ty_box( _) | ty:: ty_opaque_box |
491491 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)
493493 }
494494 ty:: ty_uniq( _) |
495495 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) {
514514 closure:: make_closure_glue ( bcx, v0, t, drop_ty)
515515 }
516516 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 ) )
519521 }
520522 ty:: ty_trait( _, _, ty:: UniqTraitStore , _) => {
521523 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) {
549551 build_return ( bcx) ;
550552}
551553
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 )
553558 -> block {
554559 let _icx = bcx. insn_ctxt ( "decr_refcnt_maybe_free" ) ;
555560 let ccx = bcx. ccx ( ) ;
@@ -559,7 +564,12 @@ pub fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef, t: ty::t)
559564 let rc = Sub ( bcx, Load ( bcx, rc_ptr) , C_int ( ccx, 1 ) ) ;
560565 Store ( bcx, rc, rc_ptr) ;
561566 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+ }
563573 }
564574}
565575
0 commit comments