Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit cd3535d

Browse files
committed
test that we also find bad uses of mem::uninitialized
1 parent 2643e41 commit cd3535d

File tree

4 files changed

+5
-24
lines changed

4 files changed

+5
-24
lines changed

tests/fail/validity/uninit_float.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
#![allow(deprecated)]
12
// This test is adapted from https://github.com/rust-lang/miri/issues/1340#issue-600900312.
23

34
fn main() {
4-
let _val = unsafe { std::mem::MaybeUninit::<f32>::uninit().assume_init() };
5+
// Deliberately using `mem::uninitialized` to make sure that despite all the mitigations, we consider this UB.
6+
let _val: f32 = unsafe { std::mem::uninitialized() };
57
//~^ ERROR: constructing invalid value at .value: encountered uninitialized bytes, but expected initialized bytes
68
}

tests/fail/validity/uninit_float.stderr

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

tests/fail/validity/uninit_integer_signed.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/fail/validity/uninit_integer_signed.stderr

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)