From b3be6b44b6a19b36ea7c579f757fb5764e83663b Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sun, 24 Oct 2021 13:43:47 -0700 Subject: [PATCH] Add tests for `-Zmiri-check-number-validity` --- tests/compile-fail/uninit_float.rs | 8 ++++++++ tests/compile-fail/uninit_integer.rs | 8 ++++++++ tests/compile-fail/uninit_integer_signed.rs | 8 ++++++++ tests/run-pass/uninit_number_ignored.rs | 8 ++++++++ 4 files changed, 32 insertions(+) create mode 100644 tests/compile-fail/uninit_float.rs create mode 100644 tests/compile-fail/uninit_integer.rs create mode 100644 tests/compile-fail/uninit_integer_signed.rs create mode 100644 tests/run-pass/uninit_number_ignored.rs diff --git a/tests/compile-fail/uninit_float.rs b/tests/compile-fail/uninit_float.rs new file mode 100644 index 00000000000..06953e1ced9 --- /dev/null +++ b/tests/compile-fail/uninit_float.rs @@ -0,0 +1,8 @@ +// compile-flags: -Zmiri-check-number-validity + +// This test is adapted from https://github.com/rust-lang/miri/issues/1340#issue-600900312. + +fn main() { + let _val = unsafe { std::mem::MaybeUninit::::uninit().assume_init() }; + //~^ ERROR type validation failed at .value: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes +} diff --git a/tests/compile-fail/uninit_integer.rs b/tests/compile-fail/uninit_integer.rs new file mode 100644 index 00000000000..757f69c050f --- /dev/null +++ b/tests/compile-fail/uninit_integer.rs @@ -0,0 +1,8 @@ +// compile-flags: -Zmiri-check-number-validity + +// This test is from https://github.com/rust-lang/miri/issues/1340#issue-600900312. + +fn main() { + let _val = unsafe { std::mem::MaybeUninit::::uninit().assume_init() }; + //~^ ERROR type validation failed at .value: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes +} diff --git a/tests/compile-fail/uninit_integer_signed.rs b/tests/compile-fail/uninit_integer_signed.rs new file mode 100644 index 00000000000..bb5d7314a7c --- /dev/null +++ b/tests/compile-fail/uninit_integer_signed.rs @@ -0,0 +1,8 @@ +// compile-flags: -Zmiri-check-number-validity + +// This test is adapted from https://github.com/rust-lang/miri/issues/1340#issue-600900312. + +fn main() { + let _val = unsafe { std::mem::MaybeUninit::::uninit().assume_init() }; + //~^ ERROR type validation failed at .value: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes +} diff --git a/tests/run-pass/uninit_number_ignored.rs b/tests/run-pass/uninit_number_ignored.rs new file mode 100644 index 00000000000..77d6af6e99c --- /dev/null +++ b/tests/run-pass/uninit_number_ignored.rs @@ -0,0 +1,8 @@ +// This test is adapted from https://github.com/rust-lang/miri/issues/1340#issue-600900312. +// This test passes because -Zmiri-check-number-validity is not passed. + +fn main() { + let _val1 = unsafe { std::mem::MaybeUninit::::uninit().assume_init() }; + let _val2 = unsafe { std::mem::MaybeUninit::::uninit().assume_init() }; + let _val3 = unsafe { std::mem::MaybeUninit::::uninit().assume_init() }; +}