mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 12:36:47 +00:00
Add miri tests.
This commit is contained in:
parent
ec28dc7aa7
commit
7c669562b1
@ -0,0 +1,17 @@
|
||||
// Make sure we find these even with many checks disabled.
|
||||
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
|
||||
|
||||
#![allow(unreachable_code)]
|
||||
#![feature(never_type)]
|
||||
|
||||
fn main() {
|
||||
let p = {
|
||||
let b = Box::new(42);
|
||||
&*b as *const i32 as *const !
|
||||
};
|
||||
unsafe {
|
||||
match *p {} //~ ERROR: entering unreachable code
|
||||
}
|
||||
panic!("this should never print");
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
error: Undefined Behavior: entering unreachable code
|
||||
--> $DIR/dangling_pointer_deref_match_never.rs:LL:CC
|
||||
|
|
||||
LL | match *p {}
|
||||
| ^^ entering unreachable code
|
||||
|
|
||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||
= note: BACKTRACE:
|
||||
= note: inside `main` at $DIR/dangling_pointer_deref_match_never.rs:LL:CC
|
||||
|
||||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -0,0 +1,14 @@
|
||||
// A `_` binding in a match is a nop, so we do not detect that the pointer is dangling.
|
||||
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
|
||||
|
||||
fn main() {
|
||||
let p = {
|
||||
let b = Box::new(42);
|
||||
&*b as *const i32
|
||||
};
|
||||
unsafe {
|
||||
match *p {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user