Skip to content

Commit f223a5f

Browse files
committed
Auto merge of rust-lang#2361 - RalfJung:uninit, r=RalfJung
test that we also find bad uses of mem::uninitialized Also we really don't need to separately test signed and unsigned integers... our test suite is big enough as it is. ;)
2 parents 2643e41 + cd3535d commit f223a5f

File tree

4 files changed

+5
-24
lines changed

4 files changed

+5
-24
lines changed

tests/fail/validity/uninit_float.rs

+3-1
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

+2-2
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

-6
This file was deleted.

tests/fail/validity/uninit_integer_signed.stderr

-15
This file was deleted.

0 commit comments

Comments
 (0)