From ede470e1fcb8b6e488f39c48a84cde0f639adcc9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 26 Mar 2022 13:10:20 -0400 Subject: [PATCH] ensure that -Zmiri-check-number-validity detects integers with provenance --- tests/compile-fail/ptr_integer_array_transmute.rs | 6 ++++++ tests/compile-fail/ptr_integer_transmute.rs | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/compile-fail/ptr_integer_array_transmute.rs create mode 100644 tests/compile-fail/ptr_integer_transmute.rs diff --git a/tests/compile-fail/ptr_integer_array_transmute.rs b/tests/compile-fail/ptr_integer_array_transmute.rs new file mode 100644 index 00000000000..7a1ae2f3c9a --- /dev/null +++ b/tests/compile-fail/ptr_integer_array_transmute.rs @@ -0,0 +1,6 @@ +// compile-flags: -Zmiri-check-number-validity + +fn main() { + let r = &mut 42; + let _i: [usize; 1] = unsafe { std::mem::transmute(r) }; //~ ERROR encountered a pointer, but expected plain (non-pointer) bytes +} diff --git a/tests/compile-fail/ptr_integer_transmute.rs b/tests/compile-fail/ptr_integer_transmute.rs new file mode 100644 index 00000000000..e15a1576375 --- /dev/null +++ b/tests/compile-fail/ptr_integer_transmute.rs @@ -0,0 +1,6 @@ +// compile-flags: -Zmiri-check-number-validity + +fn main() { + let r = &mut 42; + let _i: usize = unsafe { std::mem::transmute(r) }; //~ ERROR expected initialized plain (non-pointer) bytes +}