about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2011-09-27 20:20:51 +0200
committerMarijn Haverbeke <marijnh@gmail.com>2011-09-27 20:33:09 +0200
commite42f3b8481049fd3626c24b95297282b68df1436 (patch)
treeaf896b63d80dd61658dab18e44d6c658084620cd /src/comp
parent923aa4744eed0a2e82c89605221ac3aad616ee05 (diff)
Safeguard against self-assignment for unique types
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/trans.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 8902e76e7df..6c8d9d6bb0d 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -2020,13 +2020,15 @@ fn type_is_structural_or_param(tcx: ty::ctxt, t: ty::t) -> bool {
 
 fn copy_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
             src: ValueRef, t: ty::t) -> @block_ctxt {
-    if type_is_structural_or_param(bcx_ccx(cx).tcx, t) &&
-           action == DROP_EXISTING {
+    if action == DROP_EXISTING &&
+        (type_is_structural_or_param(bcx_tcx(cx), t) ||
+         ty::type_is_unique(bcx_tcx(cx), t)) {
         let do_copy_cx = new_sub_block_ctxt(cx, "do_copy");
         let next_cx = new_sub_block_ctxt(cx, "next");
+        let dstcmp = load_if_immediate(cx, dst, t);
         let self_assigning =
-            ICmp(cx, lib::llvm::LLVMIntNE, PointerCast(cx, dst, val_ty(src)),
-                 src);
+            ICmp(cx, lib::llvm::LLVMIntNE,
+                 PointerCast(cx, dstcmp, val_ty(src)), src);
         CondBr(cx, self_assigning, do_copy_cx.llbb, next_cx.llbb);
         do_copy_cx = copy_val_no_check(do_copy_cx, action, dst, src, t);
         Br(do_copy_cx, next_cx.llbb);