]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #97684 - RalfJung:better-provenance-control, r=oli-obk
authorbors <bors@rust-lang.org>
Mon, 6 Jun 2022 13:28:58 +0000 (13:28 +0000)
committerbors <bors@rust-lang.org>
Mon, 6 Jun 2022 13:28:58 +0000 (13:28 +0000)
interpret: better control over whether we read data with provenance

The resolution in https://github.com/rust-lang/unsafe-code-guidelines/issues/286 seems to be that when we load data at integer type, we implicitly strip provenance. So let's implement that in Miri at least for scalar loads. This makes use of the fact that `Scalar` layouts distinguish pointer-sized integers and pointers -- so I was expecting some wild bugs where layouts set this incorrectly, but so far that does not seem to happen.

This does not entirely implement the solution to https://github.com/rust-lang/unsafe-code-guidelines/issues/286; we still do the wrong thing for integers in larger types: we will `copy_op` them and then do validation, and validation will complain about the provenance. To fix that we need mutating validation; validation needs to strip the provenance rather than complaining about it. This is a larger undertaking (but will also help resolve https://github.com/rust-lang/miri/issues/845 since we can reset padding to `Uninit`).

The reason this is useful is that we can now implement `addr` as a `transmute` from a pointer to an integer, and actually get the desired behavior of stripping provenance without exposing it!

1  2 
compiler/rustc_target/src/abi/mod.rs

Simple merge