Skip to content

Commit e42f3b8

Browse files
committed
Safeguard against self-assignment for unique types
1 parent 923aa47 commit e42f3b8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/comp/middle/trans.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,13 +2020,15 @@ fn type_is_structural_or_param(tcx: ty::ctxt, t: ty::t) -> bool {
20202020

20212021
fn copy_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
20222022
src: ValueRef, t: ty::t) -> @block_ctxt {
2023-
if type_is_structural_or_param(bcx_ccx(cx).tcx, t) &&
2024-
action == DROP_EXISTING {
2023+
if action == DROP_EXISTING &&
2024+
(type_is_structural_or_param(bcx_tcx(cx), t) ||
2025+
ty::type_is_unique(bcx_tcx(cx), t)) {
20252026
let do_copy_cx = new_sub_block_ctxt(cx, "do_copy");
20262027
let next_cx = new_sub_block_ctxt(cx, "next");
2028+
let dstcmp = load_if_immediate(cx, dst, t);
20272029
let self_assigning =
2028-
ICmp(cx, lib::llvm::LLVMIntNE, PointerCast(cx, dst, val_ty(src)),
2029-
src);
2030+
ICmp(cx, lib::llvm::LLVMIntNE,
2031+
PointerCast(cx, dstcmp, val_ty(src)), src);
20302032
CondBr(cx, self_assigning, do_copy_cx.llbb, next_cx.llbb);
20312033
do_copy_cx = copy_val_no_check(do_copy_cx, action, dst, src, t);
20322034
Br(do_copy_cx, next_cx.llbb);

0 commit comments

Comments
 (0)