Skip to content

Commit 181b7fd

Browse files
committed
---
yaml --- r: 12555 b: refs/heads/master c: 90f82e1 h: refs/heads/master i: 12553: d1b7586 12551: 2d6d4ba v: v3
1 parent fb387fa commit 181b7fd

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 37b054973083ed4201a2ba73be6bdd39daf13cf6
2+
refs/heads/master: 90f82e171d17d63167d44f7bffe9c2b5e43da40f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustc/middle/trans/base.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,6 +2563,7 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr,
25632563
}
25642564
none { trans_temp_lval(cx, e) }
25652565
};
2566+
#debug(" pre-adaptation value: %s", val_str(lv.bcx.ccx().tn, lv.val));
25662567
let lv = adapt_borrowed_value(lv, arg, e);
25672568
let mut bcx = lv.bcx;
25682569
let mut val = lv.val;
@@ -2618,7 +2619,7 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr,
26182619
}
26192620

26202621
if !is_bot && arg.ty != e_ty || ty::type_has_params(arg.ty) {
2621-
#debug(" casting from %s", val_str(bcx.ccx().tn, val));
2622+
#debug(" casting from %s", val_str(bcx.ccx().tn, val));
26222623
val = PointerCast(bcx, val, lldestty);
26232624
}
26242625
#debug("--- trans_arg_expr passing %s", val_str(bcx.ccx().tn, val));
@@ -2652,10 +2653,21 @@ fn adapt_borrowed_value(lv: lval_result, _arg: ty::arg,
26522653
ty::ty_estr(_) |
26532654
ty::ty_evec(_, _) {
26542655
let ccx = bcx.ccx();
2656+
let val = alt lv.kind {
2657+
temporary { lv.val }
2658+
owned { load_if_immediate(bcx, lv.val, e_ty) }
2659+
owned_imm { lv.val }
2660+
};
2661+
26552662
let unit_ty = ty::sequence_element_type(ccx.tcx, e_ty);
26562663
let llunit_ty = type_of(ccx, unit_ty);
2657-
let (base, len) = tvec::get_base_and_len(bcx, lv.val, e_ty);
2664+
let (base, len) = tvec::get_base_and_len(bcx, val, e_ty);
26582665
let p = alloca(bcx, T_struct([T_ptr(llunit_ty), ccx.int_type]));
2666+
2667+
#debug("adapt_borrowed_value: adapting %s to %s",
2668+
val_str(bcx.ccx().tn, val),
2669+
val_str(bcx.ccx().tn, p));
2670+
26592671
Store(bcx, base, GEPi(bcx, p, [0, abi::slice_elt_base]));
26602672
Store(bcx, len, GEPi(bcx, p, [0, abi::slice_elt_len]));
26612673
ret lval_temp(bcx, p);
@@ -3064,12 +3076,7 @@ fn trans_expr_save_in(bcx: block, e: @ast::expr, dest: ValueRef)
30643076
fn trans_temp_lval(bcx: block, e: @ast::expr) -> lval_result {
30653077
let _icx = bcx.insn_ctxt("trans_temp_lval");
30663078
let mut bcx = bcx;
3067-
if expr_is_lval(bcx, e) && !expr_is_borrowed(bcx, e) {
3068-
// if the expression is borrowed, then are not actually passing the
3069-
// lvalue itself, but rather an adaptation of it. This is a bit of a
3070-
// hack, though, but it only needs to exist so long as we have
3071-
// reference modes and the like---otherwise, all potentially borrowed
3072-
// things will go directly through trans_expr() as they ought to.
3079+
if expr_is_lval(bcx, e) {
30733080
ret trans_lval(bcx, e);
30743081
} else {
30753082
let ty = expr_ty(bcx, e);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// xfail-test
2+
fn foo(x: [int]/&) -> int {
3+
x[0]
4+
}
5+
6+
fn main() {
7+
let p = [1,2,3,4,5]/_;
8+
assert foo(p) == 1;
9+
}

0 commit comments

Comments
 (0)