Skip to content

Commit 3a6f269

Browse files
committed
improve error message and testing of using an unsigned simd mask
1 parent 002da76 commit 3a6f269

File tree

6 files changed

+102
-5
lines changed

6 files changed

+102
-5
lines changed

Diff for: compiler/rustc_codegen_ssa/messages.ftl

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ codegen_ssa_invalid_monomorphization_inserted_type = invalid monomorphization of
119119
120120
codegen_ssa_invalid_monomorphization_invalid_bitmask = invalid monomorphization of `{$name}` intrinsic: invalid bitmask `{$mask_ty}`, expected `u{$expected_int_bits}` or `[u8; {$expected_bytes}]`
121121
122-
codegen_ssa_invalid_monomorphization_mask_type = invalid monomorphization of `{$name}` intrinsic: mask element type is `{$ty}`, expected `i_`
122+
codegen_ssa_invalid_monomorphization_mask_type = invalid monomorphization of `{$name}` intrinsic: found mask element type is `{$ty}`, expected a signed integer type
123+
.note = the mask may be widened, which only has the correct behavior for signed integers
123124
124125
codegen_ssa_invalid_monomorphization_mismatched_lengths = invalid monomorphization of `{$name}` intrinsic: mismatched lengths: mask length `{$m_len}` != other vector length `{$v_len}`
125126

Diff for: compiler/rustc_codegen_ssa/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ pub enum InvalidMonomorphization<'tcx> {
957957
},
958958

959959
#[diag(codegen_ssa_invalid_monomorphization_mask_type, code = E0511)]
960+
#[note]
960961
MaskType {
961962
#[primary_span]
962963
span: Span,

Diff for: tests/ui/simd/intrinsic/generic-gather.rs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//@ build-fail
2+
//@ ignore-emscripten
3+
4+
// Test that the simd_{gather,scatter} intrinsics produce ok-ish error
5+
// messages when misused.
6+
7+
#![feature(repr_simd, core_intrinsics)]
8+
#![allow(non_camel_case_types)]
9+
10+
use std::intrinsics::simd::{simd_gather, simd_scatter};
11+
12+
#[repr(simd)]
13+
#[derive(Copy, Clone, PartialEq, Debug)]
14+
struct x4<T>(pub [T; 4]);
15+
16+
fn main() {
17+
let mut x = [0_f32, 1., 2., 3., 4., 5., 6., 7.];
18+
19+
let default = x4([-3_f32, -3., -3., -3.]);
20+
let s_strided = x4([0_f32, 2., -3., 6.]);
21+
22+
let mask = x4([-1_i32, -1, 0, -1]);
23+
let umask = x4([0u16; 4]);
24+
let fmask = x4([0_f32; 4]);
25+
26+
let pointer = x.as_mut_ptr();
27+
let pointers =
28+
unsafe { x4([pointer.offset(0), pointer.offset(2), pointer.offset(4), pointer.offset(6)]) };
29+
30+
unsafe {
31+
simd_gather(default, mask, mask);
32+
//~^ ERROR expected element type `i32` of second argument `x4<i32>` to be a pointer to the element type `f32`
33+
34+
simd_gather(default, pointers, umask);
35+
//~^ ERROR expected element type `u16` of third argument `x4<u16>` to be a signed integer type
36+
37+
simd_gather(default, pointers, fmask);
38+
//~^ ERROR expected element type `f32` of third argument `x4<f32>` to be a signed integer type
39+
}
40+
41+
unsafe {
42+
let values = x4([42_f32, 43_f32, 44_f32, 45_f32]);
43+
simd_scatter(values, mask, mask);
44+
//~^ ERROR expected element type `i32` of second argument `x4<i32>` to be a pointer to the element type `f32` of the first argument `x4<f32>`, found `i32` != `*mut f32`
45+
46+
simd_scatter(values, pointers, umask);
47+
//~^ ERROR expected element type `u16` of third argument `x4<u16>` to be a signed integer type
48+
49+
simd_scatter(values, pointers, fmask);
50+
//~^ ERROR expected element type `f32` of third argument `x4<f32>` to be a signed integer type
51+
}
52+
}

Diff for: tests/ui/simd/intrinsic/generic-gather.stderr

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0511]: invalid monomorphization of `simd_gather` intrinsic: expected element type `i32` of second argument `x4<i32>` to be a pointer to the element type `f32` of the first argument `x4<f32>`, found `i32` != `*_ f32`
2+
--> $DIR/generic-gather.rs:31:9
3+
|
4+
LL | simd_gather(default, mask, mask);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error[E0511]: invalid monomorphization of `simd_gather` intrinsic: expected element type `u16` of third argument `x4<u16>` to be a signed integer type
8+
--> $DIR/generic-gather.rs:34:9
9+
|
10+
LL | simd_gather(default, pointers, umask);
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error[E0511]: invalid monomorphization of `simd_gather` intrinsic: expected element type `f32` of third argument `x4<f32>` to be a signed integer type
14+
--> $DIR/generic-gather.rs:37:9
15+
|
16+
LL | simd_gather(default, pointers, fmask);
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
error[E0511]: invalid monomorphization of `simd_scatter` intrinsic: expected element type `i32` of second argument `x4<i32>` to be a pointer to the element type `f32` of the first argument `x4<f32>`, found `i32` != `*mut f32`
20+
--> $DIR/generic-gather.rs:43:9
21+
|
22+
LL | simd_scatter(values, mask, mask);
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error[E0511]: invalid monomorphization of `simd_scatter` intrinsic: expected element type `u16` of third argument `x4<u16>` to be a signed integer type
26+
--> $DIR/generic-gather.rs:46:9
27+
|
28+
LL | simd_scatter(values, pointers, umask);
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
31+
error[E0511]: invalid monomorphization of `simd_scatter` intrinsic: expected element type `f32` of third argument `x4<f32>` to be a signed integer type
32+
--> $DIR/generic-gather.rs:49:9
33+
|
34+
LL | simd_scatter(values, pointers, fmask);
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
38+
39+
For more information about this error, try `rustc --explain E0511`.

