]>
Commit | Line | Data |
---|---|---|
1a4d82fc | 1 | // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT |
223e47cc LB |
2 | // file at the top-level directory of this distribution and at |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
1a4d82fc | 11 | // ignore-test |
223e47cc LB |
12 | // error-pattern:index out of bounds |
13 | ||
1a4d82fc JJ |
14 | use std::u64; |
15 | ||
223e47cc LB |
16 | #[cfg(target_arch="x86")] |
17 | fn main() { | |
85aaf69f | 18 | let x = vec!(1_usize,2_usize,3_usize); |
223e47cc | 19 | |
1a4d82fc | 20 | // This should cause a bounds-check panic, but may not if we do our |
223e47cc LB |
21 | // bounds checking by truncating the index value to the size of the |
22 | // machine word, losing relevant bits of the index value. | |
23 | ||
24 | // This test is only meaningful on 32-bit hosts. | |
25 | ||
85aaf69f | 26 | let idx = u64::MAX & !(u64::MAX >> 1_usize); |
1a4d82fc | 27 | println!("ov3 idx = 0x%8.8x%8.8x", |
c34b1796 AL |
28 | (idx >> 32) as usize, |
29 | idx as usize); | |
223e47cc | 30 | |
1a4d82fc | 31 | // This should panic. |
85aaf69f | 32 | println!("ov3 0x%x", x[idx]); |
223e47cc LB |
33 | } |
34 | ||
1a4d82fc | 35 | #[cfg(any(target_arch="x86_64", target_arch = "aarch64"))] |
223e47cc | 36 | fn main() { |
1a4d82fc | 37 | // This version just panics anyways, for symmetry on 64-bit hosts. |
85aaf69f SL |
38 | let x = vec!(1_usize,2_usize,3_usize); |
39 | error!("ov3 0x%x", x[200]); | |
223e47cc | 40 | } |