Skip to content

Commit

Permalink
Test and reject out-of-bounds shuffle vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Sep 15, 2020
1 parent 07ece44 commit ac96f5b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/test/ui/simd/shuffle-not-out-of-bounds.rs
@@ -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
}
}
9 changes: 9 additions & 0 deletions src/test/ui/simd/shuffle-not-out-of-bounds.stderr
@@ -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`.

0 comments on commit ac96f5b

Please sign in to comment.