various fixes for naked_asm!
implementation
- fix for divergence - fix error message - fix another cranelift test - fix some cranelift things - don't set the NORETURN option for naked asm - fix use of naked_asm! in doc comment - fix use of naked_asm! in run-make test - use `span_bug` in unreachable branch
This commit is contained in:
parent
10fa482906
commit
5fc60d1e52
29 changed files with 116 additions and 73 deletions
|
@ -499,7 +499,7 @@ passes_naked_functions_incompatible_attribute =
|
|||
|
||||
passes_naked_functions_must_naked_asm =
|
||||
the `asm!` macro is not allowed in naked functions
|
||||
.suggestion = consider using the `naked_asm!` macro instead
|
||||
.label = consider using the `naked_asm!` macro instead
|
||||
|
||||
passes_no_link =
|
||||
attribute should be applied to an `extern crate` item
|
||||
|
|
|
@ -1190,9 +1190,8 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for NakedFunctionsAsmBlock {
|
|||
#[diag(passes_naked_functions_must_naked_asm, code = E0787)]
|
||||
pub(crate) struct NakedFunctionsMustNakedAsm {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
#[suggestion(code = "naked_asm!", applicability = "machine-applicable")]
|
||||
pub macro_span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
|
@ -7,10 +7,11 @@ use rustc_hir::intravisit::Visitor;
|
|||
use rustc_hir::{ExprKind, HirIdSet, StmtKind};
|
||||
use rustc_middle::hir::nested_filter::OnlyBodies;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::lint::builtin::UNDEFINED_NAKED_FUNCTION_ABI;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::{BytePos, Span};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
use crate::errors::{
|
||||
|
@ -137,10 +138,7 @@ fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<
|
|||
ItemKind::InlineAsm => {
|
||||
has_err = true;
|
||||
|
||||
// the span that contains the `asm!` call,
|
||||
// so tooling can replace it with `naked_asm!`
|
||||
let macro_span = span.with_hi(span.lo() + BytePos("asm!".len() as u32));
|
||||
tcx.dcx().emit_err(NakedFunctionsMustNakedAsm { span, macro_span });
|
||||
tcx.dcx().emit_err(NakedFunctionsMustNakedAsm { span });
|
||||
}
|
||||
ItemKind::NonAsm => {
|
||||
must_show_error = true;
|
||||
|
@ -210,19 +208,17 @@ impl CheckInlineAssembly {
|
|||
self.items.push((ItemKind::NonAsm, span));
|
||||
}
|
||||
|
||||
ExprKind::InlineAsm(asm) => {
|
||||
match asm.asm_macro {
|
||||
rustc_ast::AsmMacro::Asm => {
|
||||
self.items.push((ItemKind::InlineAsm, span));
|
||||
}
|
||||
rustc_ast::AsmMacro::NakedAsm => {
|
||||
self.items.push((ItemKind::NakedAsm, span));
|
||||
}
|
||||
rustc_ast::AsmMacro::GlobalAsm => {
|
||||
// not allowed in this position
|
||||
}
|
||||
ExprKind::InlineAsm(asm) => match asm.asm_macro {
|
||||
rustc_ast::AsmMacro::Asm => {
|
||||
self.items.push((ItemKind::InlineAsm, span));
|
||||
}
|
||||
}
|
||||
rustc_ast::AsmMacro::NakedAsm => {
|
||||
self.items.push((ItemKind::NakedAsm, span));
|
||||
}
|
||||
rustc_ast::AsmMacro::GlobalAsm => {
|
||||
span_bug!(span, "`global_asm!` is not allowed in this position")
|
||||
}
|
||||
},
|
||||
|
||||
ExprKind::DropTemps(..) | ExprKind::Block(..) => {
|
||||
hir::intravisit::walk_expr(self, expr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue