1
Fork 0

remove checks that are now performed during macro expansion of naked_asm!

This commit is contained in:
Folkert de Vries 2024-09-05 18:56:38 +02:00
parent bc0a9543a3
commit 10fa482906
3 changed files with 8 additions and 66 deletions

View file

@ -492,9 +492,6 @@ passes_naked_functions_asm_block =
.label_multiple_asm = multiple `naked_asm!` invocations are not allowed in naked functions .label_multiple_asm = multiple `naked_asm!` invocations are not allowed in naked functions
.label_non_asm = not allowed in naked functions .label_non_asm = not allowed in naked functions
passes_naked_functions_asm_options =
asm options unsupported in naked functions: {$unsupported_options}
passes_naked_functions_incompatible_attribute = passes_naked_functions_incompatible_attribute =
attribute incompatible with `#[naked]` attribute incompatible with `#[naked]`
.label = the `{$attr}` attribute is incompatible with `#[naked]` .label = the `{$attr}` attribute is incompatible with `#[naked]`
@ -504,9 +501,6 @@ passes_naked_functions_must_naked_asm =
the `asm!` macro is not allowed in naked functions the `asm!` macro is not allowed in naked functions
.suggestion = consider using the `naked_asm!` macro instead .suggestion = consider using the `naked_asm!` macro instead
passes_naked_functions_operands =
only `const` and `sym` operands are supported in naked functions
passes_no_link = passes_no_link =
attribute should be applied to an `extern crate` item attribute should be applied to an `extern crate` item
.label = not an `extern crate` item .label = not an `extern crate` item

View file

@ -1186,21 +1186,6 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for NakedFunctionsAsmBlock {
} }
} }
#[derive(Diagnostic)]
#[diag(passes_naked_functions_operands, code = E0787)]
pub(crate) struct NakedFunctionsOperands {
#[primary_span]
pub unsupported_operands: Vec<Span>,
}
#[derive(Diagnostic)]
#[diag(passes_naked_functions_asm_options, code = E0787)]
pub(crate) struct NakedFunctionsAsmOptions {
#[primary_span]
pub span: Span,
pub unsupported_options: String,
}
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(passes_naked_functions_must_naked_asm, code = E0787)] #[diag(passes_naked_functions_must_naked_asm, code = E0787)]
pub(crate) struct NakedFunctionsMustNakedAsm { pub(crate) struct NakedFunctionsMustNakedAsm {

View file

@ -1,11 +1,10 @@
//! Checks validity of naked functions. //! Checks validity of naked functions.
use rustc_ast::InlineAsmOptions;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{LocalDefId, LocalModDefId}; use rustc_hir::def_id::{LocalDefId, LocalModDefId};
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_hir::{ExprKind, HirIdSet, InlineAsmOperand, StmtKind}; use rustc_hir::{ExprKind, HirIdSet, StmtKind};
use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::hir::nested_filter::OnlyBodies;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
@ -15,9 +14,8 @@ use rustc_span::{BytePos, Span};
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
use crate::errors::{ use crate::errors::{
NakedAsmOutsideNakedFn, NakedFunctionsAsmBlock, NakedFunctionsAsmOptions, NakedAsmOutsideNakedFn, NakedFunctionsAsmBlock, NakedFunctionsMustNakedAsm, NoPatterns,
NakedFunctionsMustNakedAsm, NakedFunctionsOperands, NoPatterns, ParamsNotAllowed, ParamsNotAllowed, UndefinedNakedFunctionAbi,
UndefinedNakedFunctionAbi,
}; };
pub(crate) fn provide(providers: &mut Providers) { pub(crate) fn provide(providers: &mut Providers) {
@ -119,7 +117,7 @@ impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> {
/// Checks that function body contains a single inline assembly block. /// Checks that function body contains a single inline assembly block.
fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<'tcx>) { fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<'tcx>) {
let mut this = CheckInlineAssembly { tcx, items: Vec::new() }; let mut this = CheckInlineAssembly { items: Vec::new() };
this.visit_body(body); this.visit_body(body);
if let [(ItemKind::NakedAsm | ItemKind::Err, _)] = this.items[..] { if let [(ItemKind::NakedAsm | ItemKind::Err, _)] = this.items[..] {
// Ok. // Ok.
@ -165,8 +163,7 @@ fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<
} }
} }
struct CheckInlineAssembly<'tcx> { struct CheckInlineAssembly {
tcx: TyCtxt<'tcx>,
items: Vec<(ItemKind, Span)>, items: Vec<(ItemKind, Span)>,
} }
@ -178,8 +175,8 @@ enum ItemKind {
Err, Err,
} }
impl<'tcx> CheckInlineAssembly<'tcx> { impl CheckInlineAssembly {
fn check_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, span: Span) { fn check_expr<'tcx>(&mut self, expr: &'tcx hir::Expr<'tcx>, span: Span) {
match expr.kind { match expr.kind {
ExprKind::ConstBlock(..) ExprKind::ConstBlock(..)
| ExprKind::Array(..) | ExprKind::Array(..)
@ -220,7 +217,6 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
} }
rustc_ast::AsmMacro::NakedAsm => { rustc_ast::AsmMacro::NakedAsm => {
self.items.push((ItemKind::NakedAsm, span)); self.items.push((ItemKind::NakedAsm, span));
self.check_inline_asm(asm, span);
} }
rustc_ast::AsmMacro::GlobalAsm => { rustc_ast::AsmMacro::GlobalAsm => {
// not allowed in this position // not allowed in this position
@ -237,42 +233,9 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
} }
} }
} }
fn check_inline_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>, span: Span) {
let unsupported_operands: Vec<Span> = asm
.operands
.iter()
.filter_map(|&(ref op, op_sp)| match op {
InlineAsmOperand::Const { .. }
| InlineAsmOperand::SymFn { .. }
| InlineAsmOperand::SymStatic { .. } => None,
InlineAsmOperand::In { .. }
| InlineAsmOperand::Out { .. }
| InlineAsmOperand::InOut { .. }
| InlineAsmOperand::SplitInOut { .. }
| InlineAsmOperand::Label { .. } => Some(op_sp),
})
.collect();
if !unsupported_operands.is_empty() {
self.tcx.dcx().emit_err(NakedFunctionsOperands { unsupported_operands });
}
let unsupported_options = asm.options.difference(InlineAsmOptions::NAKED_OPTIONS);
if !unsupported_options.is_empty() {
self.tcx.dcx().emit_err(NakedFunctionsAsmOptions {
span,
unsupported_options: unsupported_options
.human_readable_names()
.into_iter()
.map(|name| format!("`{name}`"))
.collect::<Vec<_>>()
.join(", "),
});
}
}
} }
impl<'tcx> Visitor<'tcx> for CheckInlineAssembly<'tcx> { impl<'tcx> Visitor<'tcx> for CheckInlineAssembly {
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) { fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
match stmt.kind { match stmt.kind {
StmtKind::Item(..) => {} StmtKind::Item(..) => {}