Skip to content

Commit 9d7f9d0

Browse files
committed
Add float testing and testing for wrapped arrays
1 parent b44f6db commit 9d7f9d0

6 files changed

+140
-44
lines changed

compiler/rustc_passes/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,8 @@ passes_rustc_intrinsic_const_vector_arg =
615615
616616
passes_rustc_intrinsic_const_vector_arg_invalid = attribute requires a parameter index
617617
618-
passes_rustc_intrinsic_const_vector_arg_non_vector = parameter at index {$index} must be a simd type
619-
.label = parameter is a non-simd type
618+
passes_rustc_intrinsic_const_vector_arg_non_vector = parameter at index {$index} must be a simd type defined in the local crate
619+
.label = parameter is a non-simd type or is not defined locally
620620
621621
passes_rustc_intrinsic_const_vector_arg_out_of_bounds = function does not have a parameter at index {$index}
622622
.label = function has {$arg_count} arguments

compiler/rustc_passes/src/check_attr.rs

+36-10
Original file line numberDiff line numberDiff line change
@@ -2134,18 +2134,44 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
21342134
return false;
21352135
}
21362136

2137-
let param_ty = decl.inputs[*val as usize];
2138-
let type_id: Option<DefId> = match param_ty.kind {
2139-
TyKind::Path(path) => match path {
2140-
QPath::Resolved(_, Path { res: Res::Def(_, id), .. }) => Some(*id),
2141-
QPath::TypeRelative(_, PathSegment { res: Res::Def(_, id), .. }) => {
2142-
Some(*id)
2143-
}
2137+
fn get_type_def(tcx: TyCtxt<'_>, param_ty: rustc_hir::Ty<'_>) -> Option<DefId> {
2138+
let type_id: Option<DefId> = match param_ty.kind {
2139+
TyKind::Path(path) => match path {
2140+
QPath::Resolved(_, Path { res: Res::Def(_, id), .. })
2141+
| QPath::TypeRelative(
2142+
_,
2143+
PathSegment { res: Res::Def(_, id), .. },
2144+
)
2145+
| QPath::Resolved(
2146+
_,
2147+
Path { res: Res::SelfTyAlias { alias_to: id, .. }, .. },
2148+
)
2149+
| QPath::TypeRelative(
2150+
_,
2151+
PathSegment {
2152+
res: Res::SelfTyAlias { alias_to: id, .. }, ..
2153+
},
2154+
) => Some(*id),
2155+
_ => None,
2156+
},
21442157
_ => None,
2145-
},
2146-
_ => None,
2147-
};
2158+
};
2159+
if let Some(type_id) = type_id
2160+
&& let Some(did) = type_id.as_local()
2161+
{
2162+
if let Some(param_ty) =
2163+
tcx.hir_node(tcx.local_def_id_to_hir_id(did)).ty()
2164+
{
2165+
return get_type_def(tcx, *param_ty);
2166+
} else {
2167+
return Some(type_id);
2168+
}
2169+
}
2170+
None
2171+
}
21482172

