-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #71164 - RalfJung:uninit-not-undef, r=oli-obk
reword Miri validity errors: undefined -> uninitialized I don't think we say "undefined value" or anything like that anywhere in the docs or so, but we do use the term "uninitialized memory", so I think we should do the same here. Longer-term, I think we should also internally rename "undef" to "uninit". r? @oli-obk
- Loading branch information
Showing
6 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#![feature(const_transmute)] | ||
#![allow(const_err)] // make sure we cannot allow away the errors tested here | ||
|
||
//! Test the "array of int" fast path in validity checking, and in particular whether it | ||
//! points at the right array element. | ||
use std::mem; | ||
|
||
#[repr(C)] | ||
union MaybeUninit<T: Copy> { | ||
uninit: (), | ||
init: T, | ||
} | ||
|
||
const UNINIT_INT_0: [u32; 3] = unsafe { | ||
//~^ ERROR it is undefined behavior to use this value | ||
//~| type validation failed: encountered uninitialized bytes at [0] | ||
[ | ||
MaybeUninit { uninit: () }.init, | ||
1, | ||
2, | ||
] | ||
}; | ||
const UNINIT_INT_1: [u32; 3] = unsafe { | ||
//~^ ERROR it is undefined behavior to use this value | ||
//~| type validation failed: encountered uninitialized bytes at [1] | ||
mem::transmute( | ||
[ | ||
0u8, | ||
0u8, | ||
0u8, | ||
0u8, | ||
1u8, | ||
MaybeUninit { uninit: () }.init, | ||
1u8, | ||
1u8, | ||
2u8, | ||
2u8, | ||
MaybeUninit { uninit: () }.init, | ||
2u8, | ||
] | ||
) | ||
}; | ||
const UNINIT_INT_2: [u32; 3] = unsafe { | ||
//~^ ERROR it is undefined behavior to use this value | ||
//~| type validation failed: encountered uninitialized bytes at [2] | ||
mem::transmute( | ||
[ | ||
0u8, | ||
0u8, | ||
0u8, | ||
0u8, | ||
1u8, | ||
1u8, | ||
1u8, | ||
1u8, | ||
2u8, | ||
2u8, | ||
2u8, | ||
MaybeUninit { uninit: () }.init, | ||
] | ||
) | ||
}; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/ub-int-array.rs:15:1 | ||
| | ||
LL | / const UNINIT_INT_0: [u32; 3] = unsafe { | ||
LL | | | ||
LL | | | ||
LL | | [ | ||
... | | ||
LL | | ] | ||
LL | | }; | ||
| |__^ type validation failed: encountered uninitialized bytes at [0] | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/ub-int-array.rs:24:1 | ||
| | ||
LL | / const UNINIT_INT_1: [u32; 3] = unsafe { | ||
LL | | | ||
LL | | | ||
LL | | mem::transmute( | ||
... | | ||
LL | | ) | ||
LL | | }; | ||
| |__^ type validation failed: encountered uninitialized bytes at [1] | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/ub-int-array.rs:44:1 | ||
| | ||
LL | / const UNINIT_INT_2: [u32; 3] = unsafe { | ||
LL | | | ||
LL | | | ||
LL | | mem::transmute( | ||
... | | ||
LL | | ) | ||
LL | | }; | ||
| |__^ type validation failed: encountered uninitialized bytes at [2] | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters