2 #![allow(non_camel_case_types)]
3 #![feature(repr_simd, platform_intrinsics)]
5 // Test for #73542 to verify out-of-bounds shuffle vectors do not compile.
12 #[derive(Copy, Clone)]
16 #[derive(Copy, Clone)]
20 #[derive(Copy, Clone)]
21 struct u8x16([u8; 16]);
24 #[derive(Copy, Clone)]
25 struct u8x32([u8; 32]);
28 #[derive(Copy, Clone)]
29 struct u8x64([u8; 64]);
31 extern "platform-intrinsic" {
32 pub fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
33 pub fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U;
34 pub fn simd_shuffle8<T, U>(x: T, y: T, idx: [u32; 8]) -> U;
35 pub fn simd_shuffle16<T, U>(x: T, y: T, idx: [u32; 16]) -> U;
36 pub fn simd_shuffle32<T, U>(x: T, y: T, idx: [u32; 32]) -> U;
37 pub fn simd_shuffle64<T, U>(x: T, y: T, idx: [u32; 64]) -> U;
40 // Test vectors by lane size. Since LLVM does not distinguish between a shuffle
41 // over two f32s and a shuffle over two u64s, or any other such combination,
42 // it is not necessary to test every possible vector, only lane counts.
43 macro_rules! test_shuffle_lanes {
44 ($n:literal, $x:ident, $y:ident) => {
47 const ARR: [u32; $n] = {
48 let mut arr = [0; $n];
53 let vals = [0; $n].map(|_| { n = n - 1; n });
61 //~^^^^^ ERROR: invalid monomorphization of `simd_shuffle2` intrinsic
62 //~| ERROR: invalid monomorphization of `simd_shuffle4` intrinsic
63 //~| ERROR: invalid monomorphization of `simd_shuffle8` intrinsic
64 //~| ERROR: invalid monomorphization of `simd_shuffle16` intrinsic
65 //~| ERROR: invalid monomorphization of `simd_shuffle32` intrinsic
66 //~| ERROR: invalid monomorphization of `simd_shuffle64` intrinsic
67 // Because the test is mostly embedded in a macro, all the errors have the same origin point.
68 // And unfortunately, standard comments, as in the UI test harness, disappear in macros!
71 test_shuffle_lanes!(2, u8x2, simd_shuffle2);
72 test_shuffle_lanes!(4, u8x4, simd_shuffle4);
73 test_shuffle_lanes!(8, u8x8, simd_shuffle8);
74 test_shuffle_lanes!(16, u8x16, simd_shuffle16);
75 test_shuffle_lanes!(32, u8x32, simd_shuffle32);
76 test_shuffle_lanes!(64, u8x64, simd_shuffle64);
78 extern "platform-intrinsic" {
79 fn simd_shuffle<T, I, U>(a: T, b: T, i: I) -> U;
82 const I: [u32; 2] = [4, 4];
84 let _: u8x2 = simd_shuffle(v, v, I);
85 //~^ ERROR invalid monomorphization of `simd_shuffle` intrinsic