]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/too-large-primval-write-problem.rs
Auto merge of #104915 - weihanglo:update-cargo, r=ehuss
[rust.git] / src / tools / miri / tests / pass / too-large-primval-write-problem.rs
1 // `PrimVal`s in Miri are represented with 8 bytes (u64) and at the time of writing, the `-x`
2 // will sign extend into the entire 8 bytes. Then, if you tried to write the `-x` into
3 // something smaller than 8 bytes, like a 4 byte pointer, it would crash in byteorder crate
4 // code that assumed only the low 4 bytes would be set. Actually, we were masking properly for
5 // everything except pointers before I fixed it, so this was probably impossible to reproduce on
6 // 64-bit.
7 //
8 // This is just intended as a regression test to make sure we don't reintroduce this problem.
9
10 #[cfg(target_pointer_width = "32")]
11 fn main() {
12     use std::mem::transmute;
13
14     // Make the weird PrimVal.
15     let x = 1i32;
16     let bad = unsafe { transmute::<i32, *const u8>(-x) };
17
18     // Force it through the Memory::write_primval code.
19     drop(Box::new(bad));
20 }
21
22 #[cfg(not(target_pointer_width = "32"))]
23 fn main() {}