rustc: Check for null before dropping ~objects. #5192
This commit is contained in:
parent
6e2b082adc
commit
d213443a67
2 changed files with 40 additions and 13 deletions
|
|
@ -546,20 +546,23 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
|
|||
decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx))
|
||||
}
|
||||
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
|
||||
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
|
||||
let llvtable = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
|
||||
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
|
||||
// Only drop the value when it is non-null
|
||||
do with_cond(bcx, IsNotNull(bcx, Load(bcx, lluniquevalue))) |bcx| {
|
||||
let llvtable = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
|
||||
|
||||
// Cast the vtable to a pointer to a pointer to a tydesc.
|
||||
let llvtable = PointerCast(bcx,
|
||||
llvtable,
|
||||
T_ptr(T_ptr(ccx.tydesc_type)));
|
||||
let lltydesc = Load(bcx, llvtable);
|
||||
call_tydesc_glue_full(bcx,
|
||||
lluniquevalue,
|
||||
lltydesc,
|
||||
abi::tydesc_field_free_glue,
|
||||
None);
|
||||
bcx
|
||||
// Cast the vtable to a pointer to a pointer to a tydesc.
|
||||
let llvtable = PointerCast(bcx,
|
||||
llvtable,
|
||||
T_ptr(T_ptr(ccx.tydesc_type)));
|
||||
let lltydesc = Load(bcx, llvtable);
|
||||
call_tydesc_glue_full(bcx,
|
||||
lluniquevalue,
|
||||
lltydesc,
|
||||
abi::tydesc_field_free_glue,
|
||||
None);
|
||||
bcx
|
||||
}
|
||||
}
|
||||
ty::ty_opaque_closure_ptr(ck) => {
|
||||
closure::make_opaque_cbox_drop_glue(bcx, ck, v0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue