Skip to content

Commit 81c2240

Browse files
Dretchbrson
authored andcommitted
---
yaml --- r: 30904 b: refs/heads/incoming c: 1c76d18 h: refs/heads/master v: v3
1 parent 93c384f commit 81c2240

File tree

11 files changed

+40
-10
lines changed

11 files changed

+40
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 2f95f7d8de29baca271d04ef89021146061ce975
9+
refs/heads/incoming: 1c76d189c02ddc6cb6fcf15ae94f3a3ae4de5fa7
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/rt.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) {
4040
rustrt::rust_upcall_fail(expr, file, line);
4141
}
4242

43+
#[rt(fail_bounds_check)]
44+
fn rt_fail_bounds_check(file: *c_char, line: size_t,
45+
index: size_t, len: size_t) {
46+
let msg = fmt!("index out of bounds: the len is %d but the index is %d",
47+
len as int, index as int);
48+
do str::as_buf(msg) |p, _len| {
49+
rt_fail_(p as *c_char, file, line);
50+
}
51+
}
52+
4353
#[rt(exchange_malloc)]
4454
fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
4555
return rustrt::rust_upcall_exchange_malloc(td, size);

branches/incoming/src/rustc/middle/trans/controlflow.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,21 @@ fn trans_fail_value(bcx: block, sp_opt: Option<span>, V_fail_str: ValueRef)
344344
Unreachable(bcx);
345345
return bcx;
346346
}
347+
348+
fn trans_fail_bounds_check(bcx: block, sp: span,
349+
index: ValueRef, len: ValueRef) -> block {
350+
let _icx = bcx.insn_ctxt("trans_fail_bounds_check");
351+
let ccx = bcx.ccx();
352+
353+
let loc = codemap::lookup_char_pos(bcx.sess().parse_sess.cm, sp.lo);
354+
let line = C_int(ccx, loc.line as int);
355+
let filename_cstr = C_cstr(bcx.ccx(), loc.file.name);
356+
let filename = PointerCast(bcx, filename_cstr, T_ptr(T_i8()));
357+
358+
let args = ~[filename, line, index, len];
359+
let bcx = callee::trans_rtcall(bcx, ~"fail_bounds_check", args,
360+
expr::Ignore);
361+
Unreachable(bcx);
362+
return bcx;
363+
}
364+

branches/incoming/src/rustc/middle/trans/expr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,9 @@ fn trans_index(bcx: block,
946946

947947
let bounds_check = ICmp(bcx, lib::llvm::IntUGE, scaled_ix, len);
948948
let bcx = do with_cond(bcx, bounds_check) |bcx| {
949-
controlflow::trans_fail(bcx, Some(index_expr.span), ~"bounds check")
949+
let unscaled_len = UDiv(bcx, len, vt.llunit_size);
950+
controlflow::trans_fail_bounds_check(bcx, index_expr.span,
951+
ix_val, unscaled_len)
950952
};
951953
let elt = InBoundsGEP(bcx, base, ~[ix_val]);
952954
let elt = PointerCast(bcx, elt, T_ptr(vt.llunit_ty));

branches/incoming/src/test/run-fail/bug-2470-bounds-check-overflow-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// xfail-test
2-
// error-pattern:bounds check
2+
// error-pattern:index out of bounds
33

44
fn main() {
55
let x = ~[1u,2u,3u];
@@ -14,4 +14,4 @@ fn main() {
1414

1515
// This should fail.
1616
error!("ov2 0x%x", x[idx]);
17-
}
17+
}

branches/incoming/src/test/run-fail/bug-2470-bounds-check-overflow-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// xfail-test
2-
// error-pattern:bounds check
2+
// error-pattern:index out of bounds
33

44
#[cfg(target_arch="x86")]
55
fn main() {

branches/incoming/src/test/run-fail/bug-2470-bounds-check-overflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern:bounds check
1+
// error-pattern:index out of bounds
22

33
fn main() {
44

branches/incoming/src/test/run-fail/small-negative-indexing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern:bounds check
1+
// error-pattern:index out of bounds: the len is 1024 but the index is -1
22
fn main() {
33
let v = vec::from_fn(1024u, {|n| n});
44
// this should trip a bounds check

branches/incoming/src/test/run-fail/str-overrun.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// -*- rust -*-
22

3-
// error-pattern:bounds check
3+
// error-pattern:index out of bounds: the len is 5 but the index is 5
44
fn main() {
55
let s: ~str = ~"hello";
66

branches/incoming/src/test/run-fail/vec-overrun.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// -*- rust -*-
22

3-
// error-pattern:bounds check
3+
// error-pattern:index out of bounds: the len is 1 but the index is 2
44
fn main() {
55
let v: ~[int] = ~[10];
66
let x: int = 0;

branches/incoming/src/test/run-fail/vec-underrun.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// -*- rust -*-
22

3-
// error-pattern:bounds check
3+
// error-pattern:index out of bounds: the len is 2 but the index is -1
44
fn main() {
55
let v: ~[int] = ~[10, 20];
66
let x: int = 0;

0 commit comments

Comments
 (0)