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
|
@ -4,7 +4,7 @@ use std::fs;
|
|||
use std::io::{self, Write as _};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_ast::InlineAsmTemplatePiece;
|
||||
use rustc_middle::mir::interpret::{
|
||||
AllocBytes, AllocId, Allocation, GlobalAlloc, Pointer, Provenance, alloc_range,
|
||||
read_target_uint,
|
||||
|
@ -1024,9 +1024,9 @@ impl<'tcx> TerminatorKind<'tcx> {
|
|||
vec!["real".into(), "unwind".into()]
|
||||
}
|
||||
FalseUnwind { unwind: _, .. } => vec!["real".into()],
|
||||
InlineAsm { options, ref targets, unwind, .. } => {
|
||||
InlineAsm { asm_macro, options, ref targets, unwind, .. } => {
|
||||
let mut vec = Vec::with_capacity(targets.len() + 1);
|
||||
if !options.contains(InlineAsmOptions::NORETURN) {
|
||||
if !asm_macro.diverges(options) {
|
||||
vec.push("return".into());
|
||||
}
|
||||
vec.resize(targets.len(), "label".into());
|
||||
|
|
|
@ -605,6 +605,25 @@ impl CallSource {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
|
||||
#[derive(TypeFoldable, TypeVisitable)]
|
||||
/// The macro that an inline assembly block was created by
|
||||
pub enum InlineAsmMacro {
|
||||
/// The `asm!` macro
|
||||
Asm,
|
||||
/// The `naked_asm!` macro
|
||||
NakedAsm,
|
||||
}
|
||||
|
||||
impl InlineAsmMacro {
|
||||
pub const fn diverges(self, options: InlineAsmOptions) -> bool {
|
||||
match self {
|
||||
InlineAsmMacro::Asm => options.contains(InlineAsmOptions::NORETURN),
|
||||
InlineAsmMacro::NakedAsm => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Terminators
|
||||
|
||||
|
@ -859,6 +878,9 @@ pub enum TerminatorKind<'tcx> {
|
|||
/// Block ends with an inline assembly block. This is a terminator since
|
||||
/// inline assembly is allowed to diverge.
|
||||
InlineAsm {
|
||||
/// Macro used to create this inline asm: one of `asm!` or `naked_asm!`
|
||||
asm_macro: InlineAsmMacro,
|
||||
|
||||
/// The template for the inline assembly, with placeholders.
|
||||
template: &'tcx [InlineAsmTemplatePiece],
|
||||
|
||||
|
@ -874,7 +896,7 @@ pub enum TerminatorKind<'tcx> {
|
|||
|
||||
/// Valid targets for the inline assembly.
|
||||
/// The first element is the fallthrough destination, unless
|
||||
/// InlineAsmOptions::NORETURN is set.
|
||||
/// asm_macro == InlineAsmMacro::NakedAsm or InlineAsmOptions::NORETURN is set.
|
||||
targets: Box<[BasicBlock]>,
|
||||
|
||||
/// Action to be taken if the inline assembly unwinds. This is present
|
||||
|
|
|
@ -666,6 +666,7 @@ impl<'tcx> TerminatorKind<'tcx> {
|
|||
},
|
||||
|
||||
InlineAsm {
|
||||
asm_macro: _,
|
||||
template: _,
|
||||
ref operands,
|
||||
options: _,
|
||||
|
|
|
@ -576,6 +576,7 @@ macro_rules! make_mir_visitor {
|
|||
}
|
||||
|
||||
TerminatorKind::InlineAsm {
|
||||
asm_macro: _,
|
||||
template: _,
|
||||
operands,
|
||||
options: _,
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::cmp::Ordering;
|
|||
use std::fmt;
|
||||
use std::ops::Index;
|
||||
|
||||
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_ast::{AsmMacro, InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{BindingMode, ByRef, HirId, MatchSource, RangeEnd};
|
||||
|
@ -173,6 +173,7 @@ pub struct ClosureExpr<'tcx> {
|
|||
|
||||
#[derive(Clone, Debug, HashStable)]
|
||||
pub struct InlineAsmExpr<'tcx> {
|
||||
pub asm_macro: AsmMacro,
|
||||
pub template: &'tcx [InlineAsmTemplatePiece],
|
||||
pub operands: Box<[InlineAsmOperand<'tcx>]>,
|
||||
pub options: InlineAsmOptions,
|
||||
|
|
|
@ -148,7 +148,13 @@ pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
|
|||
NamedConst { def_id: _, args: _, user_ty: _ } => {}
|
||||
ConstParam { param: _, def_id: _ } => {}
|
||||
StaticRef { alloc_id: _, ty: _, def_id: _ } => {}
|
||||
InlineAsm(box InlineAsmExpr { ref operands, template: _, options: _, line_spans: _ }) => {
|
||||
InlineAsm(box InlineAsmExpr {
|
||||
asm_macro: _,
|
||||
ref operands,
|
||||
template: _,
|
||||
options: _,
|
||||
line_spans: _,
|
||||
}) => {
|
||||
for op in &**operands {
|
||||
use InlineAsmOperand::*;
|
||||
match op {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue