Skip to content

Commit 47e6db5

Browse files
folkertdevAmanieu
authored andcommitted
separate test file for invalid const operand
1 parent b73077e commit 47e6db5

6 files changed

+155
-143
lines changed

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

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//@ needs-asm-support
2+
//@ ignore-nvptx64
3+
//@ ignore-spirv
4+
5+
#![feature(asm_const)]
6+
7+
use std::arch::{asm, global_asm};
8+
9+
// Const operands must be integers and must be constants.
10+
11+
global_asm!("{}", const 0);
12+
global_asm!("{}", const 0i32);
13+
global_asm!("{}", const 0i128);
14+
global_asm!("{}", const 0f32);
15+
//~^ ERROR invalid type for `const` operand
16+
global_asm!("{}", const 0 as *mut u8);
17+
//~^ ERROR invalid type for `const` operand
18+
19+
fn main() {
20+
unsafe {
21+
// Const operands must be integers and must be constants.
22+
23+
asm!("{}", const 0);
24+
asm!("{}", const 0i32);
25+
asm!("{}", const 0i128);
26+
asm!("{}", const 0f32);
27+
//~^ ERROR invalid type for `const` operand
28+
asm!("{}", const 0 as *mut u8);
29+
//~^ ERROR invalid type for `const` operand
30+
asm!("{}", const &0);
31+
//~^ ERROR invalid type for `const` operand
32+
33+
// Constants must be... constant
34+
35+
let x = 0;
36+
const fn const_foo(x: i32) -> i32 {
37+
x
38+
}
39+
const fn const_bar<T>(x: T) -> T {
40+
x
41+
}
42+
asm!("{}", const x);
43+
//~^ ERROR attempt to use a non-constant value in a constant
44+
asm!("{}", const const_foo(0));
45+
asm!("{}", const const_foo(x));
46+
//~^ ERROR attempt to use a non-constant value in a constant
47+
asm!("{}", const const_bar(0));
48+
asm!("{}", const const_bar(x));
49+
//~^ ERROR attempt to use a non-constant value in a constant
50+
}
51+
}
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
error[E0435]: attempt to use a non-constant value in a constant
2+
--> $DIR/invalid-const-operand.rs:42:26
3+
|
4+
LL | asm!("{}", const x);
5+
| ^ non-constant value
6+
|
7+
help: consider using `const` instead of `let`
8+
|
9+
LL | const x: /* Type */ = 0;
10+
| ~~~~~ ++++++++++++
11+
12+
error[E0435]: attempt to use a non-constant value in a constant
13+
--> $DIR/invalid-const-operand.rs:45:36
14+
|
15+
LL | asm!("{}", const const_foo(x));
16+
| ^ non-constant value
17+
|
18+
help: consider using `const` instead of `let`
19+
|
20+
LL | const x: /* Type */ = 0;
21+
| ~~~~~ ++++++++++++
22+
23+
error[E0435]: attempt to use a non-constant value in a constant
24+
--> $DIR/invalid-const-operand.rs:48:36
25+
|
26+
LL | asm!("{}", const const_bar(x));
27+
| ^ non-constant value
28+
|
29+
help: consider using `const` instead of `let`
30+
|
31+
LL | const x: /* Type */ = 0;
32+
| ~~~~~ ++++++++++++
33+
34+
error: invalid type for `const` operand
35+
--> $DIR/invalid-const-operand.rs:14:19
36+
|
37+
LL | global_asm!("{}", const 0f32);
38+
| ^^^^^^----
39+
| |
40+
| is an `f32`
41+
|
42+
= help: `const` operands must be of an integer type
43+
44+
error: invalid type for `const` operand
45+
--> $DIR/invalid-const-operand.rs:16:19
46+
|
47+
LL | global_asm!("{}", const 0 as *mut u8);
48+
| ^^^^^^------------
49+
| |
50+
| is a `*mut u8`
51+
|
52+
= help: `const` operands must be of an integer type
53+
54+
error: invalid type for `const` operand
55+
--> $DIR/invalid-const-operand.rs:26:20
56+
|
57+
LL | asm!("{}", const 0f32);
58+
| ^^^^^^----
59+
| |
60+
| is an `f32`
61+
|
62+
= help: `const` operands must be of an integer type
63+
64+
error: invalid type for `const` operand
65+
--> $DIR/invalid-const-operand.rs:28:20
66+
|
67+
LL | asm!("{}", const 0 as *mut u8);
68+
| ^^^^^^------------
69+
| |
70+
| is a `*mut u8`
71+
|
72+
= help: `const` operands must be of an integer type
73+
74+
error: invalid type for `const` operand
75+
--> $DIR/invalid-const-operand.rs:30:20
76+
|
77+
LL | asm!("{}", const &0);
78+
| ^^^^^^--
79+
| |
80+
| is a `&i32`
81+
|
82+
= help: `const` operands must be of an integer type
83+
84+
error: aborting due to 8 previous errors
85+
86+
For more information about this error, try `rustc --explain E0435`.

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
use std::arch::{asm, global_asm};
22

