diff --git a/tests/ui/simd/repr_packed.rs b/tests/ui/simd/repr_packed.rs index bfe9a2433f64..df2d59a58b88 100644 --- a/tests/ui/simd/repr_packed.rs +++ b/tests/ui/simd/repr_packed.rs @@ -6,6 +6,9 @@ #[repr(simd, packed)] struct Simd([T; N]); +#[repr(simd)] +struct FullSimd([T; N]); + fn check_size_align() { use std::mem; assert_eq!(mem::size_of::>(), mem::size_of::<[T; N]>()); @@ -37,9 +40,20 @@ fn main() { unsafe { // powers-of-two have no padding and work as usual - // non-powers-of-two have padding and need to be expanded to full vectors let x: Simd = simd_add(Simd::([0., 1., 2., 3.]), Simd::([2., 2., 2., 2.])); assert_eq!(std::mem::transmute::<_, [f64; 4]>(x), [2., 3., 4., 5.]); + + // non-powers-of-two have padding and need to be expanded to full vectors + fn load(v: Simd) -> FullSimd { + unsafe { + let mut tmp = core::mem::MaybeUninit::>::uninit(); + std::ptr::copy_nonoverlapping(&v as *const _, tmp.as_mut_ptr().cast(), 1); + tmp.assume_init() + } + } + let x: FullSimd = + simd_add(load(Simd::([0., 1., 2.])), load(Simd::([2., 2., 2.]))); + assert_eq!(x.0, [2., 3., 4.]); } }