Skip to content

Commit

Permalink
rustc: Use the scaled index, not the raw index, if a vector has gener…
Browse files Browse the repository at this point in the history
…ic size. lib-vec.rs works now.
  • Loading branch information
pcwalton committed Mar 31, 2011
1 parent 607fa14 commit 7f3f66d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down

0 comments on commit 7f3f66d

Please sign in to comment.