diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index ebc993f14ea03..50166609670b6 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -111,7 +111,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { bx: &mut Bx, layout: TyAndLayout<'tcx>, ) -> Self { - if layout.deref().is_scalable_vector() { + if layout.peel_transparent_wrappers(bx).deref().is_scalable_vector() { Self::alloca_scalable(bx, layout) } else { Self::alloca_size(bx, layout.size, layout) @@ -157,7 +157,11 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { bx: &mut Bx, layout: TyAndLayout<'tcx>, ) -> Self { - PlaceValue::new_sized(bx.alloca_with_ty(layout), layout.align.abi).with_type(layout) + PlaceValue::new_sized( + bx.alloca_with_ty(layout.peel_transparent_wrappers(bx)), + layout.align.abi, + ) + .with_type(layout) } } diff --git a/tests/ui/scalable-vectors/transparent-wrappers.rs b/tests/ui/scalable-vectors/transparent-wrappers.rs new file mode 100644 index 0000000000000..e9c50f71aae5a --- /dev/null +++ b/tests/ui/scalable-vectors/transparent-wrappers.rs @@ -0,0 +1,50 @@ +//@ only-aarch64 +//@ build-pass +//@ compile-flags: --emit=obj -Ctarget-feature=+sve +//@ edition:2021 +#![feature(simd_ffi)] +#![feature(stdarch_aarch64_sve)] + +use std::arch::aarch64::*; + +// Tests that scalable vectors in transparent wrapper types compile correctly (that is, that +// alloca we generate in LLVM IR are for scalable vector types and not arrays, because rustc +// looks through the transparent wrapper). + +static I16_147: [i16; 147] = [ + 0x0, 0x400, 0x37ff, 0x3800, 0x3801, 0x3bff, 0x3c00, 0x3c01, 0x3e00, 0x4900, 0x7bff, 0x7c00, + 0x7f23, 0x7e00, 0x7d23, 0x7c01, 0x12, 0x3ff, 0x1, -0x8000, -0x7c00, -0x4801, -0x4800, -0x47ff, + -0x4401, -0x4400, -0x43ff, -0x4200, -0x3700, -0x401, -0x400, -0xdd, -0x200, -0x2dd, -0x3ff, + -0x7fee, -0x7c01, -0x7fff, -0x400, -0x4000, 0x5140, 0x5800, 0x63d2, 0x5630, 0x3560, -0x6e6f, + 0x4178, 0x6212, 0x67d0, 0x3312, 0x4cef, 0x4973, 0x3ecc, 0x5166, 0x4d80, 0x6248, 0x46fd, 0x39c4, + 0x39c5, 0x4866, 0x6050, 0x498e, 0x4a0f, 0x3555, -0x400, -0x4000, -0x6e6f, 0x5140, 0x5800, + -0x7fff, -0x7c01, 0x63d2, 0x5630, 0x3560, 0x4178, 0x7d23, 0x7c01, 0x12, -0x4800, 0x3ff, 0x1, + 0x7e00, 0x7f23, -0x8000, -0x7c00, -0x4801, -0x47ff, 0x3312, 0x4cef, 0x4973, 0x39c4, 0x3ecc, + 0x5166, 0x67d0, 0x6212, 0x4d80, 0x6248, 0x46fd, 0x39c5, -0x43ff, -0x4200, -0x3700, -0x3ff, + -0x401, -0x400, -0x4400, -0x4401, -0xdd, -0x200, -0x2dd, -0x7fee, 0x37ff, 0x3800, 0x3801, + 0x7bff, 0x3bff, 0x3c00, 0x400, 0x0, 0x3c01, 0x3e00, 0x4900, 0x7c00, 0x498e, 0x4a0f, 0x6050, + 0x4866, 0x3555, 0x0, 0x400, 0x37ff, 0x3800, 0x3801, 0x3bff, 0x3c00, 0x3c01, 0x3e00, 0x4900, + 0x7bff, 0x7c00, 0x7f23, 0x7e00, 0x7d23, 0x7c01, 0x12, 0x3ff, 0x1, +]; + +#[allow(improper_ctypes)] +unsafe extern "C" { + fn svcreate2_s16_wrapper(__dst: *mut svint16x2_t, x0: *const svint16_t, x1: *const svint16_t); +} + +fn main() { + unsafe { + let __pred = svptrue_b16(); + let x0_val = svld1_s16(__pred, I16_147.as_ptr().add(0) as _); + + let mut __c_return_value = std::mem::MaybeUninit::uninit(); + svcreate2_s16_wrapper(__c_return_value.as_mut_ptr(), &raw const x0_val, &raw const x0_val); + let __c_return_value = __c_return_value.assume_init(); + + let eq = svcmpeq_s16( + __pred, + svget2_s16::<0>(__c_return_value), + svget2_s16::<0>(__c_return_value), + ); + } +}