mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 18:43:01 +00:00
Differentiate between asm!(), global_asm!() and naked_asm!(), and make only asm!() unsafe
This commit is contained in:
parent
edb804a100
commit
bd8087e86e
16 changed files with 198 additions and 16 deletions
|
|
@ -10,7 +10,7 @@ use tt::TextRange;
|
|||
|
||||
use crate::{
|
||||
expr_store::lower::{ExprCollector, FxIndexSet},
|
||||
hir::{AsmOperand, AsmOptions, Expr, ExprId, InlineAsm, InlineAsmRegOrRegClass},
|
||||
hir::{AsmOperand, AsmOptions, Expr, ExprId, InlineAsm, InlineAsmKind, InlineAsmRegOrRegClass},
|
||||
};
|
||||
|
||||
impl ExprCollector<'_> {
|
||||
|
|
@ -269,8 +269,17 @@ impl ExprCollector<'_> {
|
|||
}
|
||||
})
|
||||
};
|
||||
|
||||
let kind = if asm.global_asm_token().is_some() {
|
||||
InlineAsmKind::GlobalAsm
|
||||
} else if asm.naked_asm_token().is_some() {
|
||||
InlineAsmKind::NakedAsm
|
||||
} else {
|
||||
InlineAsmKind::Asm
|
||||
};
|
||||
|
||||
let idx = self.alloc_expr(
|
||||
Expr::InlineAsm(InlineAsm { operands: operands.into_boxed_slice(), options }),
|
||||
Expr::InlineAsm(InlineAsm { operands: operands.into_boxed_slice(), options, kind }),
|
||||
syntax_ptr,
|
||||
);
|
||||
self.source_map
|
||||
|
|
|
|||
|
|
@ -332,6 +332,17 @@ pub struct OffsetOf {
|
|||
pub struct InlineAsm {
|
||||
pub operands: Box<[(Option<Name>, AsmOperand)]>,
|
||||
pub options: AsmOptions,
|
||||
pub kind: InlineAsmKind,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum InlineAsmKind {
|
||||
/// `asm!()`.
|
||||
Asm,
|
||||
/// `global_asm!()`.
|
||||
GlobalAsm,
|
||||
/// `naked_asm!()`.
|
||||
NakedAsm,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||
|
|
|
|||
|
|
@ -28,6 +28,20 @@ fn test_asm_expand() {
|
|||
r#"
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! asm {() => {}}
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! global_asm {() => {}}
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! naked_asm {() => {}}
|
||||
|
||||
// FIXME: This creates an error
|
||||
// global_asm! {
|
||||
// ""
|
||||
// }
|
||||
|
||||
#[unsafe(naked)]
|
||||
extern "C" fn foo() {
|
||||
naked_asm!("");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let i: u64 = 3;
|
||||
|
|
@ -45,6 +59,20 @@ fn main() {
|
|||
expect![[r##"
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! asm {() => {}}
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! global_asm {() => {}}
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! naked_asm {() => {}}
|
||||
|
||||
// FIXME: This creates an error
|
||||
// global_asm! {
|
||||
// ""
|
||||
// }
|
||||
|
||||
#[unsafe(naked)]
|
||||
extern "C" fn foo() {
|
||||
builtin #naked_asm ("");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let i: u64 = 3;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue