diff --git a/tests/compile-fail/intptrcast_cast_int_to_fn_ptr.rs b/tests/compile-fail/intptrcast_cast_int_to_fn_ptr.rs new file mode 100644 index 000000000000..f4064cf92e2c --- /dev/null +++ b/tests/compile-fail/intptrcast_cast_int_to_fn_ptr.rs @@ -0,0 +1,10 @@ +// Validation makes this fail in the wrong place +// compile-flags: -Zmiri-disable-validation -Zmiri-seed=0000000000000000 + +fn main() { + let g = unsafe { + std::mem::transmute::(42) + }; + + g(42) //~ ERROR dangling pointer was dereferenced +} diff --git a/tests/compile-fail/intptrcast_null_pointer_deref.rs b/tests/compile-fail/intptrcast_null_pointer_deref.rs new file mode 100644 index 000000000000..0c5d46609cf8 --- /dev/null +++ b/tests/compile-fail/intptrcast_null_pointer_deref.rs @@ -0,0 +1,6 @@ +// compile-flags: -Zmiri-seed=0000000000000000 + +fn main() { + let x: i32 = unsafe { *std::ptr::null() }; //~ ERROR invalid use of NULL pointer + panic!("this should never print: {}", x); +} diff --git a/tests/compile-fail/intptrcast_wild_pointer_deref.rs b/tests/compile-fail/intptrcast_wild_pointer_deref.rs new file mode 100644 index 000000000000..2ee664eb68bd --- /dev/null +++ b/tests/compile-fail/intptrcast_wild_pointer_deref.rs @@ -0,0 +1,7 @@ +// compile-flags: -Zmiri-seed=0000000000000000 + +fn main() { + let p = 44 as *const i32; + let x = unsafe { *p }; //~ ERROR dangling pointer was dereferenced + panic!("this should never print: {}", x); +}