]> git.lizzy.rs Git - rust.git/blob - src/test/ui/asm/type-check-1.rs
Rollup merge of #99787 - aDotInTheVoid:rdj-dyn, r=camelid,notriddle,GuillaumeGomez
[rust.git] / src / test / ui / asm / type-check-1.rs
1 // needs-asm-support
2 // ignore-nvptx64
3 // ignore-spirv
4 // ignore-wasm32
5
6 #![feature(asm_const, asm_sym)]
7
8 use std::arch::{asm, global_asm};
9
10 fn main() {
11     unsafe {
12         // Outputs must be place expressions
13
14         asm!("{}", in(reg) 1 + 2);
15         asm!("{}", out(reg) 1 + 2);
16         //~^ ERROR invalid asm output
17         asm!("{}", inout(reg) 1 + 2);
18         //~^ ERROR invalid asm output
19
20         // Operands must be sized
21
22         let v: [u64; 3] = [0, 1, 2];
23         asm!("{}", in(reg) v[..]);
24         //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
25         //~| ERROR cannot use value of type `[u64]` for inline assembly
26         asm!("{}", out(reg) v[..]);
27         //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
28         //~| ERROR cannot use value of type `[u64]` for inline assembly
29         asm!("{}", inout(reg) v[..]);
30         //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
31         //~| ERROR cannot use value of type `[u64]` for inline assembly
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         asm!("{}", sym x);
51         //~^ ERROR invalid `sym` operand
52
53         // Const operands must be integers and must be constants.
54
55         asm!("{}", const 0);
56         asm!("{}", const 0i32);
57         asm!("{}", const 0i128);
58         asm!("{}", const 0f32);
59         //~^ ERROR mismatched types
60         asm!("{}", const 0 as *mut u8);
61         //~^ ERROR mismatched types
62         asm!("{}", const &0);
63         //~^ ERROR mismatched types
64     }
65 }
66
67 unsafe fn generic<T>() {
68     asm!("{}", sym generic::<T>);
69 }
70
71 // Const operands must be integers and must be constants.
72
73 global_asm!("{}", const 0);
74 global_asm!("{}", const 0i32);
75 global_asm!("{}", const 0i128);
76 global_asm!("{}", const 0f32);
77 //~^ ERROR mismatched types
78 global_asm!("{}", const 0 as *mut u8);
79 //~^ ERROR mismatched types