Add flag to check for uninitialized numbers#1904
Conversation
|
(Some of these commits should probably be squashed together, but I think I'll wait until it's closer to being merged before doing so.) |
|
By the way, let me know if/when you want me to squash :) |
|
Yeah this looks ready, so please squash. :) |
ef28253 to
c4f067e
Compare
miri: Detect uninitialized integers and floats Part of rust-lang/miri#1340. Companion Miri PR: rust-lang/miri#1904 r? `@RalfJung`
|
@camelid could you rebase on top of master and then also update the |
This commit adds a `-Zmiri-check-number-initialization` flag to check that integers and floats are initialized. This commit also changes some shims to write at type `MaybeUninit<...>` in order to prevent spurious errors from the uninit check.
Should I add a test for this, or is it not necessary? |
I don't think that is necessary. |
So that we get rust-lang/rust#88670.
|
@bors r+ |
|
📌 Commit 6dd1082 has been approved by |
|
Thanks again for your help with this change! ❤️ |
|
☀️ Test successful - checks-actions |
|
I'll try to open a submodule sync later today. |
1: Remove miri hack r=taiki-e a=taiki-e Use currently use a hack to avoid rust-lang/rust#69488 and to make sure that Miri errors for atomic load/store of integers containing uninitialized bytes (which is probably not a problem and uncharted territory at best [1] [2] [3], and can be detected by `-Zmiri-check-number-validity` [4]), do not mask Miri errors for the use of uninitialized bytes (which is definitely a problem). https://github.com/taiki-e/atomic-memcpy/blob/3507fef17534e4825b2b303d04702b4678e29dd0/src/lib.rs#L426-L450 [1]: crossbeam-rs/crossbeam#315 [2]: rust-lang/unsafe-code-guidelines#158 [3]: rust-lang/unsafe-code-guidelines#71 [4]: rust-lang/miri#1904 However, this actually causes another "unsupported operation" Miri error. ``` error: unsupported operation: unable to turn pointer into raw bytes --> /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:701:9 | 701 | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes | = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support ``` Co-authored-by: Taiki Endo <te316e89@gmail.com>
Closes #1340.
Companion rustc PR that implements this in the Miri engine: rust-lang/rust#88670
r? @RalfJung