-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Test and reject out-of-bounds shuffle vectors #76768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
// 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 u8x2(u8, u8); | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone)] | ||
struct u8x4(u8, u8, u8, u8); | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone)] | ||
struct u8x8(u8, u8, u8, u8, u8, u8, u8, u8); | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone)] | ||
struct u8x16( | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
); | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone)] | ||
struct u8x32( | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
); | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone)] | ||
struct u8x64( | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
u8, | ||
); | ||
|
||
// Test vectors by lane size. Since LLVM does not distinguish between a shuffle | ||
// over two f32s and a shuffle over two u64s, or any other such combination, | ||
// it is not necessary to test every possible vector, only lane counts. | ||
macro_rules! test_shuffle_lanes { | ||
($n:literal, $x:ident, $y:ident, $t:tt) => { | ||
unsafe { | ||
let shuffle: $x = { | ||
const ARR: [u32; $n] = { | ||
let mut arr = [0; $n]; | ||
arr[0] = $n * 2; | ||
arr | ||
}; | ||
extern "platform-intrinsic" { | ||
pub fn $y<T, U>(x: T, y: T, idx: [u32; $n]) -> U; | ||
} | ||
let vec1 = $x$t; | ||
let vec2 = $x$t; | ||
$y(vec1, vec2, ARR) | ||
}; | ||
} | ||
} | ||
} | ||
//~^^^^^ ERROR: invalid monomorphization of `simd_shuffle2` intrinsic | ||
//~^^^^^^ ERROR: invalid monomorphization of `simd_shuffle4` intrinsic | ||
//~^^^^^^^ ERROR: invalid monomorphization of `simd_shuffle8` intrinsic | ||
//~^^^^^^^^ ERROR: invalid monomorphization of `simd_shuffle16` intrinsic | ||
//~^^^^^^^^^ ERROR: invalid monomorphization of `simd_shuffle32` intrinsic | ||
//~^^^^^^^^^^ ERROR: invalid monomorphization of `simd_shuffle64` intrinsic | ||
// Because the test is mostly embedded in a macro, all the errors have the same origin point. | ||
|
||
fn main() { | ||
test_shuffle_lanes!(2, u8x2, simd_shuffle2, (2, 1)); | ||
test_shuffle_lanes!(4, u8x4, simd_shuffle4, (4, 3, 2, 1)); | ||
test_shuffle_lanes!(8, u8x8, simd_shuffle8, (8, 7, 6, 5, 4, 3, 2, 1)); | ||
test_shuffle_lanes!(16, u8x16, simd_shuffle16, | ||
(16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)); | ||
test_shuffle_lanes!(32, u8x32, simd_shuffle32, | ||
(32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, | ||
15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)); | ||
test_shuffle_lanes!(64, u8x64, simd_shuffle64, | ||
(64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, | ||
48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, | ||
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, | ||
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: shuffle index #0 is out of bounds (limit 4) | ||
--> $DIR/shuffle-not-out-of-bounds.rs:163:21 | ||
| | ||
LL | $y(vec1, vec2, ARR) | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | test_shuffle_lanes!(2, u8x2, simd_shuffle2, (2, 1)); | ||
| ---------------------------------------------------- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: shuffle index #0 is out of bounds (limit 8) | ||
--> $DIR/shuffle-not-out-of-bounds.rs:163:21 | ||
| | ||
LL | $y(vec1, vec2, ARR) | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | test_shuffle_lanes!(4, u8x4, simd_shuffle4, (4, 3, 2, 1)); | ||
| ---------------------------------------------------------- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: shuffle index #0 is out of bounds (limit 16) | ||
--> $DIR/shuffle-not-out-of-bounds.rs:163:21 | ||
| | ||
LL | $y(vec1, vec2, ARR) | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | test_shuffle_lanes!(8, u8x8, simd_shuffle8, (8, 7, 6, 5, 4, 3, 2, 1)); | ||
| ---------------------------------------------------------------------- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0511]: invalid monomorphization of `simd_shuffle16` intrinsic: shuffle index #0 is out of bounds (limit 32) | ||
--> $DIR/shuffle-not-out-of-bounds.rs:163:21 | ||
| | ||
LL | $y(vec1, vec2, ARR) | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | / test_shuffle_lanes!(16, u8x16, simd_shuffle16, | ||
LL | | (16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)); | ||
| |_________________________________________________________________- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0511]: invalid monomorphization of `simd_shuffle32` intrinsic: shuffle index #0 is out of bounds (limit 64) | ||
--> $DIR/shuffle-not-out-of-bounds.rs:163:21 | ||
| | ||
LL | $y(vec1, vec2, ARR) | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | / test_shuffle_lanes!(32, u8x32, simd_shuffle32, | ||
LL | | (32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, | ||
LL | | 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)); | ||
| |_____________________________________________________________- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0511]: invalid monomorphization of `simd_shuffle64` intrinsic: shuffle index #0 is out of bounds (limit 128) | ||
--> $DIR/shuffle-not-out-of-bounds.rs:163:21 | ||
| | ||
LL | $y(vec1, vec2, ARR) | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | / test_shuffle_lanes!(64, u8x64, simd_shuffle64, | ||
LL | | (64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, | ||
LL | | 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, | ||
LL | | 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, | ||
LL | | 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)); | ||
| |_________________________________________________________________- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0511`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.