Skip to content

Commit 21040e6

Browse files
committed
---
yaml --- r: 3812 b: refs/heads/master c: 79ce5a4 h: refs/heads/master v: v3
1 parent 34e8a77 commit 21040e6

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
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: 4618e802db4bfd886ca3d92a86a364122fb7872a
2+
refs/heads/master: 79ce5a46141f05dc454f90cb0be50e081d72e461

trunk/src/comp/middle/alias.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ fn expr_root(&ctx cx, @ast::expr ex, bool autoderef) ->
573573
case (ty::ty_box(?mt)) { mut = mt.mut != ast::imm; }
574574
case (ty::ty_res(_, _, _)) {}
575575
case (ty::ty_tag(_, _)) {}
576+
case (ty::ty_ptr(?mt)) { mut = mt.mut != ast::imm; }
576577
}
577578
vec::push(ds, rec(mut=mut, kind=unbox, outer_t=base_t));
578579
ex = base;

trunk/src/comp/middle/trans.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5263,11 +5263,11 @@ fn trans_lval_gen(&@block_ctxt cx, &@ast::expr e) -> lval_result {
52635263
auto t = ty::expr_ty(ccx.tcx, base);
52645264
auto val = alt (ty::struct(ccx.tcx, t)) {
52655265
case (ty::ty_box(_)) {
5266-
sub.bcx.build.GEP
5266+
sub.bcx.build.InBoundsGEP
52675267
(sub.val, ~[C_int(0), C_int(abi::box_rc_field_body)])
52685268
}
52695269
case (ty::ty_res(_, _, _)) {
5270-
sub.bcx.build.GEP(sub.val, ~[C_int(0), C_int(1)])
5270+
sub.bcx.build.InBoundsGEP(sub.val, ~[C_int(0), C_int(1)])
52715271
}
52725272
case (ty::ty_tag(_, _)) {
52735273
auto ety = ty::expr_ty(ccx.tcx, e);
@@ -5279,6 +5279,7 @@ fn trans_lval_gen(&@block_ctxt cx, &@ast::expr e) -> lval_result {
52795279
};
52805280
sub.bcx.build.PointerCast(sub.val, ellty)
52815281
}
5282+
case (ty::ty_ptr(_)) { sub.val }
52825283
};
52835284
ret lval_mem(sub.bcx, val);
52845285
}

trunk/src/comp/middle/typeck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
17121712
oper_t = ty::substitute_type_params
17131713
(fcx.ccx.tcx, tps, variants.(0).args.(0));
17141714
}
1715+
case (ty::ty_ptr(?inner)) { oper_t = inner.ty; }
17151716
case (_) {
17161717
fcx.ccx.tcx.sess.span_fatal
17171718
(expr.span, "dereferencing non-" +

trunk/src/lib/ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Unsafe pointer utility functions.
22

33
native "rust-intrinsic" mod rusti {
4-
fn addr_of[T](&T val) -> *T;
4+
fn addr_of[T](&mutable T val) -> *mutable T;
55
fn ptr_offset[T](*T ptr, uint count) -> *T;
66
}
77

8-
fn addr_of[T](&T val) -> *T { ret rusti::addr_of(val); }
8+
fn addr_of[T](&mutable T val) -> *mutable T { ret rusti::addr_of(val); }
99
fn offset[T](*T ptr, uint count) -> *T { ret rusti::ptr_offset(ptr, count); }
1010

trunk/src/test/run-pass/lib-ptr.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// xfail-stage0
2+
3+
use std;
4+
import std::ptr;
5+
import std::unsafe;
6+
7+
type pair = rec(mutable int fst, mutable int snd);
8+
9+
fn main() {
10+
auto p = rec(mutable fst=10, mutable snd=20);
11+
let *mutable pair pptr = ptr::addr_of(p);
12+
let *mutable int iptr = unsafe::reinterpret_cast(pptr);
13+
assert (*iptr == 10);
14+
*iptr = 30;
15+
assert (*iptr == 30);
16+
assert (p.fst == 30);
17+
18+
*pptr = rec(mutable fst=50, mutable snd=60);
19+
assert (*iptr == 50);
20+
assert (p.fst == 50);
21+
assert (p.snd == 60);
22+
}
23+

0 commit comments

Comments
 (0)