aboutsummaryrefslogtreecommitdiff
path: root/src/comp
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-03-31 10:10:21 -0700
committerPatrick Walton <[email protected]>2011-03-31 10:10:21 -0700
commit7f3f66df7b791ea16a64f5939a5607e8f50f23dc (patch)
tree01e5df65230ab6aef9878a240cb690068b34adf1 /src/comp
parentRename incr_all_refcnts to take_ty, to match drop_ty (diff)
downloadrust-7f3f66df7b791ea16a64f5939a5607e8f50f23dc.tar.xz
rust-7f3f66df7b791ea16a64f5939a5607e8f50f23dc.zip
rustc: Use the scaled index, not the raw index, if a vector has generic size. lib-vec.rs works now.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/trans.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 3fa5b699..ceb15f71 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -3819,10 +3819,13 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
ix_val = ix.val;
}
- auto unit_sz = size_of(bcx, node_ann_type(cx.fcx.ccx, ann));
+ auto unit_ty = node_ann_type(cx.fcx.ccx, ann);
+ auto unit_sz = size_of(bcx, unit_ty);
bcx = unit_sz.bcx;
+ llvm.LLVMSetValueName(unit_sz.val, _str.buf("unit_sz"));
auto scaled_ix = bcx.build.Mul(ix_val, unit_sz.val);
+ llvm.LLVMSetValueName(scaled_ix, _str.buf("scaled_ix"));
auto lim = bcx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_fill)));
lim = bcx.build.Load(lim);
@@ -3839,7 +3842,14 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
fail_res.bcx.build.Br(next_cx.llbb);
auto body = next_cx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_data)));
- auto elt = next_cx.build.GEP(body, vec(C_int(0), ix_val));
+ auto elt;
+ if (ty.type_has_dynamic_size(unit_ty)) {
+ body = next_cx.build.PointerCast(body, T_ptr(T_array(T_i8(), 0u)));
+ elt = next_cx.build.GEP(body, vec(C_int(0), scaled_ix));
+ } else {
+ elt = next_cx.build.GEP(body, vec(C_int(0), ix_val));
+ }
+
ret lval_mem(next_cx, elt);
}