Skip to content

Commit beeba4b

Browse files
committed
Reject may_unwind option in naked functions
1 parent 888332f commit beeba4b

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

compiler/rustc_passes/src/naked_functions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
251251
}
252252

253253
let unsupported_options: Vec<&'static str> = [
254+
(InlineAsmOptions::MAY_UNWIND, "`may_unwind`"),
254255
(InlineAsmOptions::NOMEM, "`nomem`"),
255256
(InlineAsmOptions::NOSTACK, "`nostack`"),
256257
(InlineAsmOptions::PRESERVES_FLAGS, "`preserves_flags`"),

src/test/ui/asm/naked-functions.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#![feature(naked_functions)]
77
#![feature(or_patterns)]
8-
#![feature(asm_const, asm_sym)]
8+
#![feature(asm_const, asm_sym, asm_unwind)]
99
#![crate_type = "lib"]
1010

1111
use std::arch::asm;
@@ -114,6 +114,12 @@ unsafe extern "C" fn invalid_options_continued() {
114114
//~| ERROR asm in naked functions must use `noreturn` option
115115
}
116116

117+
#[naked]
118+
unsafe extern "C" fn invalid_may_unwind() {
119+
asm!("", options(noreturn, may_unwind));
120+
//~^ ERROR asm options unsupported in naked functions: `may_unwind`
121+
}
122+
117123
#[naked]
118124
pub unsafe fn default_abi() {
119125
//~^ WARN Rust ABI is unsupported in naked functions

src/test/ui/asm/naked-functions.stderr

+15-9
Original file line numberDiff line numberDiff line change
@@ -199,56 +199,62 @@ error[E0787]: asm in naked functions must use `noreturn` option
199199
LL | asm!("", options(readonly, nostack), options(pure));
200200
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201201

202+
error[E0787]: asm options unsupported in naked functions: `may_unwind`
203+
--> $DIR/naked-functions.rs:119:5
204+
|
205+
LL | asm!("", options(noreturn, may_unwind));
206+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
207+
202208
warning: Rust ABI is unsupported in naked functions
203-
--> $DIR/naked-functions.rs:118:15
209+
--> $DIR/naked-functions.rs:124:15
204210
|
205211
LL | pub unsafe fn default_abi() {
206212
| ^^^^^^^^^^^
207213
|
208214
= note: `#[warn(undefined_naked_function_abi)]` on by default
209215

210216
warning: Rust ABI is unsupported in naked functions
211-
--> $DIR/naked-functions.rs:124:15
217+
--> $DIR/naked-functions.rs:130:15
212218
|
213219
LL | pub unsafe fn rust_abi() {
214220
| ^^^^^^^^
215221

216222
error: naked functions cannot be inlined
217-
--> $DIR/naked-functions.rs:164:1
223+
--> $DIR/naked-functions.rs:170:1
218224
|
219225
LL | #[inline]
220226
| ^^^^^^^^^
221227

222228
error: naked functions cannot be inlined
223-
--> $DIR/naked-functions.rs:171:1
229+
--> $DIR/naked-functions.rs:177:1
224230
|
225231
LL | #[inline(always)]
226232
| ^^^^^^^^^^^^^^^^^
227233

228234
error: naked functions cannot be inlined
229-
--> $DIR/naked-functions.rs:178:1
235+
--> $DIR/naked-functions.rs:184:1
230236
|
231237
LL | #[inline(never)]
232238
| ^^^^^^^^^^^^^^^^
233239

234240
error: naked functions cannot be inlined
235-
--> $DIR/naked-functions.rs:185:1
241+
--> $DIR/naked-functions.rs:191:1
236242
|
237243
LL | #[inline]
238244
| ^^^^^^^^^
239245

240246
error: naked functions cannot be inlined
241-
--> $DIR/naked-functions.rs:187:1
247+
--> $DIR/naked-functions.rs:193:1
242248
|
243249
LL | #[inline(always)]
244250
| ^^^^^^^^^^^^^^^^^
245251

246252
error: naked functions cannot be inlined
247-
--> $DIR/naked-functions.rs:189:1
253+
--> $DIR/naked-functions.rs:195:1
248254
|
249255
LL | #[inline(never)]
250256
| ^^^^^^^^^^^^^^^^
251257

252-
error: aborting due to 29 previous errors; 2 warnings emitted
258+
error: aborting due to 30 previous errors; 2 warnings emitted
253259

254260
For more information about this error, try `rustc --explain E0787`.

0 commit comments

Comments
 (0)