]>
Commit | Line | Data |
---|---|---|
f9f354fc XL |
1 | // only-x86_64 |
2 | ||
3 | #![feature(asm, repr_simd, never_type)] | |
4 | ||
5 | #[repr(simd)] | |
6 | struct SimdNonCopy(f32, f32, f32, f32); | |
7 | ||
8 | fn main() { | |
9 | unsafe { | |
10 | // Inputs must be initialized | |
11 | ||
12 | let x: u64; | |
13 | asm!("{}", in(reg) x); | |
14 | //~^ ERROR use of possibly-uninitialized variable: `x` | |
15 | let mut y: u64; | |
16 | asm!("{}", inout(reg) y); | |
17 | //~^ ERROR use of possibly-uninitialized variable: `y` | |
18 | let _ = y; | |
19 | ||
20 | // Outputs require mutable places | |
21 | ||
22 | let v: Vec<u64> = vec![0, 1, 2]; | |
23 | asm!("{}", in(reg) v[0]); | |
24 | asm!("{}", out(reg) v[0]); | |
25 | //~^ ERROR cannot borrow `v` as mutable, as it is not declared as mutable | |
26 | asm!("{}", inout(reg) v[0]); | |
27 | //~^ ERROR cannot borrow `v` as mutable, as it is not declared as mutable | |
28 | ||
29 | // Const operands must be integer or floats, and must be constants. | |
30 | ||
31 | let x = 0; | |
32 | const C: i32 = 0; | |
33 | const fn const_foo(x: i32) -> i32 { | |
34 | x | |
35 | } | |
36 | const fn const_bar<T>(x: T) -> T { | |
37 | x | |
38 | } | |
39 | asm!("{}", const 0i32); | |
40 | asm!("{}", const 0f32); | |
41 | asm!("{}", const 0 as *mut u8); | |
42 | //~^ ERROR asm `const` arguments must be integer or floating-point values | |
43 | asm!("{}", const &0); | |
44 | //~^ ERROR asm `const` arguments must be integer or floating-point values | |
45 | asm!("{}", const x); | |
46 | //~^ ERROR argument 1 is required to be a constant | |
47 | asm!("{}", const const_foo(0)); | |
48 | asm!("{}", const const_foo(x)); | |
49 | //~^ ERROR argument 1 is required to be a constant | |
50 | asm!("{}", const const_bar(0)); | |
51 | asm!("{}", const const_bar(x)); | |
52 | //~^ ERROR argument 1 is required to be a constant | |
53 | ||
54 | // Sym operands must point to a function or static | |
55 | ||
56 | static S: i32 = 0; | |
57 | asm!("{}", sym S); | |
58 | asm!("{}", sym main); | |
59 | asm!("{}", sym C); | |
60 | //~^ ERROR asm `sym` operand must point to a fn or static | |
61 | asm!("{}", sym x); | |
62 | //~^ ERROR asm `sym` operand must point to a fn or static | |
63 | ||
64 | // Register operands must be Copy | |
65 | ||
66 | asm!("{}", in(xmm_reg) SimdNonCopy(0.0, 0.0, 0.0, 0.0)); | |
67 | //~^ ERROR arguments for inline assembly must be copyable | |
68 | ||
69 | // Register operands must be integers, floats, SIMD vectors, pointers or | |
70 | // function pointers. | |
71 | ||
72 | asm!("{}", in(reg) 0i64); | |
73 | asm!("{}", in(reg) 0f64); | |
74 | asm!("{}", in(xmm_reg) std::arch::x86_64::_mm_setzero_ps()); | |
75 | asm!("{}", in(reg) 0 as *const u8); | |
76 | asm!("{}", in(reg) 0 as *mut u8); | |
77 | asm!("{}", in(reg) main as fn()); | |
78 | asm!("{}", in(reg) |x: i32| x); | |
79 | //~^ ERROR cannot use value of type | |
80 | asm!("{}", in(reg) vec![0]); | |
1b1a35ee | 81 | //~^ ERROR cannot use value of type `Vec<i32>` for inline assembly |
f9f354fc XL |
82 | asm!("{}", in(reg) (1, 2, 3)); |
83 | //~^ ERROR cannot use value of type `(i32, i32, i32)` for inline assembly | |
84 | asm!("{}", in(reg) [1, 2, 3]); | |
85 | //~^ ERROR cannot use value of type `[i32; 3]` for inline assembly | |
86 | ||
87 | // Register inputs (but not outputs) allow references and function types | |
88 | ||
89 | let mut f = main; | |
90 | let mut r = &mut 0; | |
91 | asm!("{}", in(reg) f); | |
92 | asm!("{}", inout(reg) f); | |
93 | //~^ ERROR cannot use value of type `fn() {main}` for inline assembly | |
94 | asm!("{}", in(reg) r); | |
95 | asm!("{}", inout(reg) r); | |
96 | //~^ ERROR cannot use value of type `&mut i32` for inline assembly | |
97 | let _ = (f, r); | |
98 | ||
99 | // Type checks ignore never type | |
100 | ||
101 | let u: ! = unreachable!(); | |
102 | asm!("{}", in(reg) u); | |
103 | } | |
104 | } |