1 //@compile-flags: -Zmiri-permissive-provenance
3 /// This manually makes sure that we have a pointer with the proper alignment.
4 fn manual_alignment() {
6 let base_addr = x as *mut _ as usize;
7 let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr + 1 };
8 let u16_ptr = base_addr_aligned as *mut u16;
14 /// Test standard library `align_to`.
16 const LEN: usize = 128;
17 let buf = &[0u8; LEN];
18 let (l, m, r) = unsafe { buf.align_to::<i32>() };
19 assert!(m.len() * 4 >= LEN - 4);
20 assert!(l.len() + r.len() <= 4);
24 // Do this a couple times in a loop because it may work "by chance".