Skip to content

Commit

Permalink
Auto merge of rust-lang#129778 - RalfJung:interp-lossy-typed-copy, r=…
Browse files Browse the repository at this point in the history
…saethlin

interpret: make typed copies lossy wrt provenance and padding

A "typed copy" in Rust can be a lossy process: when copying at type `usize` (or any other non-pointer type), if the original memory had any provenance, that provenance is lost. When copying at pointer type, if the original memory had partial provenance (i.e., not the same provenance for all bytes), that provenance is lost. When copying any type with padding, the contents of padding are lost.

This PR equips our validity-checking pass with the ability to reset provenance and padding according to those rules. Can be reviewed commit-by-commit. The first three commits are just preparation without any functional change.

Fixes rust-lang/miri#845
Fixes rust-lang/miri#2182
  • Loading branch information
bors committed Sep 10, 2024
2 parents f7b7aa3 + d257159 commit 237b11d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/tests/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,15 +773,20 @@ fn offset_of_addr() {
#[test]
fn const_maybe_uninit_zeroed() {
// Sanity check for `MaybeUninit::zeroed` in a realistic const situation (plugin array term)

// It is crucial that this type has no padding!
#[repr(C)]
struct Foo {
a: Option<&'static str>,
a: Option<&'static u8>,
b: Bar,
c: f32,
_pad: u32,
d: *const u8,
}

#[repr(C)]
struct Bar(usize);

struct FooPtr(*const Foo);
unsafe impl Sync for FooPtr {}

Expand Down

0 comments on commit 237b11d

Please sign in to comment.