rustc: Duplicate heap data of interior vectors when passing them by value

This commit is contained in:
Patrick Walton 2011-06-30 19:08:57 -07:00
parent 0eb257e864
commit b773f8d22b
2 changed files with 20 additions and 1 deletions

View File

@ -5515,7 +5515,21 @@ fn trans_arg_expr(&@block_ctxt cx, &ty::arg arg, TypeRef lldestty0,
val = do_spill(lv.res.bcx, lv.res.val);
}
} else { auto re = trans_expr(bcx, e); val = re.val; bcx = re.bcx; }
if (arg.mode == ty::mo_val) { bcx = copy_ty(bcx, val, e_ty).bcx; }
// Make a copy here if the type is structural and we're passing by value.
if (arg.mode == ty::mo_val) {
if (ty::type_owns_heap_mem(cx.fcx.lcx.ccx.tcx, e_ty)) {
auto rslt = alloc_ty(bcx, e_ty);
bcx = rslt.bcx;
auto dst = rslt.val;
rslt = copy_val(bcx, INIT, dst, val, e_ty);
bcx = rslt.bcx;
val = dst;
} else {
bcx = copy_ty(bcx, val, e_ty).bcx;
}
}
if (ty::type_is_bot(cx.fcx.lcx.ccx.tcx, e_ty)) {
// For values of type _|_, we generate an
// "undef" value, as such a value should never

View File

@ -0,0 +1,5 @@
// xfail-stage0
fn f(int[] a) {}
fn main() { f(~[ 1, 2, 3, 4, 5 ]); }