Skip to content

Commit 2dd3691

Browse files
committed
---
yaml --- r: 5279 b: refs/heads/master c: 1cabe37 h: refs/heads/master i: 5277: dac89db 5275: 033e5bf 5271: 3950f0b 5263: 18d9e65 5247: aa3e89b v: v3
1 parent 15a82e3 commit 2dd3691

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: c6619f9ce04f98b4ec78fd856fd098d88fa7ec9f
2+
refs/heads/master: 1cabe37155bf83af04ce7814186fbef096a253cb

trunk/src/comp/middle/trans.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -3521,8 +3521,7 @@ fn trans_args(cx: @block_ctxt, llenv: ValueRef, gen: option::t<generic_info>,
35213521
args: [ValueRef],
35223522
retslot: ValueRef,
35233523
to_zero: [{v: ValueRef, t: ty::t}],
3524-
to_revoke: [{v: ValueRef, t: ty::t}],
3525-
by_ref: bool} {
3524+
to_revoke: [{v: ValueRef, t: ty::t}]} {
35263525

35273526
let args: [ty::arg] = ty::ty_fn_args(bcx_tcx(cx), fn_ty);
35283527
let llargs: [ValueRef] = [];
@@ -3545,8 +3544,7 @@ fn trans_args(cx: @block_ctxt, llenv: ValueRef, gen: option::t<generic_info>,
35453544
args: [],
35463545
retslot: C_nil(),
35473546
to_zero: to_zero,
3548-
to_revoke: to_revoke,
3549-
by_ref: by_ref};
3547+
to_revoke: to_revoke};
35503548
}
35513549
let retty = ty::ty_fn_ret(tcx, fn_ty);
35523550
let llretslot_res = if by_ref {
@@ -3620,8 +3618,7 @@ fn trans_args(cx: @block_ctxt, llenv: ValueRef, gen: option::t<generic_info>,
36203618
args: llargs,
36213619
retslot: llretslot,
36223620
to_zero: to_zero,
3623-
to_revoke: to_revoke,
3624-
by_ref: by_ref};
3621+
to_revoke: to_revoke};
36253622
}
36263623

36273624
fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
@@ -3630,10 +3627,18 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
36303627
// NB: 'f' isn't necessarily a function; it might be an entire self-call
36313628
// expression because of the hack that allows us to process self-calls
36323629
// with trans_call.
3633-
let cx = new_scope_block_ctxt(in_cx, "call");
3634-
Br(in_cx, cx.llbb);
3630+
let fn_expr_ty = ty::expr_ty(bcx_tcx(in_cx), f);
3631+
let fn_ty = ty::type_autoderef(bcx_tcx(in_cx), fn_expr_ty);
3632+
let by_ref = ty::ty_fn_ret_style(bcx_tcx(in_cx), fn_ty) == ast::return_ref;
3633+
// Things that return by reference must put their arguments (FIXME only
3634+
// the referenced arguments) into the outer scope, so that they are still
3635+
// alive when the return value is used.
3636+
let cx = if by_ref { in_cx } else {
3637+
let cx = new_scope_block_ctxt(in_cx, "call");
3638+
Br(in_cx, cx.llbb);
3639+
cx
3640+
};
36353641
let f_res = trans_lval_gen(cx, f);
3636-
let fn_ty = ty::expr_ty(bcx_tcx(cx), f);
36373642
let bcx = f_res.res.bcx;
36383643

36393644
let faddr = f_res.res.val;
@@ -3646,10 +3651,9 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
36463651
}
36473652
none. {
36483653
// It's a closure. We have to autoderef.
3649-
if f_res.is_mem { faddr = load_if_immediate(bcx, faddr, fn_ty); }
3650-
let res = autoderef(bcx, faddr, fn_ty);
3654+
if f_res.is_mem { faddr = load_if_immediate(bcx, faddr, fn_expr_ty); }
3655+
let res = autoderef(bcx, faddr, fn_expr_ty);
36513656
bcx = res.bcx;
3652-
fn_ty = res.ty;
36533657

36543658
let pair = res.val;
36553659
faddr = GEP(bcx, pair, [C_int(0), C_int(abi::fn_field_code)]);
@@ -3684,7 +3688,7 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
36843688
alt lliterbody {
36853689
none. {
36863690
if !ty::type_is_nil(bcx_tcx(cx), ret_ty) {
3687-
if args_res.by_ref {
3691+
if by_ref {
36883692
let retptr = Load(bcx, llretslot);
36893693
retval = load_if_immediate(bcx, retptr, ret_ty);
36903694
} else {
@@ -3710,7 +3714,7 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
37103714
for {v: v, t: t} in args_res.to_revoke {
37113715
bcx = revoke_clean(bcx, v, t);
37123716
}
3713-
bcx = trans_block_cleanups(bcx, cx);
3717+
if !by_ref { bcx = trans_block_cleanups(bcx, cx); }
37143718
let next_cx = new_sub_block_ctxt(in_cx, "next");
37153719
Br(bcx, next_cx.llbb);
37163720
bcx = next_cx;

0 commit comments

Comments
 (0)