use an allow list for allowed asm options in naked functions
This commit is contained in:
parent
c31ff97bf1
commit
4b7a87de10
3 changed files with 11 additions and 14 deletions
|
@ -244,22 +244,19 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
|
|||
self.tcx.dcx().emit_err(NakedFunctionsOperands { unsupported_operands });
|
||||
}
|
||||
|
||||
let unsupported_options: Vec<&'static str> = [
|
||||
(InlineAsmOptions::MAY_UNWIND, "`may_unwind`"),
|
||||
(InlineAsmOptions::NOMEM, "`nomem`"),
|
||||
(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();
|
||||
let supported_options =
|
||||
InlineAsmOptions::RAW | InlineAsmOptions::NORETURN | InlineAsmOptions::ATT_SYNTAX;
|
||||
let unsupported_options = asm.options.difference(supported_options);
|
||||
|
||||
if !unsupported_options.is_empty() {
|
||||
self.tcx.dcx().emit_err(NakedFunctionsAsmOptions {
|
||||
span,
|
||||
unsupported_options: unsupported_options.join(", "),
|
||||
unsupported_options: unsupported_options
|
||||
.human_readable_names()
|
||||
.into_iter()
|
||||
.map(|name| format!("`{name}`"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue