]> git.lizzy.rs Git - rust.git/commitdiff
Use precise return type to allocate retslot in trans_args
authorMarijn Haverbeke <marijnh@gmail.com>
Thu, 5 Jan 2012 21:45:02 +0000 (22:45 +0100)
committerMarijn Haverbeke <marijnh@gmail.com>
Thu, 5 Jan 2012 21:45:02 +0000 (22:45 +0100)
Using type_of_or_i8 did, predictably, allocate an i8 for a type parameter,
which leads to memory corruption and general confusion.

Closes #1443

src/comp/middle/trans.rs

index 1160c8de627f4d342ca9ca3afa34396ff6f6ecfb..388268953a17b1b62b64e67ca1f3cf4c3d23e4f3 100644 (file)
@@ -3176,15 +3176,22 @@ fn trans_args(cx: @block_ctxt, llenv: ValueRef,
       _ { }
     }
     // Arg 0: Output pointer.
-    let llretty = type_of_or_i8(bcx, full_retty);
     let llretslot = alt dest {
       ignore. {
         if ty::type_is_nil(tcx, retty) {
-            llvm::LLVMGetUndef(T_ptr(llretty))
-        } else { alloca(cx, llretty) }
+            llvm::LLVMGetUndef(T_ptr(T_nil()))
+        } else {
+            let {bcx: cx, val} = alloc_ty(bcx, full_retty);
+            bcx = cx;
+            val
+        }
       }
       save_in(dst) { dst }
-      by_val(_) { alloca(cx, llretty) }
+      by_val(_) {
+          let {bcx: cx, val} = alloc_ty(bcx, full_retty);
+          bcx = cx;
+          val
+      }
     };
 
     if ty::type_contains_params(tcx, retty) {