Skip to content

Commit 08c8887

Browse files
committed
separate test file for invalid const operand
1 parent 74f711e commit 08c8887

File tree

4 files changed

+87
-127
lines changed

4 files changed

+87
-127
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
fn main() {
10+
unsafe {
11+
// Const operands must be integers and must be constants.
12+
13+
asm!("{}", const 0);
14+
asm!("{}", const 0i32);
15+
asm!("{}", const 0i128);
16+
asm!("{}", const 0f32);
17+
//~^ ERROR invalid type for `const` operand
18+
asm!("{}", const 0 as *mut u8);
19+
//~^ ERROR invalid type for `const` operand
20+
asm!("{}", const &0);
21+
//~^ ERROR invalid type for `const` operand
22+
}
23+
}
24+
25+
// Const operands must be integers and must be constants.
26+
27+
global_asm!("{}", const 0);
28+
global_asm!("{}", const 0i32);
29+
global_asm!("{}", const 0i128);
30+
global_asm!("{}", const 0f32);
31+
//~^ ERROR invalid type for `const` operand
32+
global_asm!("{}", const 0 as *mut u8);
33+
//~^ ERROR invalid type for `const` operand
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error: invalid type for `const` operand
2+
--> $DIR/invalid-const-operand.rs:16:20
3+
|
4+
LL | asm!("{}", const 0f32);
5+
| ^^^^^^----
6+
| |
7+
| is an `f32`
8+
|
9+
= help: `const` operands must be of an integer type
10+
11+
error: invalid type for `const` operand
12+
--> $DIR/invalid-const-operand.rs:18:20
13+
|
14+
LL | asm!("{}", const 0 as *mut u8);
15+
| ^^^^^^------------
16+
| |
17+
| is a `*mut u8`
18+
|
19+
= help: `const` operands must be of an integer type
20+
21+
error: invalid type for `const` operand
22+
--> $DIR/invalid-const-operand.rs:20:20
23+
|
24+
LL | asm!("{}", const &0);
25+
| ^^^^^^--
26+
| |
27+
| is a `&i32`
28+
|
29+
= help: `const` operands must be of an integer type
30+
31+
error: invalid type for `const` operand
32+
--> $DIR/invalid-const-operand.rs:30:19
33+
|
34+
LL | global_asm!("{}", const 0f32);
35+
| ^^^^^^----
36+
| |
37+
| is an `f32`
38+
|
39+
= help: `const` operands must be of an integer type
40+
41+
error: invalid type for `const` operand
42+
--> $DIR/invalid-const-operand.rs:32:19
43+
|
44+
LL | global_asm!("{}", const 0 as *mut u8);
45+
| ^^^^^^------------
46+
| |
47+
| is a `*mut u8`
48+
|
49+
= help: `const` operands must be of an integer type
50+
51+
error: aborting due to 5 previous errors
52+

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

Lines changed: 0 additions & 41 deletions
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

Lines changed: 2 additions & 86 deletions
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)