Skip to content

Commit 8cf3ca3

Browse files
committed
Make sure by-copy arguments take last-use into account
1 parent 1cccefd commit 8cf3ca3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/comp/middle/trans.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3621,13 +3621,19 @@ fn trans_arg_expr(cx: @block_ctxt, arg: ty::arg, lldestty0: TypeRef,
36213621
}
36223622
} else if arg.mode == ast::by_copy {
36233623
let {bcx: cx, val: alloc} = alloc_ty(bcx, e_ty);
3624+
let last_use = ccx.last_uses.contains_key(e.id);
36243625
bcx = cx;
36253626
if lv.kind == temporary { revoke_clean(bcx, val); }
36263627
if lv.kind == owned || !ty::type_is_immediate(ccx.tcx, e_ty) {
36273628
bcx = memmove_ty(bcx, alloc, val, e_ty);
3629+
if last_use && ty::type_needs_drop(ccx.tcx, e_ty) {
3630+
bcx = zero_alloca(bcx, val, e_ty);
3631+
}
36283632
} else { Store(bcx, val, alloc); }
36293633
val = alloc;
3630-
if lv.kind != temporary { bcx = take_ty(bcx, val, e_ty); }
3634+
if lv.kind != temporary && !last_use {
3635+
bcx = take_ty(bcx, val, e_ty);
3636+
}
36313637
} else if ty::type_is_immediate(ccx.tcx, e_ty) && lv.kind != owned {
36323638
let r = do_spill(bcx, val, e_ty);
36333639
val = r.val;

0 commit comments

Comments
 (0)