test that we also find bad uses of mem::uninitialized

This commit is contained in:
Ralf Jung 2022-07-12 09:49:11 -04:00
parent 2643e41674
commit cd3535d256
4 changed files with 5 additions and 24 deletions

View File

@ -1,6 +1,8 @@
#![allow(deprecated)]
// 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() };
// Deliberately using `mem::uninitialized` to make sure that despite all the mitigations, we consider this UB.
let _val: f32 = unsafe { std::mem::uninitialized() };
//~^ ERROR: constructing invalid value at .value: encountered uninitialized bytes, but expected initialized bytes
}

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: constructing invalid value at .value: encountered uninitialized bytes, but expected initialized bytes
--> $DIR/uninit_float.rs:LL:CC
|
LL | let _val = unsafe { std::mem::MaybeUninit::<f32>::uninit().assume_init() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value: encountered uninitialized bytes, but expected initialized bytes
LL | let _val: f32 = unsafe { std::mem::uninitialized() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value: encountered uninitialized bytes, but expected initialized bytes
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

View File

@ -1,6 +0,0 @@
// 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: constructing invalid value at .value: encountered uninitialized bytes, but expected initialized bytes
}

View File

@ -1,15 +0,0 @@
error: Undefined Behavior: constructing invalid value at .value: encountered uninitialized bytes, but expected initialized bytes
--> $DIR/uninit_integer_signed.rs:LL:CC
|
LL | let _val = unsafe { std::mem::MaybeUninit::<i32>::uninit().assume_init() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value: encountered uninitialized bytes, but expected initialized bytes
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: inside `main` at $DIR/uninit_integer_signed.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to previous error