From cd3535d25664f02cbf66863a3ccfa682d8082629 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 12 Jul 2022 09:49:11 -0400 Subject: [PATCH] test that we also find bad uses of mem::uninitialized --- tests/fail/validity/uninit_float.rs | 4 +++- tests/fail/validity/uninit_float.stderr | 4 ++-- tests/fail/validity/uninit_integer_signed.rs | 6 ------ tests/fail/validity/uninit_integer_signed.stderr | 15 --------------- 4 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 tests/fail/validity/uninit_integer_signed.rs delete mode 100644 tests/fail/validity/uninit_integer_signed.stderr diff --git a/tests/fail/validity/uninit_float.rs b/tests/fail/validity/uninit_float.rs index 3e7c14786e3..0f4a22cf5b7 100644 --- a/tests/fail/validity/uninit_float.rs +++ b/tests/fail/validity/uninit_float.rs @@ -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::::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 } diff --git a/tests/fail/validity/uninit_float.stderr b/tests/fail/validity/uninit_float.stderr index 2fe27c90432..d9611af79ee 100644 --- a/tests/fail/validity/uninit_float.stderr +++ b/tests/fail/validity/uninit_float.stderr @@ -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::::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 diff --git a/tests/fail/validity/uninit_integer_signed.rs b/tests/fail/validity/uninit_integer_signed.rs deleted file mode 100644 index fa484413784..00000000000 --- a/tests/fail/validity/uninit_integer_signed.rs +++ /dev/null @@ -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::::uninit().assume_init() }; - //~^ ERROR: constructing invalid value at .value: encountered uninitialized bytes, but expected initialized bytes -} diff --git a/tests/fail/validity/uninit_integer_signed.stderr b/tests/fail/validity/uninit_integer_signed.stderr deleted file mode 100644 index c53c96c596e..00000000000 --- a/tests/fail/validity/uninit_integer_signed.stderr +++ /dev/null @@ -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::::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 -