Diff for: tests/ui/simd/intrinsic/generic-select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ fn main() {
3737
//~^ ERROR mismatched lengths: mask length `8` != other vector length `4`
3838

3939
simd_select(x, x, x);
40-
//~^ ERROR mask element type is `u32`, expected `i_`
40+
//~^ ERROR mask element type is `u32`, expected a signed integer type
4141

4242
simd_select(z, z, z);
43-
//~^ ERROR mask element type is `f32`, expected `i_`
43+
//~^ ERROR mask element type is `f32`, expected a signed integer type
4444

4545
simd_select(m4, 0u32, 1u32);
4646
//~^ ERROR found non-SIMD `u32`

Diff for: tests/ui/simd/intrinsic/generic-select.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ error[E0511]: invalid monomorphization of `simd_select` intrinsic: mismatched le
44
LL | simd_select(m8, x, x);
55
| ^^^^^^^^^^^^^^^^^^^^^
66

7-
error[E0511]: invalid monomorphization of `simd_select` intrinsic: mask element type is `u32`, expected `i_`
7+
error[E0511]: invalid monomorphization of `simd_select` intrinsic: found mask element type is `u32`, expected a signed integer type
88
--> $DIR/generic-select.rs:39:9
99
|
1010
LL | simd_select(x, x, x);
1111
| ^^^^^^^^^^^^^^^^^^^^
12+
|
13+
= note: the mask may be widened, which only has the correct behavior for signed integers
1214

13-
error[E0511]: invalid monomorphization of `simd_select` intrinsic: mask element type is `f32`, expected `i_`
15+
error[E0511]: invalid monomorphization of `simd_select` intrinsic: found mask element type is `f32`, expected a signed integer type
1416
--> $DIR/generic-select.rs:42:9
1517
|
1618
LL | simd_select(z, z, z);
1719
| ^^^^^^^^^^^^^^^^^^^^
20+
|
21+
= note: the mask may be widened, which only has the correct behavior for signed integers
1822

1923
error[E0511]: invalid monomorphization of `simd_select` intrinsic: expected SIMD argument type, found non-SIMD `u32`
2024
--> $DIR/generic-select.rs:45:9

0 commit comments

Comments
 (0)