From: Marijn Haverbeke Date: Thu, 5 Jan 2012 21:45:02 +0000 (+0100) Subject: Use precise return type to allocate retslot in trans_args X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=54cf0e9c0d1151f82e86cab5488162bd7e0706a2;p=rust.git Use precise return type to allocate retslot in trans_args Using type_of_or_i8 did, predictably, allocate an i8 for a type parameter, which leads to memory corruption and general confusion. Closes #1443 --- diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 1160c8de627..388268953a1 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -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) {