Skip to content

Commit

Permalink
Reject may_unwind option in naked functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Jan 21, 2022
1 parent 888332f commit beeba4b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/naked_functions.rs
Expand Up @@ -251,6 +251,7 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
}

let unsupported_options: Vec<&'static str> = [
(InlineAsmOptions::MAY_UNWIND, "`may_unwind`"),
(InlineAsmOptions::NOMEM, "`nomem`"),
(InlineAsmOptions::NOSTACK, "`nostack`"),
(InlineAsmOptions::PRESERVES_FLAGS, "`preserves_flags`"),
Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/asm/naked-functions.rs
Expand Up @@ -5,7 +5,7 @@

#![feature(naked_functions)]
#![feature(or_patterns)]
#![feature(asm_const, asm_sym)]
#![feature(asm_const, asm_sym, asm_unwind)]
#![crate_type = "lib"]

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

#[naked]
unsafe extern "C" fn invalid_may_unwind() {
asm!("", options(noreturn, may_unwind));
//~^ ERROR asm options unsupported in naked functions: `may_unwind`
}

#[naked]
pub unsafe fn default_abi() {
//~^ WARN Rust ABI is unsupported in naked functions
Expand Down
24 changes: 15 additions & 9 deletions src/test/ui/asm/naked-functions.stderr
Expand Up @@ -199,56 +199,62 @@ error[E0787]: asm in naked functions must use `noreturn` option
LL | asm!("", options(readonly, nostack), options(pure));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0787]: asm options unsupported in naked functions: `may_unwind`
--> $DIR/naked-functions.rs:119:5
|
LL | asm!("", options(noreturn, may_unwind));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: Rust ABI is unsupported in naked functions
--> $DIR/naked-functions.rs:118:15
--> $DIR/naked-functions.rs:124:15
|
LL | pub unsafe fn default_abi() {
| ^^^^^^^^^^^
|
= note: `#[warn(undefined_naked_function_abi)]` on by default

warning: Rust ABI is unsupported in naked functions
--> $DIR/naked-functions.rs:124:15
--> $DIR/naked-functions.rs:130:15
|
LL | pub unsafe fn rust_abi() {
| ^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:164:1
--> $DIR/naked-functions.rs:170:1
|
LL | #[inline]
| ^^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:171:1
--> $DIR/naked-functions.rs:177:1
|
LL | #[inline(always)]
| ^^^^^^^^^^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:178:1
--> $DIR/naked-functions.rs:184:1
|
LL | #[inline(never)]
| ^^^^^^^^^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:185:1
--> $DIR/naked-functions.rs:191:1
|
LL | #[inline]
| ^^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:187:1
--> $DIR/naked-functions.rs:193:1
|
LL | #[inline(always)]
| ^^^^^^^^^^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:189:1
--> $DIR/naked-functions.rs:195:1
|
LL | #[inline(never)]
| ^^^^^^^^^^^^^^^^

error: aborting due to 29 previous errors; 2 warnings emitted
error: aborting due to 30 previous errors; 2 warnings emitted

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

0 comments on commit beeba4b

Please sign in to comment.