2173+
let param_ty = decl.inputs[*val as usize];
2174+
let type_id = get_type_def(self.tcx, param_ty);
21492175
let is_simd = if let Some(type_id) = type_id {
21502176
self.tcx
21512177
.get_attrs(type_id, sym::repr)

tests/ui/internal-lints/rustc_intrinsic_const_vector_arg.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
#![feature(inline_const)]
44
#![feature(intrinsics)]
55
#![allow(non_camel_case_types)]
6+
#![feature(portable_simd)]
67
#![feature(repr_simd)]
78
#![feature(rustc_attrs)]
89
#![feature(simd_ffi)]
910
#![allow(unused)]
1011

12+
use std::simd::prelude::Simd;
13+
1114
#[repr(simd)]
1215
#[derive(Clone)]
1316
pub struct i8x2(i8, i8);
@@ -46,13 +49,18 @@ extern "unadjusted" {
4649
}
4750

4851
extern "unadjusted" {
49-
#[rustc_intrinsic_const_vector_arg(0,2)] //~ ERROR function does not have a parameter at index 2
52+
#[rustc_intrinsic_const_vector_arg(0, 2)] //~ ERROR function does not have a parameter at index 2
5053
fn foo8(a: i8x2, b: i8);
5154
}
5255

5356
extern "unadjusted" {
54-
#[rustc_intrinsic_const_vector_arg(0)] //~ ERROR parameter at index 0 must be a simd type
57+
#[rustc_intrinsic_const_vector_arg(0)] //~ ERROR parameter at index 0 must be a simd type defined in the local crate
5558
fn foo9(a: i8);
5659
}
5760

61+
extern "unadjusted" {
62+
#[rustc_intrinsic_const_vector_arg(0)] //~ ERROR parameter at index 0 must be a simd type defined in the local crate
63+
fn foo10(a: Simd<i8, 2>);
64+
}
65+
5866
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,76 @@
11
error: malformed `rustc_intrinsic_const_vector_arg` attribute input
2-
--> $DIR/rustc_intrinsic_const_vector_arg.rs:16:5
2+
--> $DIR/rustc_intrinsic_const_vector_arg.rs:19:5
33
|
44
LL | #[rustc_intrinsic_const_vector_arg]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_intrinsic_const_vector_arg(arg1_index, arg2_index, ...)]`
66

77
error: malformed `rustc_intrinsic_const_vector_arg` attribute input
8-
--> $DIR/rustc_intrinsic_const_vector_arg.rs:21:5
8+
--> $DIR/rustc_intrinsic_const_vector_arg.rs:24:5
99
|
1010
LL | #[rustc_intrinsic_const_vector_arg = "1"]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_intrinsic_const_vector_arg(arg1_index, arg2_index, ...)]`
1212

1313
error: attribute should be applied to functions in `extern "unadjusted"` modules
14-
--> $DIR/rustc_intrinsic_const_vector_arg.rs:25:1
14+
--> $DIR/rustc_intrinsic_const_vector_arg.rs:28:1
1515
|
1616
LL | #[rustc_intrinsic_const_vector_arg(0)]
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818
LL | pub struct foo3(i8x2);
1919
| ---------------------- not a function in an `extern "unadjusted"` module
2020

2121
error: attribute should be applied to functions in `extern "unadjusted"` modules
22-
--> $DIR/rustc_intrinsic_const_vector_arg.rs:29:5
22+
--> $DIR/rustc_intrinsic_const_vector_arg.rs:32:5
2323
|
2424
LL | #[rustc_intrinsic_const_vector_arg(0)]
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626
LL | fn foo4(a: i8x2);
2727
| ----------------- not a function in an `extern "unadjusted"` module
2828

2929
error: function does not have a parameter at index 0
30-
--> $DIR/rustc_intrinsic_const_vector_arg.rs:34:5
30+
--> $DIR/rustc_intrinsic_const_vector_arg.rs:37:5
3131
|
3232
LL | #[rustc_intrinsic_const_vector_arg(0)]
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
LL | fn foo5();
3535
| ---------- function has 0 arguments
3636

3737
error: function does not have a parameter at index 1
38-
--> $DIR/rustc_intrinsic_const_vector_arg.rs:39:5
38+
--> $DIR/rustc_intrinsic_const_vector_arg.rs:42:5
3939
|
4040
LL | #[rustc_intrinsic_const_vector_arg(1)]
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4242
LL | fn foo6(a: i8x2);
4343
| ----------------- function has 1 arguments
4444

4545
error: attribute requires a parameter index
46-
--> $DIR/rustc_intrinsic_const_vector_arg.rs:44:40
46+
--> $DIR/rustc_intrinsic_const_vector_arg.rs:47:40
4747
|
4848
LL | #[rustc_intrinsic_const_vector_arg("bar")]
4949
| ^^^^^
5050

5151
error: function does not have a parameter at index 2
52-
--> $DIR/rustc_intrinsic_const_vector_arg.rs:49:5
52+
--> $DIR/rustc_intrinsic_const_vector_arg.rs:52:5
5353
|
54-
LL | #[rustc_intrinsic_const_vector_arg(0,2)]
55-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
LL | #[rustc_intrinsic_const_vector_arg(0, 2)]
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5656
LL | fn foo8(a: i8x2, b: i8);
5757
| ------------------------ function has 2 arguments
5858

59-
error: parameter at index 0 must be a simd type
60-
--> $DIR/rustc_intrinsic_const_vector_arg.rs:54:5
59+
error: parameter at index 0 must be a simd type defined in the local crate
60+
--> $DIR/rustc_intrinsic_const_vector_arg.rs:57:5
6161
|
6262
LL | #[rustc_intrinsic_const_vector_arg(0)]
6363
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6464
LL | fn foo9(a: i8);
65-
| -- parameter is a non-simd type
65+
| -- parameter is a non-simd type or is not defined locally
6666

67-
error: aborting due to 9 previous errors
67+
error: parameter at index 0 must be a simd type defined in the local crate
68+
--> $DIR/rustc_intrinsic_const_vector_arg.rs:62:5
69+
|
70+
LL | #[rustc_intrinsic_const_vector_arg(0)]
71+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
72+
LL | fn foo10(a: Simd<i8, 2>);
73+
| ----------- parameter is a non-simd type or is not defined locally
74+
75+
error: aborting due to 10 previous errors
6876

tests/ui/internal-lints/rustc_intrinsic_const_vector_arg_calls.rs

+42-6
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,59 @@
1212
#[derive(Clone)]
1313
pub struct i8x2(i8, i8);
1414

15+
#[repr(simd)]
16+
#[derive(Clone)]
17+
pub struct f32x2(f32, f32);
18+
19+
#[repr(simd)]
20+
#[derive(Clone)]
21+
pub struct i8x2_arr([i8; 2]);
22+
23+
#[repr(simd)]
24+
#[derive(Clone)]
25+
pub struct f32x2_arr([f32; 2]);
26+
1527
extern "unadjusted" {
1628
#[rustc_intrinsic_const_vector_arg(0)] // OK
1729
fn foo1(a: i8x2);
1830
}
1931

2032
extern "unadjusted" {
21-
#[rustc_intrinsic_const_vector_arg(0,1)] // OK
33+
#[rustc_intrinsic_const_vector_arg(0, 1)] // OK
2234
fn foo2(a: i8x2, b: i8x2);
2335
}
2436

37+
extern "unadjusted" {
38+
#[rustc_intrinsic_const_vector_arg(0)] // OK
39+
fn foo3(a: i8x2_arr);
40+
}
41+
42+
extern "unadjusted" {
43+
#[rustc_intrinsic_const_vector_arg(0)] // OK
44+
fn foo4(a: f32x2);
45+
}
46+
47+
extern "unadjusted" {
48+
#[rustc_intrinsic_const_vector_arg(0)] // OK
49+
fn foo5(a: f32x2_arr);
50+
}
51+
2552
fn main() {
2653
unsafe {
27-
foo1(i8x2(0,1)); //~ ERROR argument at index 0 must be a constant
28-
foo1({ i8x2(0,1) }); //~ ERROR argument at index 0 must be a constant
29-
foo1(const { i8x2(0,1) }); // OK
54+
foo1(i8x2(0, 1)); //~ ERROR argument at index 0 must be a constant
55+
foo1({ i8x2(0, 1) }); //~ ERROR argument at index 0 must be a constant
56+
foo1(const { i8x2(0, 1) }); // OK
57+
58+
foo2(const { i8x2(0, 1) }, { i8x2(2, 3) }); //~ ERROR argument at index 1 must be a constant
59+
foo2(const { i8x2(0, 1) }, const { i8x2(2, 3) }); // OK
60+
61+
foo3(i8x2_arr([0, 1])); //~ ERROR argument at index 0 must be a constant
62+
foo3(const { i8x2_arr([0, 1]) }); // OK
63+
64+
foo4(f32x2(0.0, 1.0)); //~ ERROR argument at index 0 must be a constant
65+
foo4(const { f32x2(0.0, 1.0) }); // OK
3066

31-
foo2(const { i8x2(0,1) }, { i8x2(2,3) }); //~ ERROR argument at index 1 must be a constant
32-
foo2(const { i8x2(0,1) }, const { i8x2(2,3) }); // OK
67+
foo5(f32x2_arr([0.0, 1.0])); //~ ERROR argument at index 0 must be a constant
68+
foo5(const { f32x2_arr([0.0, 1.0]) }); // OK
3369
}
3470
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
error: argument at index 0 must be a constant
2-
--> $DIR/rustc_intrinsic_const_vector_arg_calls.rs:27:9
2+
--> $DIR/rustc_intrinsic_const_vector_arg_calls.rs:54:9
33
|
4-
LL | foo1(i8x2(0,1));
5-
| ^^^^^^^^^^^^^^^
4+
LL | foo1(i8x2(0, 1));
5+
| ^^^^^^^^^^^^^^^^
66

77
error: argument at index 0 must be a constant
8-
--> $DIR/rustc_intrinsic_const_vector_arg_calls.rs:28:9
8+
--> $DIR/rustc_intrinsic_const_vector_arg_calls.rs:55:9
99
|
10-
LL | foo1({ i8x2(0,1) });
11-
| ^^^^^^^^^^^^^^^^^^^
10+
LL | foo1({ i8x2(0, 1) });
11+
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: argument at index 1 must be a constant
14-
--> $DIR/rustc_intrinsic_const_vector_arg_calls.rs:31:9
14+
--> $DIR/rustc_intrinsic_const_vector_arg_calls.rs:58:9
1515
|
16-
LL | foo2(const { i8x2(0,1) }, { i8x2(2,3) });
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
LL | foo2(const { i8x2(0, 1) }, { i8x2(2, 3) });
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

19-
error: aborting due to 3 previous errors
19+
error: argument at index 0 must be a constant
20+
--> $DIR/rustc_intrinsic_const_vector_arg_calls.rs:61:9
21+
|
22+
LL | foo3(i8x2_arr([0, 1]));
23+
| ^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error: argument at index 0 must be a constant
26+
--> $DIR/rustc_intrinsic_const_vector_arg_calls.rs:64:9
27+
|
28+
LL | foo4(f32x2(0.0, 1.0));
29+
| ^^^^^^^^^^^^^^^^^^^^^
30+
31+
error: argument at index 0 must be a constant
32+
--> $DIR/rustc_intrinsic_const_vector_arg_calls.rs:67:9
33+
|
34+
LL | foo5(f32x2_arr([0.0, 1.0]));
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
37+
error: aborting due to 6 previous errors
2038

0 commit comments

Comments
 (0)