Skip to content

Commit 7c66956

Browse files
committed
Add miri tests.
1 parent ec28dc7 commit 7c66956

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Make sure we find these even with many checks disabled.
2+
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
3+
4+
#![allow(unreachable_code)]
5+
#![feature(never_type)]
6+
7+
fn main() {
8+
let p = {
9+
let b = Box::new(42);
10+
&*b as *const i32 as *const !
11+
};
12+
unsafe {
13+
match *p {} //~ ERROR: entering unreachable code
14+
}
15+
panic!("this should never print");
16+
}
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: entering unreachable code
2+
--> $DIR/dangling_pointer_deref_match_never.rs:LL:CC
3+
|
4+
LL | match *p {}
5+
| ^^ entering unreachable code
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at $DIR/dangling_pointer_deref_match_never.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to previous error
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// A `_` binding in a match is a nop, so we do not detect that the pointer is dangling.
2+
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
3+
4+
fn main() {
5+
let p = {
6+
let b = Box::new(42);
7+
&*b as *const i32
8+
};
9+
unsafe {
10+
match *p {
11+
_ => {}
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)