]> git.lizzy.rs Git - rust.git/blob - src/test/ui/asm/naked-functions.rs
Auto merge of #79780 - camelid:use-summary_opts, r=GuillaumeGomez
[rust.git] / src / test / ui / asm / naked-functions.rs
1 // only-x86_64
2 #![feature(asm)]
3 #![feature(llvm_asm)]
4 #![feature(naked_functions)]
5 #![feature(or_patterns)]
6 #![crate_type = "lib"]
7
8 #[repr(C)]
9 pub struct P { x: u8, y: u16 }
10
11 #[naked]
12 pub unsafe extern "C" fn patterns(
13     mut a: u32,
14     //~^ ERROR patterns not allowed in naked function parameters
15     &b: &i32,
16     //~^ ERROR patterns not allowed in naked function parameters
17     (None | Some(_)): Option<std::ptr::NonNull<u8>>,
18     //~^ ERROR patterns not allowed in naked function parameters
19     P { x, y }: P,
20     //~^ ERROR patterns not allowed in naked function parameters
21 ) {
22     asm!("", options(noreturn))
23 }
24
25 #[naked]
26 pub unsafe extern "C" fn inc(a: u32) -> u32 {
27     //~^ WARN naked functions must contain a single asm block
28     //~| WARN this was previously accepted
29     a + 1
30     //~^ ERROR referencing function parameters is not allowed in naked functions
31 }
32
33 #[naked]
34 pub unsafe extern "C" fn inc_asm(a: u32) -> u32 {
35     asm!("/* {0} */", in(reg) a, options(noreturn));
36     //~^ ERROR referencing function parameters is not allowed in naked functions
37     //~| WARN only `const` and `sym` operands are supported in naked functions
38     //~| WARN this was previously accepted
39 }
40
41 #[naked]
42 pub unsafe extern "C" fn inc_closure(a: u32) -> u32 {
43     //~^ WARN naked functions must contain a single asm block
44     //~| WARN this was previously accepted
45     (|| a + 1)()
46 }
47
48 #[naked]
49 pub unsafe extern "C" fn unsupported_operands() {
50     //~^ WARN naked functions must contain a single asm block
51     //~| WARN this was previously accepted
52     let mut a = 0usize;
53     let mut b = 0usize;
54     let mut c = 0usize;
55     let mut d = 0usize;
56     let mut e = 0usize;
57     const F: usize = 0usize;
58     static G: usize = 0usize;
59     asm!("/* {0} {1} {2} {3} {4} {5} {6} */",
60          //~^ WARN asm in naked functions must use `noreturn` option
61          //~| WARN this was previously accepted
62          in(reg) a,
63          //~^ WARN only `const` and `sym` operands are supported in naked functions
64          //~| WARN this was previously accepted
65          inlateout(reg) b,
66          inout(reg) c,
67          lateout(reg) d,
68          out(reg) e,
69          const F,
70          sym G,
71     );
72 }
73
74 #[naked]
75 pub extern "C" fn missing_assembly() {
76     //~^ WARN naked functions must contain a single asm block
77     //~| WARN this was previously accepted
78 }
79
80 #[naked]
81 pub extern "C" fn too_many_asm_blocks() {
82     //~^ WARN naked functions must contain a single asm block
83     //~| WARN this was previously accepted
84     asm!("");
85     //~^ WARN asm in naked functions must use `noreturn` option
86     //~| WARN this was previously accepted
87     asm!("");
88     //~^ WARN asm in naked functions must use `noreturn` option
89     //~| WARN this was previously accepted
90     asm!("");
91     //~^ WARN asm in naked functions must use `noreturn` option
92     //~| WARN this was previously accepted
93     asm!("", options(noreturn));
94 }
95
96 pub fn outer(x: u32) -> extern "C" fn(usize) -> usize {
97     #[naked]
98     pub extern "C" fn inner(y: usize) -> usize {
99         //~^ WARN naked functions must contain a single asm block
100         //~| WARN this was previously accepted
101         *&y
102         //~^ ERROR referencing function parameters is not allowed in naked functions
103     }
104     inner
105 }
106
107 #[naked]
108 unsafe extern "C" fn llvm() -> ! {
109     //~^ WARN naked functions must contain a single asm block
110     //~| WARN this was previously accepted
111     llvm_asm!("");
112     //~^ WARN LLVM-style inline assembly is unsupported in naked functions
113     //~| WARN this was previously accepted
114     core::hint::unreachable_unchecked();
115 }
116
117 #[naked]
118 unsafe extern "C" fn invalid_options() {
119     asm!("", options(nomem, preserves_flags, noreturn));
120     //~^ WARN asm options unsupported in naked functions: `nomem`, `preserves_flags`
121     //~| WARN this was previously accepted
122 }
123
124 #[naked]
125 unsafe extern "C" fn invalid_options_continued() {
126     asm!("", options(readonly, nostack), options(pure));
127     //~^ ERROR asm with `pure` option must have at least one output
128     //~| WARN asm options unsupported in naked functions: `nostack`, `pure`, `readonly`
129     //~| WARN this was previously accepted
130     //~| WARN asm in naked functions must use `noreturn` option
131     //~| WARN this was previously accepted
132 }
133
134 #[naked]
135 pub unsafe fn default_abi() {
136     //~^ WARN Rust ABI is unsupported in naked functions
137     //~| WARN this was previously accepted
138     asm!("", options(noreturn));
139 }
140
141 #[naked]
142 pub unsafe extern "Rust" fn rust_abi() {
143     //~^ WARN Rust ABI is unsupported in naked functions
144     //~| WARN this was previously accepted
145     asm!("", options(noreturn));
146 }
147
148 #[naked]
149 pub extern "C" fn valid_a<T>() -> T {
150     unsafe { asm!("", options(noreturn)); }
151 }
152
153 #[naked]
154 pub extern "C" fn valid_b() {
155     unsafe { { {
156         asm!("", options(noreturn)); ; ; ;
157     } ; }  ; }
158 }
159
160 #[naked]
161 pub unsafe extern "C" fn valid_c() {
162     asm!("", options(noreturn));
163 }
164
165 #[cfg(target_arch = "x86_64")]
166 #[naked]
167 pub unsafe extern "C" fn valid_att_syntax() {
168     asm!("", options(noreturn, att_syntax));
169 }