Skip to content

Commit 3e93045

Browse files
saethlinRalfJung
andcommitted
Add a minimal reproducer of the ICE
Co-authored-by: Ralf Jung <post@ralfj.de>
1 parent db93abe commit 3e93045

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tests/pass/issues/issue-miri-2389.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::cell::Cell;
2+
3+
fn main() {
4+
unsafe {
5+
let root0 = Cell::new(42);
6+
let wildcard = &root0 as *const Cell<i32> as usize as *const Cell<i32>;
7+
// empty the stack to unknown (via SRW reborrow from wildcard)
8+
let _ref0 = &*wildcard;
9+
// Do a non-SRW reborrow from wildcard to start building up a stack again.
10+
// Now new refs start being inserted at idx 0, pushing the unique_range up.
11+
let _refn = &*&*&*&*&*(wildcard.cast::<i32>());
12+
// empty the stack again, but this time with unique_range.start sitting at some high index.
13+
let _ref0 = &*wildcard;
14+
// and do a read which tries to clear the uniques
15+
wildcard.cast::<i32>().read();
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
warning: integer-to-pointer cast
2+
--> $DIR/issue-miri-2389.rs:LL:CC
3+
|
4+
LL | let wildcard = &root0 as *const Cell<i32> as usize as *const Cell<i32>;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
6+
|
7+
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
8+
= help: which means that Miri might miss pointer bugs in this program.
9+
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
10+
= help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
11+
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
12+
= help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
13+
= note: backtrace:
14+
= note: inside `main` at $DIR/issue-miri-2389.rs:LL:CC
15+

0 commit comments

Comments
 (0)