Skip to content

Commit b73077e

Browse files
folkertdevAmanieu
authored andcommitted
separate test file for invalid sym operand
1 parent be66415 commit b73077e

8 files changed

+80
-116
lines changed

tests/ui/asm/aarch64/type-check-2.rs

-18
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ fn main() {
1515
unsafe {
1616
// Inputs must be initialized
1717

18-
// Sym operands must point to a function or static
19-
20-
const C: i32 = 0;
21-
static S: i32 = 0;
22-
asm!("{}", sym S);
23-
asm!("{}", sym main);
24-
asm!("{}", sym C);
25-
//~^ ERROR invalid `sym` operand
26-
2718
// Register operands must be Copy
2819

2920
asm!("{:v}", in(vreg) SimdNonCopy(0.0, 0.0, 0.0, 0.0));
@@ -65,12 +56,3 @@ fn main() {
6556
asm!("{}", in(reg) u);
6657
}
6758
}
68-
69-
// Sym operands must point to a function or static
70-
71-
const C: i32 = 0;
72-
static S: i32 = 0;
73-
global_asm!("{}", sym S);
74-
global_asm!("{}", sym main);
75-
global_asm!("{}", sym C);
76-
//~^ ERROR invalid `sym` operand
+9-25
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
1-
error: invalid `sym` operand
2-
--> $DIR/type-check-2.rs:75:19
3-
|
4-
LL | global_asm!("{}", sym C);
5-
| ^^^^^ is an `i32`
6-
|
7-
= help: `sym` operands must refer to either a function or a static
8-
9-
error: invalid `sym` operand
10-
--> $DIR/type-check-2.rs:24:20
11-
|
12-
LL | asm!("{}", sym C);
13-
| ^^^^^ is an `i32`
14-
|
15-
= help: `sym` operands must refer to either a function or a static
16-
171
error: arguments for inline assembly must be copyable
18-
--> $DIR/type-check-2.rs:29:31
2+
--> $DIR/type-check-2.rs:20:31
193
|
204
LL | asm!("{:v}", in(vreg) SimdNonCopy(0.0, 0.0, 0.0, 0.0));
215
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
226
|
237
= note: `SimdNonCopy` does not implement the Copy trait
248

25-
error: cannot use value of type `{closure@$DIR/type-check-2.rs:41:28: 41:36}` for inline assembly
26-
--> $DIR/type-check-2.rs:41:28
9+
error: cannot use value of type `{closure@$DIR/type-check-2.rs:32:28: 32:36}` for inline assembly
10+
--> $DIR/type-check-2.rs:32:28
2711
|
2812
LL | asm!("{}", in(reg) |x: i32| x);
2913
| ^^^^^^^^^^
3014
|
3115
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
3216

3317
error: cannot use value of type `Vec<i32>` for inline assembly
34-
--> $DIR/type-check-2.rs:43:28
18+
--> $DIR/type-check-2.rs:34:28
3519
|
3620
LL | asm!("{}", in(reg) vec![0]);
3721
| ^^^^^^^
@@ -40,36 +24,36 @@ LL | asm!("{}", in(reg) vec![0]);
4024
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
4125

4226
error: cannot use value of type `(i32, i32, i32)` for inline assembly
43-
--> $DIR/type-check-2.rs:45:28
27+
--> $DIR/type-check-2.rs:36:28
4428
|
4529
LL | asm!("{}", in(reg) (1, 2, 3));
4630
| ^^^^^^^^^
4731
|
4832
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
4933

5034
error: cannot use value of type `[i32; 3]` for inline assembly
51-
--> $DIR/type-check-2.rs:47:28
35+
--> $DIR/type-check-2.rs:38:28
5236
|
5337
LL | asm!("{}", in(reg) [1, 2, 3]);
5438
| ^^^^^^^^^
5539
|
5640
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
5741

5842
error: cannot use value of type `fn() {main}` for inline assembly
59-
--> $DIR/type-check-2.rs:55:31
43+
--> $DIR/type-check-2.rs:46:31
6044
|
6145
LL | asm!("{}", inout(reg) f);
6246
| ^
6347
|
6448
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
6549

6650
error: cannot use value of type `&mut i32` for inline assembly
67-
--> $DIR/type-check-2.rs:58:31
51+
--> $DIR/type-check-2.rs:49:31
6852
|
6953
LL | asm!("{}", inout(reg) r);
7054
| ^
7155
|
7256
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
7357

74-
error: aborting due to 9 previous errors
58+
error: aborting due to 7 previous errors
7559

tests/ui/asm/invalid-sym-operand.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::arch::{asm, global_asm};
2+
3+
fn main() {
4+
unsafe {
5+
// Sym operands must point to a function or static
6+
7+
let x: u64 = 0;
8+
const C: i32 = 0;
9+
static S: i32 = 0;
10+
asm!("{}", sym S);
11+
asm!("{}", sym main);
12+
asm!("{}", sym C);
13+
//~^ ERROR invalid `sym` operand
14+
asm!("{}", sym x);
15+
//~^ ERROR invalid `sym` operand
16+
}
17+
}
18+
19+
unsafe fn generic<T>() {
20+
asm!("{}", sym generic::<T>);
21+
}
22+
23+
// Sym operands must point to a function or static
24+
25+
const C: i32 = 0;
26+
static S: i32 = 0;
27+
global_asm!("{}", sym S);
28+
global_asm!("{}", sym main);
29+
global_asm!("{}", sym C);
30+
//~^ ERROR invalid `sym` operand
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: invalid `sym` operand
2+
--> $DIR/invalid-sym-operand.rs:14:24
3+
|
4+
LL | asm!("{}", sym x);
5+
| ^ is a local variable
6+
|
7+
= help: `sym` operands must refer to either a function or a static
8+
9+
error: invalid `sym` operand
10+
--> $DIR/invalid-sym-operand.rs:12:20
11+
|
12+
LL | asm!("{}", sym C);
13+
| ^^^^^ is an `i32`
14+
|
15+
= help: `sym` operands must refer to either a function or a static
16+
17+
error: invalid `sym` operand
18+
--> $DIR/invalid-sym-operand.rs:29:19
19+
|
20+
LL | global_asm!("{}", sym C);
21+
| ^^^^^ is an `i32`
22+
|
23+
= help: `sym` operands must refer to either a function or a static
24+
25+
error: aborting due to 3 previous errors
26+

tests/ui/asm/type-check-1.rs

-6
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ fn main() {
4646
asm!("{}", const const_bar(0));
4747
asm!("{}", const const_bar(x));
4848
//~^ ERROR attempt to use a non-constant value in a constant
49-
asm!("{}", sym x);
50-
//~^ ERROR invalid `sym` operand
5149

5250
// Const operands must be integers and must be constants.
5351

@@ -64,10 +62,6 @@ fn main() {
6462
}
6563
}
6664

67-
unsafe fn generic<T>() {
68-
asm!("{}", sym generic::<T>);
69-
}
70-
7165
// Const operands must be integers and must be constants.
7266

7367
global_asm!("{}", const 0);

tests/ui/asm/type-check-1.stderr

+6-14
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ help: consider using `const` instead of `let`
3131
LL | const x: /* Type */ = 0;
3232
| ~~~~~ ++++++++++++
3333

34-
error: invalid `sym` operand
35-
--> $DIR/type-check-1.rs:49:24
36-
|
37-
LL | asm!("{}", sym x);
38-
| ^ is a local variable
39-
|
40-
= help: `sym` operands must refer to either a function or a static
41-
4234
error: invalid asm output
4335
--> $DIR/type-check-1.rs:14:29
4436
|
@@ -103,7 +95,7 @@ LL | asm!("{}", inout(reg) v[..]);
10395
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
10496

10597
error: invalid type for `const` operand
106-
--> $DIR/type-check-1.rs:57:20
98+
--> $DIR/type-check-1.rs:55:20
10799
|
108100
LL | asm!("{}", const 0f32);
109101
| ^^^^^^----
@@ -113,7 +105,7 @@ LL | asm!("{}", const 0f32);
113105
= help: `const` operands must be of an integer type
114106

115107
error: invalid type for `const` operand
116-
--> $DIR/type-check-1.rs:59:20
108+
--> $DIR/type-check-1.rs:57:20
117109
|
118110
LL | asm!("{}", const 0 as *mut u8);
119111
| ^^^^^^------------
@@ -123,7 +115,7 @@ LL | asm!("{}", const 0 as *mut u8);
123115
= help: `const` operands must be of an integer type
124116

125117
error: invalid type for `const` operand
126-
--> $DIR/type-check-1.rs:62:20
118+
--> $DIR/type-check-1.rs:60:20
127119
|
128120
LL | asm!("{}", const &0);
129121
| ^^^^^^--
@@ -133,7 +125,7 @@ LL | asm!("{}", const &0);
133125
= help: `const` operands must be of an integer type
134126

135127
error: invalid type for `const` operand
136-
--> $DIR/type-check-1.rs:76:19
128+
--> $DIR/type-check-1.rs:70:19
137129
|
138130
LL | global_asm!("{}", const 0f32);
139131
| ^^^^^^----
@@ -143,7 +135,7 @@ LL | global_asm!("{}", const 0f32);
143135
= help: `const` operands must be of an integer type
144136

145137
error: invalid type for `const` operand
146-
--> $DIR/type-check-1.rs:78:19
138+
--> $DIR/type-check-1.rs:72:19
147139
|
148140
LL | global_asm!("{}", const 0 as *mut u8);
149141
| ^^^^^^------------
@@ -152,7 +144,7 @@ LL | global_asm!("{}", const 0 as *mut u8);
152144
|
153145
= help: `const` operands must be of an integer type
154146

155-
error: aborting due to 17 previous errors
147+
error: aborting due to 16 previous errors
156148

157149
Some errors have detailed explanations: E0277, E0435.
158150
For more information about an error, try `rustc --explain E0277`.

tests/ui/asm/x86_64/type-check-2.rs

-20
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ fn main() {
2727
asm!("{}", out(reg) v[0]);
2828
asm!("{}", inout(reg) v[0]);
2929

30-
// Sym operands must point to a function or static
31-
32-
const C: i32 = 0;
33-
static S: i32 = 0;
34-
asm!("{}", sym S);
35-
asm!("{}", sym main);
36-
asm!("{}", sym C);
37-
//~^ ERROR invalid `sym` operand
38-
asm!("{}", sym x);
39-
//~^ ERROR invalid `sym` operand
40-
4130
// Register operands must be Copy
4231

4332
asm!("{}", in(xmm_reg) SimdNonCopy(0.0, 0.0, 0.0, 0.0));
@@ -79,12 +68,3 @@ fn main() {
7968
asm!("{}", in(reg) u);
8069
}
8170
}
82-
83-
// Sym operands must point to a function or static
84-
85-
const C: i32 = 0;
86-
static S: i32 = 0;
87-
global_asm!("{}", sym S);
88-
global_asm!("{}", sym main);
89-
global_asm!("{}", sym C);
90-
//~^ ERROR invalid `sym` operand

tests/ui/asm/x86_64/type-check-2.stderr

+9-33
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
1-
error: invalid `sym` operand
2-
--> $DIR/type-check-2.rs:38:24
3-
|
4-
LL | asm!("{}", sym x);
5-
| ^ is a local variable
6-
|
7-
= help: `sym` operands must refer to either a function or a static
8-
91
error: arguments for inline assembly must be copyable
10-
--> $DIR/type-check-2.rs:43:32
2+
--> $DIR/type-check-2.rs:32:32
113
|
124
LL | asm!("{}", in(xmm_reg) SimdNonCopy(0.0, 0.0, 0.0, 0.0));
135
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146
|
157
= note: `SimdNonCopy` does not implement the Copy trait
168

17-
error: cannot use value of type `{closure@$DIR/type-check-2.rs:55:28: 55:36}` for inline assembly
18-
--> $DIR/type-check-2.rs:55:28
9+
error: cannot use value of type `{closure@$DIR/type-check-2.rs:44:28: 44:36}` for inline assembly
10+
--> $DIR/type-check-2.rs:44:28
1911
|
2012
LL | asm!("{}", in(reg) |x: i32| x);
2113
| ^^^^^^^^^^
2214
|
2315
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
2416

2517
error: cannot use value of type `Vec<i32>` for inline assembly
26-
--> $DIR/type-check-2.rs:57:28
18+
--> $DIR/type-check-2.rs:46:28
2719
|
2820
LL | asm!("{}", in(reg) vec![0]);
2921
| ^^^^^^^
@@ -32,45 +24,37 @@ LL | asm!("{}", in(reg) vec![0]);
3224
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
3325

3426
error: cannot use value of type `(i32, i32, i32)` for inline assembly
35-
--> $DIR/type-check-2.rs:59:28
27+
--> $DIR/type-check-2.rs:48:28
3628
|
3729
LL | asm!("{}", in(reg) (1, 2, 3));
3830
| ^^^^^^^^^
3931
|
4032
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
4133

4234
error: cannot use value of type `[i32; 3]` for inline assembly
43-
--> $DIR/type-check-2.rs:61:28
35+
--> $DIR/type-check-2.rs:50:28
4436
|
4537
LL | asm!("{}", in(reg) [1, 2, 3]);
4638
| ^^^^^^^^^
4739
|
4840
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
4941

5042
error: cannot use value of type `fn() {main}` for inline assembly
51-
--> $DIR/type-check-2.rs:69:31
43+
--> $DIR/type-check-2.rs:58:31
5244
|
5345
LL | asm!("{}", inout(reg) f);
5446
| ^
5547
|
5648
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
5749

5850
error: cannot use value of type `&mut i32` for inline assembly
59-
--> $DIR/type-check-2.rs:72:31
51+
--> $DIR/type-check-2.rs:61:31
6052
|
6153
LL | asm!("{}", inout(reg) r);
6254
| ^
6355
|
6456
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
6557

66-
error: invalid `sym` operand
67-
--> $DIR/type-check-2.rs:36:20
68-
|
69-
LL | asm!("{}", sym C);
70-
| ^^^^^ is an `i32`
71-
|
72-
= help: `sym` operands must refer to either a function or a static
73-
7458
error[E0381]: used binding `x` isn't initialized
7559
--> $DIR/type-check-2.rs:15:28
7660
|
@@ -113,15 +97,7 @@ help: consider changing this to be mutable
11397
LL | let mut v: Vec<u64> = vec![0, 1, 2];
11498
| +++
11599

116-
error: invalid `sym` operand
117-
--> $DIR/type-check-2.rs:89:19
118-
|
119-
LL | global_asm!("{}", sym C);
120-
| ^^^^^ is an `i32`
121-
|
122-
= help: `sym` operands must refer to either a function or a static
123-
124-
error: aborting due to 13 previous errors
100+
error: aborting due to 10 previous errors
125101

126102
Some errors have detailed explanations: E0381, E0596.
127103
For more information about an error, try `rustc --explain E0381`.

0 commit comments

Comments
 (0)