Test and reject out-of-bounds shuffle vectors

This commit is contained in:
Jubilee Young 2020-09-15 16:10:26 -07:00
parent 07ece44a42
commit ac96f5b39c
2 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,23 @@
// build-fail
#![allow(non_camel_case_types)]
#![feature(repr_simd, platform_intrinsics)]
// Test for #73542 to verify out-of-bounds shuffle vectors do not compile.
#[repr(simd)]
#[derive(Copy, Clone)]
struct f32x4(f32, f32, f32, f32);
extern "platform-intrinsic" {
pub fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U;
}
fn main() {
unsafe {
let vec1 = f32x4(1.0, 2.0, 3.0, 4.0);
let vec2 = f32x4(10_000.0, 20_000.0, 30_000.0, 40_000.0);
let shuffled: f32x4 = simd_shuffle4(vec1, vec2, [0, 4, 7, 9]);
//~^ ERROR: invalid monomorphization of `simd_shuffle4` intrinsic: shuffle index #3 is out
}
}

View file

@ -0,0 +1,9 @@
error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: shuffle index #3 is out of bounds (limit 8)
--> $DIR/shuffle-not-out-of-bounds.rs:20:31
|
LL | let shuffled: f32x4 = simd_shuffle4(vec1, vec2, [0, 4, 7, 9]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0511`.