3+
// Sym operands must point to a function or static
4+
5+
const C: i32 = 0;
6+
static S: i32 = 0;
7+
global_asm!("{}", sym S);
8+
global_asm!("{}", sym main);
9+
global_asm!("{}", sym C);
10+
//~^ ERROR invalid `sym` operand
11+
312
fn main() {
413
unsafe {
514
// Sym operands must point to a function or static
@@ -19,12 +28,3 @@ fn main() {
1928
unsafe fn generic<T>() {
2029
asm!("{}", sym generic::<T>);
2130
}
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

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
error: invalid `sym` operand
2-
--> $DIR/invalid-sym-operand.rs:14:24
2+
--> $DIR/invalid-sym-operand.rs:23:24
33
|
44
LL | asm!("{}", sym x);
55
| ^ is a local variable
66
|
77
= help: `sym` operands must refer to either a function or a static
88

99
error: invalid `sym` operand
10-
--> $DIR/invalid-sym-operand.rs:12:20
10+
--> $DIR/invalid-sym-operand.rs:9:19
1111
|
12-
LL | asm!("{}", sym C);
13-
| ^^^^^ is an `i32`
12+
LL | global_asm!("{}", sym C);
13+
| ^^^^^ is an `i32`
1414
|
1515
= help: `sym` operands must refer to either a function or a static
1616

1717
error: invalid `sym` operand
18-
--> $DIR/invalid-sym-operand.rs:29:19
18+
--> $DIR/invalid-sym-operand.rs:21:20
1919
|
20-
LL | global_asm!("{}", sym C);
21-
| ^^^^^ is an `i32`
20+
LL | asm!("{}", sym C);
21+
| ^^^^^ is an `i32`
2222
|
2323
= help: `sym` operands must refer to either a function or a static
2424

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

-41
Original file line numberDiff line numberDiff line change
@@ -28,46 +28,5 @@ fn main() {
2828
asm!("{}", inout(reg) v[..]);
2929
//~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
3030
//~| ERROR cannot use value of type `[u64]` for inline assembly
31-
32-
// Constants must be... constant
33-
34-
let x = 0;
35-
const fn const_foo(x: i32) -> i32 {
36-
x
37-
}
38-
const fn const_bar<T>(x: T) -> T {
39-
x
40-
}
41-
asm!("{}", const x);
42-
//~^ ERROR attempt to use a non-constant value in a constant
43-
asm!("{}", const const_foo(0));
44-
asm!("{}", const const_foo(x));
45-
//~^ ERROR attempt to use a non-constant value in a constant
46-
asm!("{}", const const_bar(0));
47-
asm!("{}", const const_bar(x));
48-
//~^ ERROR attempt to use a non-constant value in a constant
49-
50-
// Const operands must be integers and must be constants.
51-
52-
asm!("{}", const 0);
53-
asm!("{}", const 0i32);
54-
asm!("{}", const 0i128);
55-
asm!("{}", const 0f32);
56-
//~^ ERROR invalid type for `const` operand
57-
asm!("{}", const 0 as *mut u8);
58-
//~^ ERROR invalid type for `const` operand
59-
60-
asm!("{}", const &0);
61-
//~^ ERROR invalid type for `const` operand
6231
}
6332
}
64-
65-
// Const operands must be integers and must be constants.
66-
67-
global_asm!("{}", const 0);
68-
global_asm!("{}", const 0i32);
69-
global_asm!("{}", const 0i128);
70-
global_asm!("{}", const 0f32);
71-
//~^ ERROR invalid type for `const` operand
72-
global_asm!("{}", const 0 as *mut u8);
73-
//~^ ERROR invalid type for `const` operand

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

+2-86
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,3 @@
1-
error[E0435]: attempt to use a non-constant value in a constant
2-
--> $DIR/type-check-1.rs:41:26
3-
|
4-
LL | asm!("{}", const x);
5-
| ^ non-constant value
6-
|
7-
help: consider using `const` instead of `let`
8-
|
9-
LL | const x: /* Type */ = 0;
10-
| ~~~~~ ++++++++++++
11-
12-
error[E0435]: attempt to use a non-constant value in a constant
13-
--> $DIR/type-check-1.rs:44:36
14-
|
15-
LL | asm!("{}", const const_foo(x));
16-
| ^ non-constant value
17-
|
18-
help: consider using `const` instead of `let`
19-
|
20-
LL | const x: /* Type */ = 0;
21-
| ~~~~~ ++++++++++++
22-
23-
error[E0435]: attempt to use a non-constant value in a constant
24-
--> $DIR/type-check-1.rs:47:36
25-
|
26-
LL | asm!("{}", const const_bar(x));
27-
| ^ non-constant value
28-
|
29-
help: consider using `const` instead of `let`
30-
|
31-
LL | const x: /* Type */ = 0;
32-
| ~~~~~ ++++++++++++
33-
341
error: invalid asm output
352
--> $DIR/type-check-1.rs:14:29
363
|
@@ -94,57 +61,6 @@ LL | asm!("{}", inout(reg) v[..]);
9461
|
9562
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
9663

97-
error: invalid type for `const` operand
98-
--> $DIR/type-check-1.rs:55:20
99-
|
100-
LL | asm!("{}", const 0f32);
101-
| ^^^^^^----
102-
| |
103-
| is an `f32`
104-
|
105-
= help: `const` operands must be of an integer type
106-
107-
error: invalid type for `const` operand
108-
--> $DIR/type-check-1.rs:57:20
109-
|
110-
LL | asm!("{}", const 0 as *mut u8);
111-
| ^^^^^^------------
112-
| |
113-
| is a `*mut u8`
114-
|
115-
= help: `const` operands must be of an integer type
116-
117-
error: invalid type for `const` operand
118-
--> $DIR/type-check-1.rs:60:20
119-
|
120-
LL | asm!("{}", const &0);
121-
| ^^^^^^--
122-
| |
123-
| is a `&i32`
124-
|
125-
= help: `const` operands must be of an integer type
126-
127-
error: invalid type for `const` operand
128-
--> $DIR/type-check-1.rs:70:19
129-
|
130-
LL | global_asm!("{}", const 0f32);
131-
| ^^^^^^----
132-
| |
133-
| is an `f32`
134-
|
135-
= help: `const` operands must be of an integer type
136-
137-
error: invalid type for `const` operand
138-
--> $DIR/type-check-1.rs:72:19
139-
|
140-
LL | global_asm!("{}", const 0 as *mut u8);
141-
| ^^^^^^------------
142-
| |
143-
| is a `*mut u8`
144-
|
145-
= help: `const` operands must be of an integer type
146-
147-
error: aborting due to 16 previous errors
64+
error: aborting due to 8 previous errors
14865

149-
Some errors have detailed explanations: E0277, E0435.
150-
For more information about an error, try `rustc --explain E0277`.
66+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)