Skip to content

Commit 721164d

Browse files
committed
Zero the struct in the take glue, not the drop glue
1 parent d9f6dd2 commit 721164d

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/librustc/middle/trans/glue.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,6 @@ pub fn trans_struct_drop(mut bcx: block, t: ty::t, v0: ValueRef, dtor_did: ast::
484484
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
485485
}
486486

487-
// Zero out the struct
488-
unsafe {
489-
let ty = Type::from_ref(llvm::LLVMTypeOf(v0));
490-
memzero(bcx, v0, ty);
491-
}
492-
493487
bcx
494488
}
495489

@@ -635,6 +629,23 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) {
635629
ty::ty_opaque_closure_ptr(ck) => {
636630
closure::make_opaque_cbox_take_glue(bcx, ck, v)
637631
}
632+
ty::ty_struct(did, ref substs) => {
633+
let tcx = bcx.tcx();
634+
let bcx = iter_structural_ty(bcx, v, t, take_ty);
635+
636+
match ty::ty_dtor(tcx, did) {
637+
ty::TraitDtor(dtor, false) => {
638+
// Zero out the struct
639+
unsafe {
640+
let ty = Type::from_ref(llvm::LLVMTypeOf(v));
641+
memzero(bcx, v, ty);
642+
}
643+
644+
}
645+
_ => { }
646+
}
647+
bcx
648+
}
638649
_ if ty::type_is_structural(t) => {
639650
iter_structural_ty(bcx, v, t, take_ty)
640651
}

0 commit comments

Comments
 (0)