Skip to content

Commit 54cf0e9

Browse files
committed
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
1 parent 75f84b2 commit 54cf0e9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/comp/middle/trans.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,15 +3176,22 @@ fn trans_args(cx: @block_ctxt, llenv: ValueRef,
31763176
_ { }
31773177
}
31783178
// Arg 0: Output pointer.
3179-
let llretty = type_of_or_i8(bcx, full_retty);
31803179
let llretslot = alt dest {
31813180
ignore. {
31823181
if ty::type_is_nil(tcx, retty) {
3183-
llvm::LLVMGetUndef(T_ptr(llretty))
3184-
} else { alloca(cx, llretty) }
3182+
llvm::LLVMGetUndef(T_ptr(T_nil()))
3183+
} else {
3184+
let {bcx: cx, val} = alloc_ty(bcx, full_retty);
3185+
bcx = cx;
3186+
val
3187+
}
31853188
}
31863189
save_in(dst) { dst }
3187-
by_val(_) { alloca(cx, llretty) }
3190+
by_val(_) {
3191+
let {bcx: cx, val} = alloc_ty(bcx, full_retty);
3192+
bcx = cx;
3193+
val
3194+
}
31883195
};
31893196

31903197
if ty::type_contains_params(tcx, retty) {

0 commit comments

Comments
 (0)