diff options
| author | Patrick Walton <[email protected]> | 2011-03-07 15:43:55 -0800 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-03-07 15:44:42 -0800 |
| commit | 6f7e21ddac7bd956db55ea6885fbcfd3fb9f29a7 (patch) | |
| tree | 34e82a1b4ac2e53d5fcfcafccbd17dd126c8e03e /src | |
| parent | Parse opacity (and drop on the floor), so std.rc parses now. (diff) | |
| download | rust-6f7e21ddac7bd956db55ea6885fbcfd3fb9f29a7.tar.xz rust-6f7e21ddac7bd956db55ea6885fbcfd3fb9f29a7.zip | |
rustc: Truncate or zero-extend indexes appropriately. Un-XFAIL integral-indexing.rs.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 1 | ||||
| -rw-r--r-- | src/comp/middle/trans.rs | 17 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/Makefile b/src/Makefile index a1c13918..2a6e7b15 100644 --- a/src/Makefile +++ b/src/Makefile @@ -456,7 +456,6 @@ TEST_XFAILS_RUSTC := $(addprefix test/run-pass/, \ generic-recursive-tag.rs \ generic-tag-alt.rs \ generic-tag-values.rs \ - integral-indexing.rs \ iter-range.rs \ iter-ret.rs \ lazychan.rs \ diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index aa904674..7ad96ba2 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -3209,10 +3209,23 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base, auto v = lv.val; auto bcx = ix.bcx; + // Cast to an LLVM integer. Rust is less strict than LLVM in this regard. + auto ix_val; + auto ix_size = llsize_of_real(cx.fcx.ccx, val_ty(ix.val)); + auto int_size = llsize_of_real(cx.fcx.ccx, T_int()); + if (ix_size < int_size) { + ix_val = bcx.build.ZExt(ix.val, T_int()); + } else if (ix_size > int_size) { + ix_val = bcx.build.Trunc(ix.val, T_int()); + } else { + ix_val = ix.val; + } + auto llunit_ty = node_type(cx.fcx.ccx, ann); auto unit_sz = size_of(bcx, node_ann_type(cx.fcx.ccx, ann)); bcx = unit_sz.bcx; - auto scaled_ix = bcx.build.Mul(ix.val, unit_sz.val); + + auto scaled_ix = bcx.build.Mul(ix_val, unit_sz.val); auto lim = bcx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_fill))); lim = bcx.build.Load(lim); @@ -3229,7 +3242,7 @@ 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 = next_cx.build.GEP(body, vec(C_int(0), ix_val)); ret lval_mem(next_cx, elt); } |