File tree 8 files changed +21
-14
lines changed
8 files changed +21
-14
lines changed Original file line number Diff line number Diff line change 1
- 94b2b15e63c5d2b2a6a0910e3dae554ce9415bf9
1
+ 4fd4de7ea358ad6fc28c5780533ea8ccc09e1006
Original file line number Diff line number Diff line change
1
+ #![ allow( invalid_value) ]
1
2
// Validation makes this fail in the wrong place
2
3
// Make sure we find these even with many checks disabled.
3
4
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
Original file line number Diff line number Diff line change 1
- #![ allow( deprecated) ]
1
+ #![ allow( deprecated, invalid_value ) ]
2
2
// This test is adapted from https://github.com/rust-lang/miri/issues/1340#issue-600900312.
3
3
4
4
fn main ( ) {
5
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 ( ) } ;
6
+ // The array avoids a `Scalar` layout which detects uninit without even doing validation.
7
+ let _val: [ f32 ; 1 ] = unsafe { std:: mem:: uninitialized ( ) } ;
7
8
//~^ ERROR: uninitialized
8
9
}
Original file line number Diff line number Diff line change 1
- error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
1
+ error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized bytes
2
2
--> $DIR/uninit_float.rs:LL:CC
3
3
|
4
- LL | let _val: f32 = unsafe { std::mem::uninitialized() };
5
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
4
+ LL | let _val: [ f32; 1] = unsafe { std::mem::uninitialized() };
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized bytes
6
6
|
7
7
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8
8
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Original file line number Diff line number Diff line change
1
+ #![ allow( invalid_value) ]
1
2
// This test is from https://github.com/rust-lang/miri/issues/1340#issue-600900312.
2
3
3
4
fn main ( ) {
4
- let _val = unsafe { std:: mem:: MaybeUninit :: < usize > :: uninit ( ) . assume_init ( ) } ;
5
+ // The array avoids a `Scalar` layout which detects uninit without even doing validation.
6
+ let _val = unsafe { std:: mem:: MaybeUninit :: < [ usize ; 1 ] > :: uninit ( ) . assume_init ( ) } ;
5
7
//~^ ERROR: uninitialized
6
8
}
Original file line number Diff line number Diff line change 1
- error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
1
+ error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized bytes
2
2
--> $DIR/uninit_integer.rs:LL:CC
3
3
|
4
- LL | let _val = unsafe { std::mem::MaybeUninit::<usize>::uninit().assume_init() };
5
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
4
+ LL | let _val = unsafe { std::mem::MaybeUninit::<[ usize; 1] >::uninit().assume_init() };
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized bytes
6
6
|
7
7
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8
8
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Original file line number Diff line number Diff line change
1
+ #![ allow( invalid_value) ]
2
+
1
3
fn main ( ) {
2
- let _val = unsafe { std:: mem:: MaybeUninit :: < * const u8 > :: uninit ( ) . assume_init ( ) } ;
4
+ // The array avoids a `Scalar` layout which detects uninit without even doing validation.
5
+ let _val = unsafe { std:: mem:: MaybeUninit :: < [ * const u8 ; 1 ] > :: uninit ( ) . assume_init ( ) } ;
3
6
//~^ ERROR: uninitialized
4
7
}
Original file line number Diff line number Diff line change 1
- error: Undefined Behavior: using uninitialized data , but this operation requires initialized memory
1
+ error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized memory , but expected a raw pointer
2
2
--> $DIR/uninit_raw_ptr.rs:LL:CC
3
3
|
4
- LL | let _val = unsafe { std::mem::MaybeUninit::<*const u8>::uninit().assume_init() };
5
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data , but this operation requires initialized memory
4
+ LL | let _val = unsafe { std::mem::MaybeUninit::<[ *const u8; 1] >::uninit().assume_init() };
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized memory , but expected a raw pointer
6
6
|
7
7
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8
8
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
You can’t perform that action at this time.
0 commit comments