]> git.proxmox.com Git - rustc.git/blob - src/test/ui/asm/type-check-1.rs
New upstream version 1.54.0+dfsg1
[rustc.git] / src / test / ui / asm / type-check-1.rs
1 // only-x86_64
2
3 #![feature(asm, global_asm)]
4
5 fn main() {
6 unsafe {
7 // Outputs must be place expressions
8
9 asm!("{}", in(reg) 1 + 2);
10 asm!("{}", out(reg) 1 + 2);
11 //~^ ERROR invalid asm output
12 asm!("{}", inout(reg) 1 + 2);
13 //~^ ERROR invalid asm output
14
15 // Operands must be sized
16
17 let v: [u64; 3] = [0, 1, 2];
18 asm!("{}", in(reg) v[..]);
19 //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
20 asm!("{}", out(reg) v[..]);
21 //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
22 asm!("{}", inout(reg) v[..]);
23 //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
24
25 // Constants must be... constant
26
27 let x = 0;
28 const fn const_foo(x: i32) -> i32 {
29 x
30 }
31 const fn const_bar<T>(x: T) -> T {
32 x
33 }
34 asm!("{}", const x);
35 //~^ ERROR attempt to use a non-constant value in a constant
36 asm!("{}", const const_foo(0));
37 asm!("{}", const const_foo(x));
38 //~^ ERROR attempt to use a non-constant value in a constant
39 asm!("{}", const const_bar(0));
40 asm!("{}", const const_bar(x));
41 //~^ ERROR attempt to use a non-constant value in a constant
42
43 // Const operands must be integers and must be constants.
44
45 asm!("{}", const 0);
46 asm!("{}", const 0i32);
47 asm!("{}", const 0i128);
48 asm!("{}", const 0f32);
49 //~^ ERROR mismatched types
50 asm!("{}", const 0 as *mut u8);
51 //~^ ERROR mismatched types
52 }
53 }
54
55 // Const operands must be integers and must be constants.
56
57 global_asm!("{}", const 0);
58 global_asm!("{}", const 0i32);
59 global_asm!("{}", const 0i128);
60 global_asm!("{}", const 0f32);
61 //~^ ERROR mismatched types
62 global_asm!("{}", const 0 as *mut u8);
63 //~^ ERROR mismatched types