Skip to content

Commit ac96f5b

Browse files
Test and reject out-of-bounds shuffle vectors
1 parent 07ece44 commit ac96f5b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 f32x4(f32, f32, f32, f32);
10+
11+
extern "platform-intrinsic" {
12+
pub fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U;
13+
}
14+
15+
16+
fn main() {
17+
unsafe {
18+
let vec1 = f32x4(1.0, 2.0, 3.0, 4.0);
19+
let vec2 = f32x4(10_000.0, 20_000.0, 30_000.0, 40_000.0);
20+
let shuffled: f32x4 = simd_shuffle4(vec1, vec2, [0, 4, 7, 9]);
21+
//~^ ERROR: invalid monomorphization of `simd_shuffle4` intrinsic: shuffle index #3 is out
22+
}
23+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: shuffle index #3 is out of bounds (limit 8)
2+
--> $DIR/shuffle-not-out-of-bounds.rs:20:31
3+
|
4+
LL | let shuffled: f32x4 = simd_shuffle4(vec1, vec2, [0, 4, 7, 9]);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0511`.

0 commit comments

Comments
 (0)