mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
use an allow list for allowed asm options in naked functions
This commit is contained in:
parent
c31ff97bf1
commit
4b7a87de10
@ -244,22 +244,19 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
|
|||||||
self.tcx.dcx().emit_err(NakedFunctionsOperands { unsupported_operands });
|
self.tcx.dcx().emit_err(NakedFunctionsOperands { unsupported_operands });
|
||||||
}
|
}
|
||||||
|
|
||||||
let unsupported_options: Vec<&'static str> = [
|
let supported_options =
|
||||||
(InlineAsmOptions::MAY_UNWIND, "`may_unwind`"),
|
InlineAsmOptions::RAW | InlineAsmOptions::NORETURN | InlineAsmOptions::ATT_SYNTAX;
|
||||||
(InlineAsmOptions::NOMEM, "`nomem`"),
|
let unsupported_options = asm.options.difference(supported_options);
|
||||||
(InlineAsmOptions::NOSTACK, "`nostack`"),
|
|
||||||
(InlineAsmOptions::PRESERVES_FLAGS, "`preserves_flags`"),
|
|
||||||
(InlineAsmOptions::PURE, "`pure`"),
|
|
||||||
(InlineAsmOptions::READONLY, "`readonly`"),
|
|
||||||
]
|
|
||||||
.iter()
|
|
||||||
.filter_map(|&(option, name)| if asm.options.contains(option) { Some(name) } else { None })
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if !unsupported_options.is_empty() {
|
if !unsupported_options.is_empty() {
|
||||||
self.tcx.dcx().emit_err(NakedFunctionsAsmOptions {
|
self.tcx.dcx().emit_err(NakedFunctionsAsmOptions {
|
||||||
span,
|
span,
|
||||||
unsupported_options: unsupported_options.join(", "),
|
unsupported_options: unsupported_options
|
||||||
|
.human_readable_names()
|
||||||
|
.into_iter()
|
||||||
|
.map(|name| format!("`{name}`"))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", "),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ unsafe extern "C" fn invalid_options() {
|
|||||||
unsafe extern "C" fn invalid_options_continued() {
|
unsafe extern "C" fn invalid_options_continued() {
|
||||||
asm!("", options(readonly, nostack), options(pure));
|
asm!("", options(readonly, nostack), options(pure));
|
||||||
//~^ ERROR asm with the `pure` option must have at least one output
|
//~^ ERROR asm with the `pure` option must have at least one output
|
||||||
//~| ERROR asm options unsupported in naked functions: `nostack`, `pure`, `readonly`
|
//~| ERROR asm options unsupported in naked functions: `pure`, `readonly`, `nostack`
|
||||||
//~| ERROR asm in naked functions must use `noreturn` option
|
//~| ERROR asm in naked functions must use `noreturn` option
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ error[E0787]: asm options unsupported in naked functions: `nomem`, `preserves_fl
|
|||||||
LL | asm!("", options(nomem, preserves_flags, noreturn));
|
LL | asm!("", options(nomem, preserves_flags, noreturn));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0787]: asm options unsupported in naked functions: `nostack`, `pure`, `readonly`
|
error[E0787]: asm options unsupported in naked functions: `pure`, `readonly`, `nostack`
|
||||||
--> $DIR/naked-functions.rs:112:5
|
--> $DIR/naked-functions.rs:112:5
|
||||||
|
|
|
|
||||||
LL | asm!("", options(readonly, nostack), options(pure));
|
LL | asm!("", options(readonly, nostack), options(pure));
|
||||||
|
Loading…
Reference in New Issue
Block a user