Skip to content

Commit 65e4488

Browse files
authored
Rollup merge of #76768 - workingjubilee:reject-oob-shuffles, r=ralfjung
Test and reject out-of-bounds shuffle vectors Fixes #73542.
2 parents b654555 + 2fcd183 commit 65e4488

File tree

2 files changed

+267
-0
lines changed

2 files changed

+267
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
// build-fail
2+
#![allow(non_camel_case_types)]
3+
#![feature(repr_simd, platform_intrinsics)]
4+
5+
// Test for #73542 to verify out-of-bounds shuffle vectors do not compile.
6+
7+
#[repr(simd)]
8+
#[derive(Copy, Clone)]
9+
struct u8x2(u8, u8);
10+
11+
#[repr(simd)]
12+
#[derive(Copy, Clone)]
13+
struct u8x4(u8, u8, u8, u8);
14+
15+
#[repr(simd)]
16+
#[derive(Copy, Clone)]
17+
struct u8x8(u8, u8, u8, u8, u8, u8, u8, u8);
18+
19+
#[repr(simd)]
20+
#[derive(Copy, Clone)]
21+
struct u8x16(
22+
u8,
23+
u8,
24+
u8,
25+
u8,
26+
u8,
27+
u8,
28+
u8,
29+
u8,
30+
u8,
31+
u8,
32+
u8,
33+
u8,
34+
u8,
35+
u8,
36+
u8,
37+
u8,
38+
);
39+
40+
#[repr(simd)]
41+
#[derive(Copy, Clone)]
42+
struct u8x32(
43+
u8,
44+
u8,
45+
u8,
46+
u8,
47+
u8,
48+
u8,
49+
u8,
50+
u8,
51+
u8,
52+
u8,
53+
u8,
54+
u8,
55+
u8,
56+
u8,
57+
u8,
58+
u8,
59+
u8,
60+
u8,
61+
u8,
62+
u8,
63+
u8,
64+
u8,
65+
u8,
66+
u8,
67+
u8,
68+
u8,
69+
u8,
70+
u8,
71+
u8,
72+
u8,
73+
u8,
74+
u8,
75+
);
76+
77+
#[repr(simd)]
78+
#[derive(Copy, Clone)]
79+
struct u8x64(
80+
u8,
81+
u8,
82+
u8,
83+
u8,
84+
u8,
85+
u8,
86+
u8,
87+
u8,
88+
u8,
89+
u8,
90+
u8,
91+
u8,
92+
u8,
93+
u8,
94+
u8,
95+
u8,
96+
u8,
97+
u8,
98+
u8,
99+
u8,
100+
u8,
101+
u8,
102+
u8,
103+
u8,
104+
u8,
105+
u8,
106+
u8,
107+
u8,
108+
u8,
109+
u8,
110+
u8,
111+
u8,
112+
u8,
113+
u8,
114+
u8,
115+
u8,
116+
u8,
117+
u8,
118+
u8,
119+
u8,
120+
u8,
121+
u8,
122+
u8,
123+
u8,
124+
u8,
125+
u8,
126+
u8,
127+
u8,
128+
u8,
129+
u8,
130+
u8,
131+
u8,
132+
u8,
133+
u8,
134+
u8,
135+
u8,
136+
u8,
137+
u8,
138+
u8,
139+
u8,
140+
u8,
141+
u8,
142+
u8,
143+
u8,
144+
);
145+
146+
// Test vectors by lane size. Since LLVM does not distinguish between a shuffle
147+
// over two f32s and a shuffle over two u64s, or any other such combination,
148+
// it is not necessary to test every possible vector, only lane counts.
149+
macro_rules! test_shuffle_lanes {
150+
($n:literal, $x:ident, $y:ident, $t:tt) => {
151+
unsafe {
152+
let shuffle: $x = {
153+
const ARR: [u32; $n] = {
154+
let mut arr = [0; $n];
155+
arr[0] = $n * 2;
156+
arr
157+
};
158+
extern "platform-intrinsic" {
159+
pub fn $y<T, U>(x: T, y: T, idx: [u32; $n]) -> U;
160+
}
161+
let vec1 = $x$t;
162+
let vec2 = $x$t;
163+
$y(vec1, vec2, ARR)
164+
};
165+
}
166+
}
167+
}
168+
//~^^^^^ ERROR: invalid monomorphization of `simd_shuffle2` intrinsic
169+
//~| ERROR: invalid monomorphization of `simd_shuffle4` intrinsic
170+
//~| ERROR: invalid monomorphization of `simd_shuffle8` intrinsic
171+
//~| ERROR: invalid monomorphization of `simd_shuffle16` intrinsic
172+
//~| ERROR: invalid monomorphization of `simd_shuffle32` intrinsic
173+
//~| ERROR: invalid monomorphization of `simd_shuffle64` intrinsic
174+
// Because the test is mostly embedded in a macro, all the errors have the same origin point.
175+
// And unfortunately, standard comments, as in the UI test harness, disappear in macros!
176+
177+
fn main() {
178+
test_shuffle_lanes!(2, u8x2, simd_shuffle2, (2, 1));
179+
test_shuffle_lanes!(4, u8x4, simd_shuffle4, (4, 3, 2, 1));
180+
test_shuffle_lanes!(8, u8x8, simd_shuffle8, (8, 7, 6, 5, 4, 3, 2, 1));
181+
test_shuffle_lanes!(16, u8x16, simd_shuffle16,
182+
(16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
183+
test_shuffle_lanes!(32, u8x32, simd_shuffle32,
184+
(32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16,
185+
15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
186+
test_shuffle_lanes!(64, u8x64, simd_shuffle64,
187+
(64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49,
188+
48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33,
189+
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17,
190+
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
191+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: shuffle index #0 is out of bounds (limit 4)
2+
--> $DIR/shuffle-not-out-of-bounds.rs:163:21
3+
|
4+
LL | $y(vec1, vec2, ARR)
5+
| ^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | test_shuffle_lanes!(2, u8x2, simd_shuffle2, (2, 1));
8+
| ---------------------------------------------------- in this macro invocation
9+
|
10+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: shuffle index #0 is out of bounds (limit 8)
13+
--> $DIR/shuffle-not-out-of-bounds.rs:163:21
14+
|
15+
LL | $y(vec1, vec2, ARR)
16+
| ^^^^^^^^^^^^^^^^^^^
17+
...
18+
LL | test_shuffle_lanes!(4, u8x4, simd_shuffle4, (4, 3, 2, 1));
19+
| ---------------------------------------------------------- in this macro invocation
20+
|
21+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
22+
23+
error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: shuffle index #0 is out of bounds (limit 16)
24+
--> $DIR/shuffle-not-out-of-bounds.rs:163:21
25+
|
26+
LL | $y(vec1, vec2, ARR)
27+
| ^^^^^^^^^^^^^^^^^^^
28+
...
29+
LL | test_shuffle_lanes!(8, u8x8, simd_shuffle8, (8, 7, 6, 5, 4, 3, 2, 1));
30+
| ---------------------------------------------------------------------- in this macro invocation
31+
|
32+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
33+
34+
error[E0511]: invalid monomorphization of `simd_shuffle16` intrinsic: shuffle index #0 is out of bounds (limit 32)
35+
--> $DIR/shuffle-not-out-of-bounds.rs:163:21
36+
|
37+
LL | $y(vec1, vec2, ARR)
38+
| ^^^^^^^^^^^^^^^^^^^
39+
...
40+
LL | / test_shuffle_lanes!(16, u8x16, simd_shuffle16,
41+
LL | | (16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
42+
| |_________________________________________________________________- in this macro invocation
43+
|
44+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
45+
46+
error[E0511]: invalid monomorphization of `simd_shuffle32` intrinsic: shuffle index #0 is out of bounds (limit 64)
47+
--> $DIR/shuffle-not-out-of-bounds.rs:163:21
48+
|
49+
LL | $y(vec1, vec2, ARR)
50+
| ^^^^^^^^^^^^^^^^^^^
51+
...
52+
LL | / test_shuffle_lanes!(32, u8x32, simd_shuffle32,
53+
LL | | (32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16,
54+
LL | | 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
55+
| |_____________________________________________________________- in this macro invocation
56+
|
57+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
58+
59+
error[E0511]: invalid monomorphization of `simd_shuffle64` intrinsic: shuffle index #0 is out of bounds (limit 128)
60+
--> $DIR/shuffle-not-out-of-bounds.rs:163:21
61+
|
62+
LL | $y(vec1, vec2, ARR)
63+
| ^^^^^^^^^^^^^^^^^^^
64+
...
65+
LL | / test_shuffle_lanes!(64, u8x64, simd_shuffle64,
66+
LL | | (64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49,
67+
LL | | 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33,
68+
LL | | 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17,
69+
LL | | 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
70+
| |_________________________________________________________________- in this macro invocation
71+
|
72+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
73+
74+
error: aborting due to 6 previous errors
75+
76+
For more information about this error, try `rustc --explain E0511`.

0 commit comments

Comments
 (0)