2022-07-21 20:48:30 -05:00
|
|
|
//@ run-pass
|
|
|
|
|
2024-02-23 11:36:24 -06:00
|
|
|
#![feature(repr_simd, intrinsics)]
|
2022-07-21 20:48:30 -05:00
|
|
|
|
2024-02-23 11:36:24 -06:00
|
|
|
extern "rust-intrinsic" {
|
2022-07-21 20:48:30 -05:00
|
|
|
fn simd_cast_ptr<T, U>(x: T) -> U;
|
2024-04-03 08:17:00 -05:00
|
|
|
fn simd_expose_provenance<T, U>(x: T) -> U;
|
2024-03-23 17:00:53 -05:00
|
|
|
fn simd_with_exposed_provenance<T, U>(x: T) -> U;
|
2022-07-21 20:48:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
#[repr(simd)]
|
|
|
|
struct V<T>([T; 2]);
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
unsafe {
|
|
|
|
let mut foo = 4i8;
|
|
|
|
let ptr = &mut foo as *mut i8;
|
|
|
|
|
|
|
|
let ptrs = V::<*mut i8>([ptr, core::ptr::null_mut()]);
|
|
|
|
|
|
|
|
// change constness and type
|
|
|
|
let const_ptrs: V<*const u8> = simd_cast_ptr(ptrs);
|
|
|
|
|
2024-04-03 08:17:00 -05:00
|
|
|
let exposed_addr: V<usize> = simd_expose_provenance(const_ptrs);
|
2022-07-21 20:48:30 -05:00
|
|
|
|
2024-03-23 17:00:53 -05:00
|
|
|
let with_exposed_provenance: V<*mut i8> = simd_with_exposed_provenance(exposed_addr);
|
2022-07-21 20:48:30 -05:00
|
|
|
|
|
|
|
assert!(const_ptrs.0 == [ptr as *const u8, core::ptr::null()]);
|
|
|
|
assert!(exposed_addr.0 == [ptr as usize, 0]);
|
2024-03-23 05:47:11 -05:00
|
|
|
assert!(with_exposed_provenance.0 == ptrs.0);
|
2022-07-21 20:48:30 -05:00
|
|
|
}
|
|
|
|
}
|