Skip to content

Commit 3b14266

Browse files
committed
Auto merge of #116915 - bend-n:unwet, r=saethlin
Add an assume that the index is inbounds to slice::get_unchecked Fixes #116878
2 parents 454dec2 + 87ba80a commit 3b14266

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
//@compile-flags: -Zmiri-strict-provenance
2-
//@error-in-other-file: /retag .* tag does not exist in the borrow stack/
32

43
fn main() {
54
unsafe {
65
let a = [1, 2, 3];
76
let s = &a[0..0];
87
assert_eq!(s.len(), 0);
9-
assert_eq!(*s.get_unchecked(1), 2);
8+
assert_eq!(*s.as_ptr().add(1), 2); //~ ERROR: /retag .* tag does not exist in the borrow stack/
109
}
1110
}

tests/fail/stacked_borrows/zst_slice.stderr

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
error: Undefined Behavior: trying to retag from <TAG> for SharedReadOnly permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
2-
--> RUSTLIB/core/src/slice/mod.rs:LL:CC
2+
--> $DIR/zst_slice.rs:LL:CC
33
|
4-
LL | unsafe { &*index.get_unchecked(self) }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| trying to retag from <TAG> for SharedReadOnly permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
8-
| this error occurs as part of retag at ALLOC[0x4..0x8]
4+
LL | assert_eq!(*s.as_ptr().add(1), 2);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| trying to retag from <TAG> for SharedReadOnly permission at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
8+
| this error occurs as part of retag at ALLOC[0x4..0x8]
99
|
1010
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> would have been created here, but this is a zero-size retag ([0x0..0x0]) so the tag in question does not exist anywhere
1313
--> $DIR/zst_slice.rs:LL:CC
1414
|
15-
LL | assert_eq!(*s.get_unchecked(1), 2);
16-
| ^^^^^^^^^^^^^^^^^^
15+
LL | assert_eq!(*s.as_ptr().add(1), 2);
16+
| ^^^^^^^^^^
1717
= note: BACKTRACE (of the first span):
18-
= note: inside `core::slice::<impl [i32]>::get_unchecked::<usize>` at RUSTLIB/core/src/slice/mod.rs:LL:CC
19-
note: inside `main`
20-
--> $DIR/zst_slice.rs:LL:CC
21-
|
22-
LL | assert_eq!(*s.get_unchecked(1), 2);
23-
| ^^^^^^^^^^^^^^^^^^
18+
= note: inside `main` at RUSTLIB/core/src/macros/mod.rs:LL:CC
19+
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
2420

2521
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
2622

tests/fail/uninit/uninit_byte_read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@compile-flags: -Zmiri-disable-stacked-borrows
22
fn main() {
33
let v: Vec<u8> = Vec::with_capacity(10);
4-
let undef = unsafe { *v.get_unchecked(5) }; //~ ERROR: uninitialized
4+
let undef = unsafe { *v.as_ptr().add(5) }; //~ ERROR: uninitialized
55
let x = undef + 1;
66
panic!("this should never print: {}", x);
77
}

tests/fail/uninit/uninit_byte_read.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
22
--> $DIR/uninit_byte_read.rs:LL:CC
33
|
4-
LL | let undef = unsafe { *v.get_unchecked(5) };
5-
| ^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
4+
LL | let undef = unsafe { *v.as_ptr().add(5) };
5+
| ^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

tests/pass/float_nan.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use NaNKind::*;
2020
#[track_caller]
2121
fn check_all_outcomes<T: Eq + Hash + fmt::Display>(expected: HashSet<T>, generate: impl Fn() -> T) {
2222
let mut seen = HashSet::new();
23-
// Let's give it 8x as many tries as we are expecting values.
24-
let tries = expected.len() * 8;
23+
// Let's give it sixteen times as many tries as we are expecting values.
24+
let tries = expected.len() * 16;
2525
for _ in 0..tries {
2626
let val = generate();
2727
assert!(expected.contains(&val), "got an unexpected value: {val}");

0 commit comments

Comments
 (0)