Skip to content

Commit fb070a9

Browse files
committed
---
yaml --- r: 3672 b: refs/heads/master c: 16f82dc h: refs/heads/master v: v3
1 parent 381cd8f commit fb070a9

File tree

2 files changed

+26
-46
lines changed

2 files changed

+26
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 3bdbf74d4703771571fdee1733b7b3d919b5ede8
2+
refs/heads/master: 16f82dce1c1c2a9f42a1a5e2c4e3345f07ee5c2d

trunk/src/comp/middle/trans.rs

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5666,64 +5666,44 @@ fn trans_bind(&@block_ctxt cx, &@ast::expr f,
56665666

56675667
fn trans_arg_expr(&@block_ctxt cx, &ty::arg arg, TypeRef lldestty0,
56685668
&@ast::expr e) -> result {
5669-
auto val;
5670-
auto bcx = cx;
5671-
auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
5672-
if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) {
5673-
auto re = trans_expr(bcx, e);
5674-
val = re.val;
5675-
bcx = re.bcx;
5676-
} else if (arg.mode != ty::mo_val) {
5677-
let lval_result lv;
5678-
if (ty::is_lval(e)) {
5679-
lv = trans_lval(bcx, e);
5680-
} else {
5681-
auto r = trans_expr(bcx, e);
5682-
if (type_is_immediate(cx.fcx.lcx.ccx, e_ty)) {
5683-
lv = lval_val(r.bcx, r.val);
5684-
} else { lv = lval_mem(r.bcx, r.val); }
5685-
}
5686-
bcx = lv.res.bcx;
5687-
if (lv.is_mem) {
5688-
val = lv.res.val;
5689-
} else {
5690-
// Non-mem but we're trying to alias; synthesize an
5691-
// alloca, spill to it and pass its address.
5692-
val = do_spill(lv.res.bcx, lv.res.val);
5693-
}
5694-
} else { auto re = trans_expr(bcx, e); val = re.val; bcx = re.bcx; }
5695-
auto is_bot = ty::type_is_bot(cx.fcx.lcx.ccx.tcx, e_ty);
5696-
5697-
// Make a copy here if the type is structural and we're passing by value.
5698-
if (arg.mode == ty::mo_val && !is_bot) {
5699-
if (ty::type_owns_heap_mem(cx.fcx.lcx.ccx.tcx, e_ty)) {
5700-
auto rslt = alloc_ty(bcx, e_ty);
5701-
bcx = rslt.bcx;
5702-
auto dst = rslt.val;
5703-
rslt = copy_val(bcx, INIT, dst, val, e_ty);
5704-
bcx = rslt.bcx;
5705-
val = dst;
5706-
} else {
5707-
bcx = copy_ty(bcx, val, e_ty).bcx;
5708-
}
5709-
}
5710-
5669+
auto ccx = cx.fcx.lcx.ccx;
5670+
auto e_ty = ty::expr_ty(ccx.tcx, e);
5671+
auto is_bot = ty::type_is_bot(ccx.tcx, e_ty);
5672+
auto lv = trans_lval(cx, e);
5673+
auto bcx = lv.res.bcx;
5674+
auto val = lv.res.val;
57115675
if (is_bot) {
57125676
// For values of type _|_, we generate an
57135677
// "undef" value, as such a value should never
57145678
// be inspected. It's important for the value
57155679
// to have type lldestty0 (the callee's expected type).
57165680
val = llvm::LLVMGetUndef(lldestty0);
5717-
} else if (ty::type_contains_params(cx.fcx.lcx.ccx.tcx, arg.ty)) {
5681+
} else if (arg.mode == ty::mo_val) {
5682+
if (ty::type_owns_heap_mem(ccx.tcx, e_ty)) {
5683+
auto dst = alloc_ty(bcx, e_ty);
5684+
val = dst.val;
5685+
bcx = move_val_if_temp(dst.bcx, INIT, val, lv, e_ty).bcx;
5686+
} else {
5687+
if (lv.is_mem) { val = load_if_immediate(bcx, val, e_ty); }
5688+
// FIXME for non-is-mem lvals, we should be able to just drop the
5689+
// cleanup. However, this currently leads to a memory-corrupting
5690+
// stage2/rustc . Find out why.
5691+
bcx = copy_ty(bcx, val, e_ty).bcx;
5692+
}
5693+
} else if (type_is_immediate(ccx, e_ty) && !lv.is_mem) {
5694+
val = do_spill(bcx, val);
5695+
}
5696+
5697+
if (!is_bot && ty::type_contains_params(ccx.tcx, arg.ty)) {
57185698
auto lldestty = lldestty0;
57195699
if (arg.mode == ty::mo_val
5720-
&& ty::type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) {
5700+
&& ty::type_is_structural(ccx.tcx, e_ty)) {
57215701
lldestty = T_ptr(lldestty);
57225702
}
57235703
val = bcx.build.PointerCast(val, lldestty);
57245704
}
57255705
if (arg.mode == ty::mo_val
5726-
&& ty::type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) {
5706+
&& ty::type_is_structural(ccx.tcx, e_ty)) {
57275707
// Until here we've been treating structures by pointer;
57285708
// we are now passing it as an arg, so need to load it.
57295709
val = bcx.build.Load(val);

0 commit comments

Comments
 (0)