Rollup merge of #128138 - folkertdev:asm-option-allowlist, r=lcnr
`#[naked]`: use an allowlist for allowed options on `asm!` in naked functions tracking issue: https://github.com/rust-lang/rust/issues/90957 this is mostly just a refactor, but using an allowlist (rather than a denylist) for which asm options are allowed in naked functions is a little safer. These options are disallowed because naked functions are effectively global asm, but defined using inline asm.
This commit is contained in:
commit
e76bb3fab6
6 changed files with 49 additions and 72 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