Skip to content

Commit 237b11d

Browse files
committed
Auto merge of rust-lang#129778 - RalfJung:interp-lossy-typed-copy, r=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
2 parents f7b7aa3 + d257159 commit 237b11d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

core/tests/mem.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -773,15 +773,20 @@ fn offset_of_addr() {
773773
#[test]
774774
fn const_maybe_uninit_zeroed() {
775775
// Sanity check for `MaybeUninit::zeroed` in a realistic const situation (plugin array term)
776+
777+
// It is crucial that this type has no padding!
776778
#[repr(C)]
777779
struct Foo {
778-
a: Option<&'static str>,
780+
a: Option<&'static u8>,
779781
b: Bar,
780782
c: f32,
783+
_pad: u32,
781784
d: *const u8,
782785
}
786+
783787
#[repr(C)]
784788
struct Bar(usize);
789+
785790
struct FooPtr(*const Foo);
786791
unsafe impl Sync for FooPtr {}
787792

0 commit comments

Comments
 (0)