Skip to content

Commit 532fd87

Browse files
committed
---
yaml --- r: 1541 b: refs/heads/master c: 6f7e21d h: refs/heads/master i: 1539: 0038235 v: v3
1 parent 3cc817f commit 532fd87

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
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: df3038e68bf1189cd9cb0fc81e57da2c23594b63
2+
refs/heads/master: 6f7e21ddac7bd956db55ea6885fbcfd3fb9f29a7

trunk/src/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ TEST_XFAILS_RUSTC := $(addprefix test/run-pass/, \
456456
generic-recursive-tag.rs \
457457
generic-tag-alt.rs \
458458
generic-tag-values.rs \
459-
integral-indexing.rs \
460459
iter-range.rs \
461460
iter-ret.rs \
462461
lazychan.rs \

trunk/src/comp/middle/trans.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,10 +3209,23 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
32093209
auto v = lv.val;
32103210
auto bcx = ix.bcx;
32113211

3212+
// Cast to an LLVM integer. Rust is less strict than LLVM in this regard.
3213+
auto ix_val;
3214+
auto ix_size = llsize_of_real(cx.fcx.ccx, val_ty(ix.val));
3215+
auto int_size = llsize_of_real(cx.fcx.ccx, T_int());
3216+
if (ix_size < int_size) {
3217+
ix_val = bcx.build.ZExt(ix.val, T_int());
3218+
} else if (ix_size > int_size) {
3219+
ix_val = bcx.build.Trunc(ix.val, T_int());
3220+
} else {
3221+
ix_val = ix.val;
3222+
}
3223+
32123224
auto llunit_ty = node_type(cx.fcx.ccx, ann);
32133225
auto unit_sz = size_of(bcx, node_ann_type(cx.fcx.ccx, ann));
32143226
bcx = unit_sz.bcx;
3215-
auto scaled_ix = bcx.build.Mul(ix.val, unit_sz.val);
3227+
3228+
auto scaled_ix = bcx.build.Mul(ix_val, unit_sz.val);
32163229

32173230
auto lim = bcx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_fill)));
32183231
lim = bcx.build.Load(lim);
@@ -3229,7 +3242,7 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
32293242
fail_res.bcx.build.Br(next_cx.llbb);
32303243

32313244
auto body = next_cx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_data)));
3232-
auto elt = next_cx.build.GEP(body, vec(C_int(0), ix.val));
3245+
auto elt = next_cx.build.GEP(body, vec(C_int(0), ix_val));
32333246
ret lval_mem(next_cx, elt);
32343247
}
32353248

0 commit comments

Comments
 (0)