]> git.proxmox.com Git - rustc.git/blob - src/test/ui/asm/naked-functions.rs
New upstream version 1.58.1+dfsg1
[rustc.git] / src / test / ui / asm / naked-functions.rs
1 // needs-asm-support
2 // ignore-nvptx64
3 // ignore-spirv
4 // ignore-wasm32
5
6 #![feature(asm)]
7 #![feature(llvm_asm)]
8 #![feature(naked_functions)]
9 #![feature(or_patterns)]
10 #![feature(asm_const, asm_sym)]
11 #![crate_type = "lib"]
12 #![allow(deprecated)] // llvm_asm!
13
14 #[repr(C)]
15 pub struct P {
16 x: u8,
17 y: u16,
18 }
19
20 #[naked]
21 pub unsafe extern "C" fn patterns(
22 mut a: u32,
23 //~^ ERROR patterns not allowed in naked function parameters
24 &b: &i32,
25 //~^ ERROR patterns not allowed in naked function parameters
26 (None | Some(_)): Option<std::ptr::NonNull<u8>>,
27 //~^ ERROR patterns not allowed in naked function parameters
28 P { x, y }: P,
29 //~^ ERROR patterns not allowed in naked function parameters
30 ) {
31 asm!("", options(noreturn))
32 }
33
34 #[naked]
35 pub unsafe extern "C" fn inc(a: u32) -> u32 {
36 //~^ WARN naked functions must contain a single asm block
37 //~| WARN this was previously accepted
38 a + 1
39 //~^ ERROR referencing function parameters is not allowed in naked functions
40 }
41
42 #[naked]
43 pub unsafe extern "C" fn inc_asm(a: u32) -> u32 {
44 asm!("/* {0} */", in(reg) a, options(noreturn));
45 //~^ ERROR referencing function parameters is not allowed in naked functions
46 //~| WARN only `const` and `sym` operands are supported in naked functions
47 //~| WARN this was previously accepted
48 }
49
50 #[naked]
51 pub unsafe extern "C" fn inc_closure(a: u32) -> u32 {
52 //~^ WARN naked functions must contain a single asm block
53 //~| WARN this was previously accepted
54 (|| a + 1)()
55 }
56
57 #[naked]
58 pub unsafe extern "C" fn unsupported_operands() {
59 //~^ WARN naked functions must contain a single asm block
60 //~| WARN this was previously accepted
61 let mut a = 0usize;
62 let mut b = 0usize;
63 let mut c = 0usize;
64 let mut d = 0usize;
65 let mut e = 0usize;
66 const F: usize = 0usize;
67 static G: usize = 0usize;
68 asm!("/* {0} {1} {2} {3} {4} {5} {6} */",
69 //~^ WARN asm in naked functions must use `noreturn` option
70 //~| WARN this was previously accepted
71 in(reg) a,
72 //~^ WARN only `const` and `sym` operands are supported in naked functions
73 //~| WARN this was previously accepted
74 inlateout(reg) b,
75 inout(reg) c,
76 lateout(reg) d,
77 out(reg) e,
78 const F,
79 sym G,
80 );
81 }
82
83 #[naked]
84 pub extern "C" fn missing_assembly() {
85 //~^ WARN naked functions must contain a single asm block
86 //~| WARN this was previously accepted
87 }
88
89 #[naked]
90 pub extern "C" fn too_many_asm_blocks() {
91 //~^ WARN naked functions must contain a single asm block
92 //~| WARN this was previously accepted
93 asm!("");
94 //~^ WARN asm in naked functions must use `noreturn` option
95 //~| WARN this was previously accepted
96 asm!("");
97 //~^ WARN asm in naked functions must use `noreturn` option
98 //~| WARN this was previously accepted
99 asm!("");
100 //~^ WARN asm in naked functions must use `noreturn` option
101 //~| WARN this was previously accepted
102 asm!("", options(noreturn));
103 }
104
105 pub fn outer(x: u32) -> extern "C" fn(usize) -> usize {
106 #[naked]
107 pub extern "C" fn inner(y: usize) -> usize {
108 //~^ WARN naked functions must contain a single asm block
109 //~| WARN this was previously accepted
110 *&y
111 //~^ ERROR referencing function parameters is not allowed in naked functions
112 }
113 inner
114 }
115
116 #[naked]
117 unsafe extern "C" fn llvm() -> ! {
118 //~^ WARN naked functions must contain a single asm block
119 //~| WARN this was previously accepted
120 llvm_asm!("");
121 //~^ WARN LLVM-style inline assembly is unsupported in naked functions
122 //~| WARN this was previously accepted
123 core::hint::unreachable_unchecked();
124 }
125
126 #[naked]
127 unsafe extern "C" fn invalid_options() {
128 asm!("", options(nomem, preserves_flags, noreturn));
129 //~^ WARN asm options unsupported in naked functions: `nomem`, `preserves_flags`
130 //~| WARN this was previously accepted
131 }
132
133 #[naked]
134 unsafe extern "C" fn invalid_options_continued() {
135 asm!("", options(readonly, nostack), options(pure));
136 //~^ ERROR asm with the `pure` option must have at least one output
137 //~| WARN asm options unsupported in naked functions: `nostack`, `pure`, `readonly`
138 //~| WARN this was previously accepted
139 //~| WARN asm in naked functions must use `noreturn` option
140 //~| WARN this was previously accepted
141 }
142
143 #[naked]
144 pub unsafe fn default_abi() {
145 //~^ WARN Rust ABI is unsupported in naked functions
146 asm!("", options(noreturn));
147 }
148
149 #[naked]
150 pub unsafe fn rust_abi() {
151 //~^ WARN Rust ABI is unsupported in naked functions
152 asm!("", options(noreturn));
153 }
154
155 #[naked]
156 pub extern "C" fn valid_a<T>() -> T {
157 unsafe {
158 asm!("", options(noreturn));
159 }
160 }
161
162 #[naked]
163 pub extern "C" fn valid_b() {
164 unsafe {
165 {
166 {
167 asm!("", options(noreturn));
168 };
169 };
170 }
171 }
172
173 #[naked]
174 pub unsafe extern "C" fn valid_c() {
175 asm!("", options(noreturn));
176 }
177
178 #[cfg(target_arch = "x86_64")]
179 #[naked]
180 pub unsafe extern "C" fn valid_att_syntax() {
181 asm!("", options(noreturn, att_syntax));
182 }
183
184 #[naked]
185 pub unsafe extern "C" fn inline_none() {
186 asm!("", options(noreturn));
187 }
188
189 #[naked]
190 #[inline]
191 //~^ WARN naked functions cannot be inlined
192 //~| WARN this was previously accepted
193 pub unsafe extern "C" fn inline_hint() {
194 asm!("", options(noreturn));
195 }
196
197 #[naked]
198 #[inline(always)]
199 //~^ WARN naked functions cannot be inlined
200 //~| WARN this was previously accepted
201 pub unsafe extern "C" fn inline_always() {
202 asm!("", options(noreturn));
203 }
204
205 #[naked]
206 #[inline(never)]
207 //~^ WARN naked functions cannot be inlined
208 //~| WARN this was previously accepted
209 pub unsafe extern "C" fn inline_never() {
210 asm!("", options(noreturn));
211 }
212
213 #[naked]
214 #[inline]
215 //~^ WARN naked functions cannot be inlined
216 //~| WARN this was previously accepted
217 #[inline(always)]
218 //~^ WARN naked functions cannot be inlined
219 //~| WARN this was previously accepted
220 #[inline(never)]
221 //~^ WARN naked functions cannot be inlined
222 //~| WARN this was previously accepted
223 pub unsafe extern "C" fn inline_all() {
224 asm!("", options(noreturn));
225 }