Skip to content

Commit 8ceb1fe

Browse files
committed
---
yaml --- r: 2013 b: refs/heads/master c: 015c0d0 h: refs/heads/master i: 2011: 621293d v: v3
1 parent 56b08bf commit 8ceb1fe

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
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: b4422cca2195be788d99c849e662c3c778496739
2+
refs/heads/master: 015c0d0d5985548d93e6d9c314ab2a18b8af491f

trunk/src/comp/middle/trans.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,15 +2591,9 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
25912591
ret res(sub.bcx, box);
25922592
}
25932593
case (ast.deref) {
2594-
auto val = sub.bcx.build.GEP(sub.val,
2595-
vec(C_int(0),
2596-
C_int(abi.box_rc_field_body)));
2597-
auto e_ty = node_ann_type(sub.bcx.fcx.ccx, a);
2598-
if (ty.type_is_scalar(e_ty) ||
2599-
ty.type_is_nil(e_ty)) {
2600-
val = sub.bcx.build.Load(val);
2601-
}
2602-
ret res(sub.bcx, val);
2594+
log "deref expressions should have been translated using " +
2595+
"trans_lval(), not trans_unary()";
2596+
fail;
26032597
}
26042598
}
26052599
fail;
@@ -3908,6 +3902,15 @@ fn trans_lval(@block_ctxt cx, @ast.expr e) -> lval_result {
39083902
case (ast.expr_index(?base, ?idx, ?ann)) {
39093903
ret trans_index(cx, e.span, base, idx, ann);
39103904
}
3905+
case (ast.expr_unary(?unop, ?base, ?ann)) {
3906+
check (unop == ast.deref);
3907+
3908+
auto sub = trans_expr(cx, base);
3909+
auto val = sub.bcx.build.GEP(sub.val,
3910+
vec(C_int(0),
3911+
C_int(abi.box_rc_field_body)));
3912+
ret lval_mem(sub.bcx, val);
3913+
}
39113914

39123915
// Kind of bizarre to pass an *entire* self-call here...but let's try
39133916
// it
@@ -3925,7 +3928,9 @@ fn trans_lval(@block_ctxt cx, @ast.expr e) -> lval_result {
39253928

39263929
}
39273930
}
3928-
case (_) { cx.fcx.ccx.sess.unimpl("expr variant in trans_lval"); }
3931+
case (_) {
3932+
cx.fcx.ccx.sess.span_unimpl(e.span, "expr variant in trans_lval");
3933+
}
39293934
}
39303935
fail;
39313936
}
@@ -4685,7 +4690,9 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
46854690
}
46864691

46874692
case (ast.expr_unary(?op, ?x, ?ann)) {
4688-
ret trans_unary(cx, op, x, ann);
4693+
if (op != ast.deref) {
4694+
ret trans_unary(cx, op, x, ann);
4695+
}
46894696
}
46904697

46914698
case (ast.expr_binary(?op, ?x, ?y, _)) {
@@ -4832,18 +4839,17 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
48324839
ret trans_recv(cx, lhs, rhs, ann);
48334840
}
48344841

4835-
// lval cases fall through to trans_lval and then
4836-
// possibly load the result (if it's non-structural).
4837-
48384842
case (_) {
4839-
auto t = ty.expr_ty(e);
4840-
auto sub = trans_lval(cx, e);
4841-
ret res(sub.res.bcx,
4842-
load_scalar_or_boxed(sub.res.bcx, sub.res.val, t));
4843+
// The expression is an lvalue. Fall through.
48434844
}
48444845
}
4845-
cx.fcx.ccx.sess.unimpl("expr variant in trans_expr");
4846-
fail;
4846+
4847+
// lval cases fall through to trans_lval and then
4848+
// possibly load the result (if it's non-structural).
4849+
4850+
auto t = ty.expr_ty(e);
4851+
auto sub = trans_lval(cx, e);
4852+
ret res(sub.res.bcx, load_scalar_or_boxed(sub.res.bcx, sub.res.val, t));
48474853
}
48484854

48494855
// We pass structural values around the compiler "by pointer" and

trunk/src/test/run-pass/deref-lval.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
auto x = @mutable 5;
3+
*x = 1000;
4+
log *x;
5+
}
6+

0 commit comments

Comments
 (0)