From e57447014d0cc8ab9ec86c30bc94e48c588d4526 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 21 Jun 2019 16:32:54 -0500 Subject: [PATCH] Duplicate compile-fail tests for intptrcast --- tests/compile-fail/intptrcast_cast_int_to_fn_ptr.rs | 10 ++++++++++ tests/compile-fail/intptrcast_null_pointer_deref.rs | 6 ++++++ tests/compile-fail/intptrcast_wild_pointer_deref.rs | 7 +++++++ 3 files changed, 23 insertions(+) create mode 100644 tests/compile-fail/intptrcast_cast_int_to_fn_ptr.rs create mode 100644 tests/compile-fail/intptrcast_null_pointer_deref.rs create mode 100644 tests/compile-fail/intptrcast_wild_pointer_deref.rs 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); +}