Skip to content

Commit 7f3f66d

Browse files
committed
rustc: Use the scaled index, not the raw index, if a vector has generic size. lib-vec.rs works now.
1 parent 607fa14 commit 7f3f66d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/comp/middle/trans.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3819,10 +3819,13 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
38193819
ix_val = ix.val;
38203820
}
38213821

3822-
auto unit_sz = size_of(bcx, node_ann_type(cx.fcx.ccx, ann));
3822+
auto unit_ty = node_ann_type(cx.fcx.ccx, ann);
3823+
auto unit_sz = size_of(bcx, unit_ty);
38233824
bcx = unit_sz.bcx;
3825+
llvm.LLVMSetValueName(unit_sz.val, _str.buf("unit_sz"));
38243826

38253827
auto scaled_ix = bcx.build.Mul(ix_val, unit_sz.val);
3828+
llvm.LLVMSetValueName(scaled_ix, _str.buf("scaled_ix"));
38263829

38273830
auto lim = bcx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_fill)));
38283831
lim = bcx.build.Load(lim);
@@ -3839,7 +3842,14 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
38393842
fail_res.bcx.build.Br(next_cx.llbb);
38403843

38413844
auto body = next_cx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_data)));
3842-
auto elt = next_cx.build.GEP(body, vec(C_int(0), ix_val));
3845+
auto elt;
3846+
if (ty.type_has_dynamic_size(unit_ty)) {
3847+
body = next_cx.build.PointerCast(body, T_ptr(T_array(T_i8(), 0u)));
3848+
elt = next_cx.build.GEP(body, vec(C_int(0), scaled_ix));
3849+
} else {
3850+
elt = next_cx.build.GEP(body, vec(C_int(0), ix_val));
3851+
}
3852+
38433853
ret lval_mem(next_cx, elt);
38443854
}
38453855

0 commit comments

Comments
 (0)