Add tests for -Zmiri-check-number-validity

This commit is contained in:
Noah Lev 2021-10-24 13:43:47 -07:00
parent 1659ef4206
commit b3be6b44b6
4 changed files with 32 additions and 0 deletions

View File

@ -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::<f32>::uninit().assume_init() };
//~^ ERROR type validation failed at .value: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
}

View File

@ -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::<usize>::uninit().assume_init() };
//~^ ERROR type validation failed at .value: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
}

View File

@ -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::<i32>::uninit().assume_init() };
//~^ ERROR type validation failed at .value: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
}

View File

@ -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::<usize>::uninit().assume_init() };
let _val2 = unsafe { std::mem::MaybeUninit::<i32>::uninit().assume_init() };
let _val3 = unsafe { std::mem::MaybeUninit::<f32>::uninit().assume_init() };
}