diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2020-01-14 13:40:42 +0000 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2020-03-26 15:49:22 +0000 |
| commit | d162d096ddf7972819e5b700890726a2ea85f272 (patch) | |
| tree | 10aef78eb9fffb1aa127609e953204a62b18ecef | |
| parent | 2fbb07525e2f07a815e780a4268b11916248b5a9 (diff) | |
| download | rust-d162d096ddf7972819e5b700890726a2ea85f272.tar.gz rust-d162d096ddf7972819e5b700890726a2ea85f272.zip | |
Rename asm! to llvm_asm!
asm! is left as a wrapper around llvm_asm! to maintain compatibility.
65 files changed, 213 insertions, 187 deletions
diff --git a/src/doc/unstable-book/src/library-features/asm.md b/src/doc/unstable-book/src/library-features/llvm-asm.md index 2a1b6397781..e07f716e567 100644 --- a/src/doc/unstable-book/src/library-features/asm.md +++ b/src/doc/unstable-book/src/library-features/llvm-asm.md @@ -1,17 +1,17 @@ -# `asm` +# `llvm_asm` -The tracking issue for this feature is: [#29722] +The tracking issue for this feature is: [#70173] -[#29722]: https://github.com/rust-lang/rust/issues/29722 +[#70173]: https://github.com/rust-lang/rust/issues/70173 ------------------------ For extremely low-level manipulations and performance reasons, one might wish to control the CPU directly. Rust supports using inline -assembly to do this via the `asm!` macro. +assembly to do this via the `llvm_asm!` macro. ```rust,ignore -asm!(assembly template +llvm_asm!(assembly template : output operands : input operands : clobbers @@ -19,7 +19,7 @@ asm!(assembly template ); ``` -Any use of `asm` is feature gated (requires `#![feature(asm)]` on the +Any use of `llvm_asm` is feature gated (requires `#![feature(llvm_asm)]` on the crate to allow) and of course requires an `unsafe` block. > **Note**: the examples here are given in x86/x86-64 assembly, but @@ -31,12 +31,12 @@ The `assembly template` is the only required parameter and must be a literal string (i.e. `""`) ```rust -#![feature(asm)] +#![feature(llvm_asm)] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn foo() { unsafe { - asm!("NOP"); + llvm_asm!("NOP"); } } @@ -51,16 +51,16 @@ fn main() { } ``` -(The `feature(asm)` and `#[cfg]`s are omitted from now on.) +(The `feature(llvm_asm)` and `#[cfg]`s are omitted from now on.) Output operands, input operands, clobbers and options are all optional but you must add the right number of `:` if you skip them: ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] # fn main() { unsafe { -asm!("xor %eax, %eax" +llvm_asm!("xor %eax, %eax" : : : "eax" @@ -73,10 +73,10 @@ asm!("xor %eax, %eax" Whitespace also doesn't matter: ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] # fn main() { unsafe { -asm!("xor %eax, %eax" ::: "eax"); +llvm_asm!("xor %eax, %eax" ::: "eax"); # } } # #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] # fn main() {} @@ -89,12 +89,12 @@ Input and output operands follow the same format: `: expressions must be mutable lvalues, or not yet assigned: ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn add(a: i32, b: i32) -> i32 { let c: i32; unsafe { - asm!("add $2, $0" + llvm_asm!("add $2, $0" : "=r"(c) : "0"(a), "r"(b) ); @@ -116,11 +116,11 @@ operand. This is useful for very low level programming, where which register you use is important: ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] # unsafe fn read_byte_in(port: u16) -> u8 { let result: u8; -asm!("in %dx, %al" : "={al}"(result) : "{dx}"(port)); +llvm_asm!("in %dx, %al" : "={al}"(result) : "{dx}"(port)); result # } ``` @@ -133,11 +133,11 @@ compiler not to assume any values loaded into those registers will stay valid. ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] # fn main() { unsafe { // Put the value 0x200 in eax: -asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax"); +llvm_asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax"); # } } # #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] # fn main() {} @@ -167,12 +167,12 @@ Current valid options are: 3. *intel* - use intel syntax instead of the default AT&T. ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] # fn main() { let result: i32; unsafe { - asm!("mov eax, 2" : "={eax}"(result) : : : "intel") + llvm_asm!("mov eax, 2" : "={eax}"(result) : : : "intel") } println!("eax is currently {}", result); # } @@ -182,7 +182,7 @@ println!("eax is currently {}", result); ## More Information -The current implementation of the `asm!` macro is a direct binding to [LLVM's +The current implementation of the `llvm_asm!` macro is a direct binding to [LLVM's inline assembler expressions][llvm-docs], so be sure to check out [their documentation as well][llvm-docs] for more information about clobbers, constraints, etc. @@ -190,4 +190,4 @@ constraints, etc. [llvm-docs]: http://llvm.org/docs/LangRef.html#inline-assembler-expressions If you need more power and don't mind losing some of the niceties of -`asm!`, check out [global_asm](global-asm.md). +`llvm_asm!`, check out [global_asm](global-asm.md). diff --git a/src/libcore/hint.rs b/src/libcore/hint.rs index 6cbd26a78de..698c97999c4 100644 --- a/src/libcore/hint.rs +++ b/src/libcore/hint.rs @@ -113,7 +113,7 @@ pub fn black_box<T>(dummy: T) -> T { // box. This isn't the greatest implementation since it probably deoptimizes // more than we want, but it's so far good enough. unsafe { - asm!("" : : "r"(&dummy)); + llvm_asm!("" : : "r"(&dummy)); dummy } } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 0bee16f98bd..73c5e3fad47 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -98,6 +98,7 @@ #![feature(is_sorted)] #![feature(lang_items)] #![feature(link_llvm_intrinsics)] +#![feature(llvm_asm)] #![cfg_attr(not(bootstrap), feature(negative_impls))] #![feature(never_type)] #![feature(nll)] diff --git a/src/libcore/macros/mod.rs b/src/libcore/macros/mod.rs index a0873fe6b62..f67762cd043 100644 --- a/src/libcore/macros/mod.rs +++ b/src/libcore/macros/mod.rs @@ -1307,7 +1307,7 @@ pub(crate) mod builtin { /// [unstable book]: ../unstable-book/library-features/asm.html #[unstable( feature = "asm", - issue = "29722", + issue = "70173", reason = "inline assembly is not stable enough for use and is subject to change" )] #[rustc_builtin_macro] @@ -1322,6 +1322,47 @@ pub(crate) mod builtin { }; } + /// Inline assembly. + /// + /// Read the [unstable book] for the usage. + /// + /// [unstable book]: ../unstable-book/library-features/asm.html + #[cfg(bootstrap)] + #[unstable( + feature = "llvm_asm", + issue = "70173", + reason = "inline assembly is not stable enough for use and is subject to change" + )] + #[macro_export] + #[allow_internal_unstable(asm)] + macro_rules! llvm_asm { + // Redirect to asm! for stage0 + ($($arg:tt)*) => { $crate::asm!($($arg)*) } + } + + /// Inline assembly. + /// + /// Read the [unstable book] for the usage. + /// + /// [unstable book]: ../unstable-book/library-features/asm.html + #[cfg(not(bootstrap))] + #[unstable( + feature = "llvm_asm", + issue = "70173", + reason = "inline assembly is not stable enough for use and is subject to change" + )] + #[rustc_builtin_macro] + #[macro_export] + macro_rules! llvm_asm { + ("assembly template" + : $("output"(operand),)* + : $("input"(operand),)* + : $("clobbers",)* + : $("options",)*) => { + /* compiler built-in */ + }; + } + /// Module-level inline assembly. #[unstable( feature = "global_asm", diff --git a/src/libcore/num/dec2flt/algorithm.rs b/src/libcore/num/dec2flt/algorithm.rs index c5f6903f379..aaeb4d8a22c 100644 --- a/src/libcore/num/dec2flt/algorithm.rs +++ b/src/libcore/num/dec2flt/algorithm.rs @@ -60,7 +60,7 @@ mod fpu_precision { fn set_cw(cw: u16) { // SAFETY: the `fldcw` instruction has been audited to be able to work correctly with // any `u16` - unsafe { asm!("fldcw $0" :: "m" (cw) :: "volatile") } + unsafe { llvm_asm!("fldcw $0" :: "m" (cw) :: "volatile") } } /// Sets the precision field of the FPU to `T` and returns a `FPUControlWord`. @@ -78,7 +78,7 @@ mod fpu_precision { // `FPUControlWord` structure is dropped // SAFETY: the `fnstcw` instruction has been audited to be able to work correctly with // any `u16` - unsafe { asm!("fnstcw $0" : "=*m" (&cw) ::: "volatile") } + unsafe { llvm_asm!("fnstcw $0" : "=*m" (&cw) ::: "volatile") } // Set the control word to the desired precision. This is achieved by masking away the old // precision (bits 8 and 9, 0x300) and replacing it with the precision flag computed above. diff --git a/src/libcore/prelude/v1.rs b/src/libcore/prelude/v1.rs index c91370b2719..9b4ed4e8205 100644 --- a/src/libcore/prelude/v1.rs +++ b/src/libcore/prelude/v1.rs @@ -57,8 +57,8 @@ pub use crate::hash::macros::Hash; #[doc(no_inline)] pub use crate::{ asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, - format_args_nl, global_asm, include, include_bytes, include_str, line, log_syntax, module_path, - option_env, stringify, trace_macros, + format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, log_syntax, + module_path, option_env, stringify, trace_macros, }; #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 1e47317cf1a..9ba9d816d0f 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1584,7 +1584,7 @@ pub enum StatementKind<'tcx> { /// Executes a piece of inline Assembly. Stored in a Box to keep the size /// of `StatementKind` low. - InlineAsm(Box<InlineAsm<'tcx>>), + LlvmInlineAsm(Box<LlvmInlineAsm<'tcx>>), /// Retag references in the given place, ensuring they got fresh tags. This is /// part of the Stacked Borrows model. These statements are currently only interpreted @@ -1668,8 +1668,8 @@ pub enum FakeReadCause { } #[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)] -pub struct InlineAsm<'tcx> { - pub asm: hir::InlineAsmInner, +pub struct LlvmInlineAsm<'tcx> { + pub asm: hir::LlvmInlineAsmInner, pub outputs: Box<[Place<'tcx>]>, pub inputs: Box<[(Span, Operand<'tcx>)]>, } @@ -1696,8 +1696,8 @@ impl Debug for Statement<'_> { SetDiscriminant { ref place, variant_index } => { write!(fmt, "discriminant({:?}) = {:?}", place, variant_index) } - InlineAsm(ref asm) => { - write!(fmt, "asm!({:?} : {:?} : {:?})", asm.asm, asm.outputs, asm.inputs) + LlvmInlineAsm(ref asm) => { + write!(fmt, "llvm_asm!({:?} : {:?} : {:?})", asm.asm, asm.outputs, asm.inputs) } AscribeUserType(box (ref place, ref c_ty), ref variance) => { write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty) diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 2aca6f684f4..c1b27b40f7d 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -385,7 +385,7 @@ macro_rules! make_mir_visitor { location ); } - StatementKind::InlineAsm(asm) => { + StatementKind::LlvmInlineAsm(asm) => { for output in & $($mutability)? asm.outputs[..] { self.visit_place( output, diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 81be5b11143..429791d09a4 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -263,7 +263,7 @@ CloneTypeFoldableAndLiftImpls! { ::rustc_span::symbol::Symbol, ::rustc_hir::def::Res, ::rustc_hir::def_id::DefId, - ::rustc_hir::InlineAsmInner, + ::rustc_hir::LlvmInlineAsmInner, ::rustc_hir::MatchSource, ::rustc_hir::Mutability, ::rustc_hir::Unsafety, diff --git a/src/librustc_ast/ast.rs b/src/librustc_ast/ast.rs index 3e7fb0e73bf..646294a7cca 100644 --- a/src/librustc_ast/ast.rs +++ b/src/librustc_ast/ast.rs @@ -1114,7 +1114,7 @@ impl Expr { ExprKind::Break(..) => ExprPrecedence::Break, ExprKind::Continue(..) => ExprPrecedence::Continue, ExprKind::Ret(..) => ExprPrecedence::Ret, - ExprKind::InlineAsm(..) => ExprPrecedence::InlineAsm, + ExprKind::LlvmInlineAsm(..) => ExprPrecedence::InlineAsm, ExprKind::MacCall(..) => ExprPrecedence::Mac, ExprKind::Struct(..) => ExprPrecedence::Struct, ExprKind::Repeat(..) => ExprPrecedence::Repeat, @@ -1243,8 +1243,8 @@ pub enum ExprKind { /// A `return`, with an optional value to be returned. Ret(Option<P<Expr>>), - /// Output of the `asm!()` macro. - InlineAsm(P<InlineAsm>), + /// Output of the `llvm_asm!()` macro. + LlvmInlineAsm(P<LlvmInlineAsm>), /// A macro invocation; pre-expansion. MacCall(MacCall), @@ -1860,37 +1860,37 @@ pub enum TraitObjectSyntax { /// Inline assembly dialect. /// -/// E.g., `"intel"` as in `asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`. +/// E.g., `"intel"` as in `llvm_asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`. #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] -pub enum AsmDialect { +pub enum LlvmAsmDialect { Att, Intel, } -/// Inline assembly. +/// LLVM-style inline assembly. /// -/// E.g., `"={eax}"(result)` as in `asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`. +/// E.g., `"={eax}"(result)` as in `llvm_asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct InlineAsmOutput { +pub struct LlvmInlineAsmOutput { pub constraint: Symbol, pub expr: P<Expr>, pub is_rw: bool, pub is_indirect: bool, } -/// Inline assembly. +/// LLVM-style inline assembly. /// -/// E.g., `asm!("NOP");`. +/// E.g., `llvm_asm!("NOP");`. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct InlineAsm { +pub struct LlvmInlineAsm { pub asm: Symbol, pub asm_str_style: StrStyle, - pub outputs: Vec<InlineAsmOutput>, + pub outputs: Vec<LlvmInlineAsmOutput>, pub inputs: Vec<(Symbol, P<Expr>)>, pub clobbers: Vec<Symbol>, pub volatile: bool, pub alignstack: bool, - pub dialect: AsmDialect, + pub dialect: LlvmAsmDialect, } /// A parameter in a function header. diff --git a/src/librustc_ast/mut_visit.rs b/src/librustc_ast/mut_visit.rs index aa2968b3cbe..67f7764d5bb 100644 --- a/src/librustc_ast/mut_visit.rs +++ b/src/librustc_ast/mut_visit.rs @@ -1202,8 +1202,8 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { kind, id, span, attrs }: &mut Expr, ExprKind::Ret(expr) => { visit_opt(expr, |expr| vis.visit_expr(expr)); } - ExprKind::InlineAsm(asm) => { - let InlineAsm { + ExprKind::LlvmInlineAsm(asm) => { + let LlvmInlineAsm { asm: _, asm_str_style: _, outputs, @@ -1214,7 +1214,7 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { kind, id, span, attrs }: &mut Expr, dialect: _, } = asm.deref_mut(); for out in outputs { - let InlineAsmOutput { constraint: _, expr, is_rw: _, is_indirect: _ } = out; + let LlvmInlineAsmOutput { constraint: _, expr, is_rw: _, is_indirect: _ } = out; vis.visit_expr(expr); } visit_vec(inputs, |(_c, expr)| vis.visit_expr(expr)); diff --git a/src/librustc_ast/visit.rs b/src/librustc_ast/visit.rs index 39028b7583c..cc2b1c48b51 100644 --- a/src/librustc_ast/visit.rs +++ b/src/librustc_ast/visit.rs @@ -813,7 +813,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { } ExprKind::MacCall(ref mac) => visitor.visit_mac(mac), ExprKind::Paren(ref subexpression) => visitor.visit_expr(subexpression), - ExprKind::InlineAsm(ref ia) => { + ExprKind::LlvmInlineAsm(ref ia) => { for &(_, ref input) in &ia.inputs { visitor.visit_expr(input) } diff --git a/src/librustc_ast_lowering/expr.rs b/src/librustc_ast_lowering/expr.rs index 239dec9e974..9984eb4e282 100644 --- a/src/librustc_ast_lowering/expr.rs +++ b/src/librustc_ast_lowering/expr.rs @@ -159,7 +159,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let e = e.as_ref().map(|x| self.lower_expr(x)); hir::ExprKind::Ret(e) } - ExprKind::InlineAsm(ref asm) => self.lower_expr_asm(asm), + ExprKind::LlvmInlineAsm(ref asm) => self.lower_expr_asm(asm), ExprKind::Struct(ref path, ref fields, ref maybe_expr) => { let maybe_expr = maybe_expr.as_ref().map(|x| self.lower_expr(x)); hir::ExprKind::Struct( @@ -952,13 +952,13 @@ impl<'hir> LoweringContext<'_, 'hir> { result } - fn lower_expr_asm(&mut self, asm: &InlineAsm) -> hir::ExprKind<'hir> { - let inner = hir::InlineAsmInner { + fn lower_expr_asm(&mut self, asm: &LlvmInlineAsm) -> hir::ExprKind<'hir> { + let inner = hir::LlvmInlineAsmInner { inputs: asm.inputs.iter().map(|&(c, _)| c).collect(), outputs: asm .outputs .iter() - .map(|out| hir::InlineAsmOutput { + .map(|out| hir::LlvmInlineAsmOutput { constraint: out.constraint, is_rw: out.is_rw, is_indirect: out.is_indirect, @@ -972,7 +972,7 @@ impl<'hir> LoweringContext<'_, 'hir> { alignstack: asm.alignstack, dialect: asm.dialect, }; - let hir_asm = hir::InlineAsm { + let hir_asm = hir::LlvmInlineAsm { inner, inputs_exprs: self.arena.alloc_from_iter( asm.inputs.iter().map(|&(_, ref input)| self.lower_expr_mut(input)), @@ -981,7 +981,7 @@ impl<'hir> LoweringContext<'_, 'hir> { .arena .alloc_from_iter(asm.outputs.iter().map(|out| self.lower_expr_mut(&out.expr))), }; - hir::ExprKind::InlineAsm(self.arena.alloc(hir_asm)) + hir::ExprKind::LlvmInlineAsm(self.arena.alloc(hir_asm)) } fn lower_field(&mut self, f: &Field) -> hir::Field<'hir> { diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index d6d1153f279..885f2f939a6 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -716,12 +716,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> { fn visit_expr(&mut self, expr: &'a Expr) { match &expr.kind { - ExprKind::InlineAsm(..) if !self.session.target.target.options.allow_asm => { + ExprKind::LlvmInlineAsm(..) if !self.session.target.target.options.allow_asm => { struct_span_err!( self.session, expr.span, E0472, - "asm! is unsupported on this target" + "llvm_asm! is unsupported on this target" ) .emit(); } diff --git a/src/librustc_ast_pretty/pprust.rs b/src/librustc_ast_pretty/pprust.rs index bb73e982a9c..2d6932ffbee 100644 --- a/src/librustc_ast_pretty/pprust.rs +++ b/src/librustc_ast_pretty/pprust.rs @@ -2024,8 +2024,8 @@ impl<'a> State<'a> { self.print_expr_maybe_paren(expr, parser::PREC_JUMP); } } - ast::ExprKind::InlineAsm(ref a) => { - self.s.word("asm!"); + ast::ExprKind::LlvmInlineAsm(ref a) => { + self.s.word("llvm_asm!"); self.popen(); self.print_string(&a.asm.as_str(), a.asm_str_style); self.word_space(":"); @@ -2066,7 +2066,7 @@ impl<'a> State<'a> { if a.alignstack { options.push("alignstack"); } - if a.dialect == ast::AsmDialect::Intel { + if a.dialect == ast::LlvmAsmDialect::Intel { options.push("intel"); } diff --git a/src/librustc_builtin_macros/lib.rs b/src/librustc_builtin_macros/lib.rs index 26a59c6b1be..caed0bf7a08 100644 --- a/src/librustc_builtin_macros/lib.rs +++ b/src/librustc_builtin_macros/lib.rs @@ -19,7 +19,6 @@ use rustc_expand::proc_macro::BangProcMacro; use rustc_span::edition::Edition; use rustc_span::symbol::sym; -mod asm; mod assert; mod cfg; mod cfg_accessible; @@ -32,6 +31,7 @@ mod format; mod format_foreign; mod global_allocator; mod global_asm; +mod llvm_asm; mod log_syntax; mod source_util; mod test; @@ -61,7 +61,7 @@ pub fn register_builtin_macros(resolver: &mut dyn Resolver, edition: Edition) { } register_bang! { - asm: asm::expand_asm, + asm: llvm_asm::expand_llvm_asm, assert: assert::expand_assert, cfg: cfg::expand_cfg, column: source_util::expand_column, @@ -77,6 +77,7 @@ pub fn register_builtin_macros(resolver: &mut dyn Resolver, edition: Edition) { include_str: source_util::expand_include_str, include: source_util::expand_include, line: source_util::expand_line, + llvm_asm: llvm_asm::expand_llvm_asm, log_syntax: log_syntax::expand_log_syntax, module_path: source_util::expand_mod, option_env: env::expand_option_env, diff --git a/src/librustc_builtin_macros/asm.rs b/src/librustc_builtin_macros/llvm_asm.rs index 9811a6621af..88756f533d4 100644 --- a/src/librustc_builtin_macros/asm.rs +++ b/src/librustc_builtin_macros/llvm_asm.rs @@ -1,8 +1,8 @@ -// Inline assembly support. +// Llvm-style inline assembly support. // use State::*; -use rustc_ast::ast::{self, AsmDialect}; +use rustc_ast::ast::{self, LlvmAsmDialect}; use rustc_ast::ptr::P; use rustc_ast::token::{self, Token}; use rustc_ast::tokenstream::{self, TokenStream}; @@ -36,7 +36,7 @@ impl State { const OPTIONS: &[Symbol] = &[sym::volatile, sym::alignstack, sym::intel]; -pub fn expand_asm<'cx>( +pub fn expand_llvm_asm<'cx>( cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream, @@ -58,7 +58,7 @@ pub fn expand_asm<'cx>( MacEager::expr(P(ast::Expr { id: ast::DUMMY_NODE_ID, - kind: ast::ExprKind::InlineAsm(P(inline_asm)), + kind: ast::ExprKind::LlvmInlineAsm(P(inline_asm)), span: cx.with_def_site_ctxt(sp), attrs: ast::AttrVec::new(), })) @@ -80,9 +80,9 @@ fn parse_inline_asm<'a>( cx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream, -) -> Result<Option<ast::InlineAsm>, DiagnosticBuilder<'a>> { - // Split the tts before the first colon, to avoid `asm!("x": y)` being - // parsed as `asm!(z)` with `z = "x": y` which is type ascription. +) -> Result<Option<ast::LlvmInlineAsm>, DiagnosticBuilder<'a>> { + // Split the tts before the first colon, to avoid `llvm_asm!("x": y)` being + // parsed as `llvm_asm!(z)` with `z = "x": y` which is type ascription. let first_colon = tts .trees() .position(|tt| match tt { @@ -99,7 +99,7 @@ fn parse_inline_asm<'a>( let mut clobs = Vec::new(); let mut volatile = false; let mut alignstack = false; - let mut dialect = AsmDialect::Att; + let mut dialect = LlvmAsmDialect::Att; let mut state = Asm; @@ -183,7 +183,7 @@ fn parse_inline_asm<'a>( let is_rw = output.is_some(); let is_indirect = constraint_str.contains('*'); - outputs.push(ast::InlineAsmOutput { + outputs.push(ast::LlvmInlineAsmOutput { constraint: output.unwrap_or(constraint), expr, is_rw, @@ -257,7 +257,7 @@ fn parse_inline_asm<'a>( } else if option == sym::alignstack { alignstack = true; } else if option == sym::intel { - dialect = AsmDialect::Intel; + dialect = LlvmAsmDialect::Intel; } else { cx.span_warn(p.prev_token.span, "unrecognized option"); } @@ -287,7 +287,7 @@ fn parse_inline_asm<'a>( } } - Ok(Some(ast::InlineAsm { + Ok(Some(ast::LlvmInlineAsm { asm, asm_str_style: asm_str_style.unwrap(), outputs, diff --git a/src/librustc_codegen_llvm/asm.rs b/src/librustc_codegen_llvm/asm.rs index 6edc3d5ecd4..30bf3ce7528 100644 --- a/src/librustc_codegen_llvm/asm.rs +++ b/src/librustc_codegen_llvm/asm.rs @@ -14,9 +14,9 @@ use libc::{c_char, c_uint}; use log::debug; impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { - fn codegen_inline_asm( + fn codegen_llvm_inline_asm( &mut self, - ia: &hir::InlineAsmInner, + ia: &hir::LlvmInlineAsmInner, outputs: Vec<PlaceRef<'tcx, &'ll Value>>, mut inputs: Vec<&'ll Value>, span: Span, @@ -138,7 +138,7 @@ fn inline_asm_call( output: &'ll llvm::Type, volatile: bool, alignstack: bool, - dia: ::rustc_ast::ast::AsmDialect, + dia: ::rustc_ast::ast::LlvmAsmDialect, ) -> Option<&'ll Value> { let volatile = if volatile { llvm::True } else { llvm::False }; let alignstack = if alignstack { llvm::True } else { llvm::False }; diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index 69881e2149b..1d61d95cc6b 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -389,10 +389,10 @@ pub enum AsmDialect { } impl AsmDialect { - pub fn from_generic(asm: rustc_ast::ast::AsmDialect) -> Self { + pub fn from_generic(asm: rustc_ast::ast::LlvmAsmDialect) -> Self { match asm { - rustc_ast::ast::AsmDialect::Att => AsmDialect::Att, - rustc_ast::ast::AsmDialect::Intel => AsmDialect::Intel, + rustc_ast::ast::LlvmAsmDialect::Att => AsmDialect::Att, + rustc_ast::ast::LlvmAsmDialect::Intel => AsmDialect::Intel, } } } diff --git a/src/librustc_codegen_ssa/mir/statement.rs b/src/librustc_codegen_ssa/mir/statement.rs index e68b41ad188..5edd9b9f0a0 100644 --- a/src/librustc_codegen_ssa/mir/statement.rs +++ b/src/librustc_codegen_ssa/mir/statement.rs @@ -66,7 +66,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } bx } - mir::StatementKind::InlineAsm(ref asm) => { + mir::StatementKind::LlvmInlineAsm(ref asm) => { let outputs = asm .outputs .iter() @@ -93,7 +93,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ); if input_vals.len() == asm.inputs.len() { - let res = bx.codegen_inline_asm( + let res = bx.codegen_llvm_inline_asm( &asm.asm, outputs, input_vals, diff --git a/src/librustc_codegen_ssa/traits/asm.rs b/src/librustc_codegen_ssa/traits/asm.rs index d31b063232c..1cdfd3ae356 100644 --- a/src/librustc_codegen_ssa/traits/asm.rs +++ b/src/librustc_codegen_ssa/traits/asm.rs @@ -1,13 +1,13 @@ use super::BackendTypes; use crate::mir::place::PlaceRef; -use rustc_hir::{GlobalAsm, InlineAsmInner}; +use rustc_hir::{GlobalAsm, LlvmInlineAsmInner}; use rustc_span::Span; pub trait AsmBuilderMethods<'tcx>: BackendTypes { /// Take an inline assembly expression and splat it out via LLVM - fn codegen_inline_asm( + fn codegen_llvm_inline_asm( &mut self, - ia: &InlineAsmInner, + ia: &LlvmInlineAsmInner, outputs: Vec<PlaceRef<'tcx, Self::Value>>, inputs: Vec<Self::Value>, span: Span, diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index fdcf3d63957..fe68e9eacbf 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -541,7 +541,7 @@ E0751: include_str!("./error_codes/E0751.md"), // E0467, removed // E0470, removed // E0471, // constant evaluation error (in pattern) - E0472, // asm! is unsupported on this target + E0472, // llvm_asm! is unsupported on this target E0473, // dereference of reference outside its lifetime E0474, // captured variable `..` does not outlive the enclosing closure E0475, // index of slice outside its lifetime diff --git a/src/librustc_error_codes/error_codes/E0660.md b/src/librustc_error_codes/error_codes/E0660.md index 189459175dc..732de6a3818 100644 --- a/src/librustc_error_codes/error_codes/E0660.md +++ b/src/librustc_error_codes/error_codes/E0660.md @@ -1,9 +1,9 @@ -The argument to the `asm` macro is not well-formed. +The argument to the `llvm_asm` macro is not well-formed. Erroneous code example: ```compile_fail,E0660 -asm!("nop" "nop"); +llvm_asm!("nop" "nop"); ``` Considering that this would be a long explanation, we instead recommend you diff --git a/src/librustc_error_codes/error_codes/E0661.md b/src/librustc_error_codes/error_codes/E0661.md index b171ada6205..3d5cd90f6a3 100644 --- a/src/librustc_error_codes/error_codes/E0661.md +++ b/src/librustc_error_codes/error_codes/E0661.md @@ -1,10 +1,10 @@ -An invalid syntax was passed to the second argument of an `asm` macro line. +An invalid syntax was passed to the second argument of an `llvm_asm` macro line. Erroneous code example: ```compile_fail,E0661 let a; -asm!("nop" : "r"(a)); +llvm_asm!("nop" : "r"(a)); ``` Considering that this would be a long explanation, we instead recommend you diff --git a/src/librustc_error_codes/error_codes/E0662.md b/src/librustc_error_codes/error_codes/E0662.md index c15e736610b..9858abd10c5 100644 --- a/src/librustc_error_codes/error_codes/E0662.md +++ b/src/librustc_error_codes/error_codes/E0662.md @@ -1,12 +1,13 @@ -An invalid input operand constraint was passed to the `asm` macro (third line). +An invalid input operand constraint was passed to the `llvm_asm` macro +(third line). Erroneous code example: ```compile_fail,E0662 -asm!("xor %eax, %eax" - : - : "=test"("a") - ); +llvm_asm!("xor %eax, %eax" + : + : "=test"("a") + ); ``` Considering that this would be a long explanation, we instead recommend you diff --git a/src/librustc_error_codes/error_codes/E0663.md b/src/librustc_error_codes/error_codes/E0663.md index bd450230ec3..36b87be7d6e 100644 --- a/src/librustc_error_codes/error_codes/E0663.md +++ b/src/librustc_error_codes/error_codes/E0663.md @@ -1,12 +1,13 @@ -An invalid input operand constraint was passed to the `asm` macro (third line). +An invalid input operand constraint was passed to the `llvm_asm` macro +(third line). Erroneous code example: ```compile_fail,E0663 -asm!("xor %eax, %eax" - : - : "+test"("a") - ); +llvm_asm!("xor %eax, %eax" + : + : "+test"("a") + ); ``` Considering that this would be a long explanation, we instead recommend you diff --git a/src/librustc_error_codes/error_codes/E0664.md b/src/librustc_error_codes/error_codes/E0664.md index 768ffdf2de9..33924b14e6d 100644 --- a/src/librustc_error_codes/error_codes/E0664.md +++ b/src/librustc_error_codes/error_codes/E0664.md @@ -1,13 +1,13 @@ -A clobber was surrounded by braces in the `asm` macro. +A clobber was surrounded by braces in the `llvm_asm` macro. Erroneous code example: ```compile_fail,E0664 -asm!("mov $$0x200, %eax" - : - : - : "{eax}" - ); +llvm_asm!("mov $$0x200, %eax" + : + : + : "{eax}" + ); ``` Considering that this would be a long explanation, we instead recommend you diff --git a/src/librustc_error_codes/error_codes/E0668.md b/src/librustc_error_codes/error_codes/E0668.md index f5d26244fb9..5d7c4cda05b 100644 --- a/src/librustc_error_codes/error_codes/E0668.md +++ b/src/librustc_error_codes/error_codes/E0668.md @@ -12,7 +12,7 @@ constraint (see issue #51430): fn main() { let rax: u64; unsafe { - asm!("" :"={rax"(rax)); + llvm_asm!("" :"={rax"(rax)); println!("Accumulator is: {}", rax); } } diff --git a/src/librustc_hir/arena.rs b/src/librustc_hir/arena.rs index 978565a4c39..b8a691dd981 100644 --- a/src/librustc_hir/arena.rs +++ b/src/librustc_hir/arena.rs @@ -28,7 +28,7 @@ macro_rules! arena_types { [] fn_decl: rustc_hir::FnDecl<$tcx>, [] foreign_item: rustc_hir::ForeignItem<$tcx>, [] impl_item_ref: rustc_hir::ImplItemRef<$tcx>, - [] inline_asm: rustc_hir::InlineAsm<$tcx>, + [] inline_asm: rustc_hir::LlvmInlineAsm<$tcx>, [] local: rustc_hir::Local<$tcx>, [few] macro_def: rustc_hir::MacroDef<$tcx>, [] param: rustc_hir::Param<$tcx>, diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs index bb864edc999..4051febbd58 100644 --- a/src/librustc_hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -8,7 +8,7 @@ crate use BlockCheckMode::*; crate use FnRetTy::*; crate use UnsafeSource::*; -use rustc_ast::ast::{self, AsmDialect, CrateSugar, Ident, Name}; +use rustc_ast::ast::{self, CrateSugar, Ident, LlvmAsmDialect, Name}; use rustc_ast::ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy}; pub use rustc_ast::ast::{BorrowKind, ImplPolarity, IsAuto}; pub use rustc_ast::ast::{CaptureBy, Movability, Mutability}; @@ -1389,7 +1389,7 @@ impl Expr<'_> { ExprKind::Break(..) => ExprPrecedence::Break, ExprKind::Continue(..) => ExprPrecedence::Continue, ExprKind::Ret(..) => ExprPrecedence::Ret, - ExprKind::InlineAsm(..) => ExprPrecedence::InlineAsm, + ExprKind::LlvmInlineAsm(..) => ExprPrecedence::InlineAsm, ExprKind::Struct(..) => ExprPrecedence::Struct, ExprKind::Repeat(..) => ExprPrecedence::Repeat, ExprKind::Yield(..) => ExprPrecedence::Yield, @@ -1444,7 +1444,7 @@ impl Expr<'_> { | ExprKind::Ret(..) | ExprKind::Loop(..) | ExprKind::Assign(..) - | ExprKind::InlineAsm(..) + | ExprKind::LlvmInlineAsm(..) | ExprKind::AssignOp(..) | ExprKind::Lit(_) | ExprKind::Unary(..) @@ -1631,8 +1631,8 @@ pub enum ExprKind<'hir> { /// A `return`, with an optional value to be returned. Ret(Option<&'hir Expr<'hir>>), - /// Inline assembly (from `asm!`), with its outputs and inputs. - InlineAsm(&'hir InlineAsm<'hir>), + /// Inline assembly (from `llvm_asm!`), with its outputs and inputs. + LlvmInlineAsm(&'hir LlvmInlineAsm<'hir>), /// A struct or struct-like variant literal expression. /// @@ -2061,7 +2061,7 @@ pub enum TyKind<'hir> { } #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic, PartialEq)] -pub struct InlineAsmOutput { +pub struct LlvmInlineAsmOutput { pub constraint: Symbol, pub is_rw: bool, pub is_indirect: bool, @@ -2071,20 +2071,20 @@ pub struct InlineAsmOutput { // NOTE(eddyb) This is used within MIR as well, so unlike the rest of the HIR, // it needs to be `Clone` and use plain `Vec<T>` instead of arena-allocated slice. #[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic, PartialEq)] -pub struct InlineAsmInner { +pub struct LlvmInlineAsmInner { pub asm: Symbol, pub asm_str_style: StrStyle, - pub outputs: Vec<InlineAsmOutput>, + pub outputs: Vec<LlvmInlineAsmOutput>, pub inputs: Vec<Symbol>, pub clobbers: Vec<Symbol>, pub volatile: bool, pub alignstack: bool, - pub dialect: AsmDialect, + pub dialect: LlvmAsmDialect, } #[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] -pub struct InlineAsm<'hir> { - pub inner: InlineAsmInner, +pub struct LlvmInlineAsm<'hir> { + pub inner: LlvmInlineAsmInner, pub outputs_exprs: &'hir [Expr<'hir>], pub inputs_exprs: &'hir [Expr<'hir>], } diff --git a/src/librustc_hir/intravisit.rs b/src/librustc_hir/intravisit.rs index 11749cf996b..7b8c9e2a4a2 100644 --- a/src/librustc_hir/intravisit.rs +++ b/src/librustc_hir/intravisit.rs @@ -1151,7 +1151,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) ExprKind::Ret(ref optional_expression) => { walk_list!(visitor, visit_expr, optional_expression); } - ExprKind::InlineAsm(ref asm) => { + ExprKind::LlvmInlineAsm(ref asm) => { walk_list!(visitor, visit_expr, asm.outputs_exprs); walk_list!(visitor, visit_expr, asm.inputs_exprs); } diff --git a/src/librustc_hir/print.rs b/src/librustc_hir/print.rs index cd16e451f1d..8df3b6dc669 100644 --- a/src/librustc_hir/print.rs +++ b/src/librustc_hir/print.rs @@ -1388,9 +1388,9 @@ impl<'a> State<'a> { self.print_expr_maybe_paren(&expr, parser::PREC_JUMP); } } - hir::ExprKind::InlineAsm(ref a) => { + hir::ExprKind::LlvmInlineAsm(ref a) => { let i = &a.inner; - self.s.word("asm!"); + self.s.word("llvm_asm!"); self.popen(); self.print_string(&i.asm.as_str(), i.asm_str_style); self.word_space(":"); @@ -1435,7 +1435,7 @@ impl<'a> State<'a> { if i.alignstack { options.push("alignstack"); } - if i.dialect == ast::AsmDialect::Intel { + if i.dialect == ast::LlvmAsmDialect::Intel { options.push("intel"); } diff --git a/src/librustc_mir/borrow_check/invalidation.rs b/src/librustc_mir/borrow_check/invalidation.rs index d33639aa9d9..3d1768cf0e5 100644 --- a/src/librustc_mir/borrow_check/invalidation.rs +++ b/src/librustc_mir/borrow_check/invalidation.rs @@ -68,7 +68,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> { StatementKind::SetDiscriminant { ref place, variant_index: _ } => { self.mutate_place(location, place, Shallow(None), JustWrite); } - StatementKind::InlineAsm(ref asm) => { + StatementKind::LlvmInlineAsm(ref asm) => { for (o, output) in asm.asm.outputs.iter().zip(asm.outputs.iter()) { if o.is_indirect { // FIXME(eddyb) indirect inline asm outputs should diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 6c1901455fd..91516887cf7 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -550,7 +550,7 @@ impl<'cx, 'tcx> dataflow::generic::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt StatementKind::SetDiscriminant { ref place, variant_index: _ } => { self.mutate_place(location, (place, span), Shallow(None), JustWrite, flow_state); } - StatementKind::InlineAsm(ref asm) => { + StatementKind::LlvmInlineAsm(ref asm) => { for (o, output) in asm.asm.outputs.iter().zip(asm.outputs.iter()) { if o.is_indirect { // FIXME(eddyb) indirect inline asm outputs should diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index f94160cc08a..289f147a387 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -1529,7 +1529,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { StatementKind::FakeRead(..) | StatementKind::StorageLive(..) | StatementKind::StorageDead(..) - | StatementKind::InlineAsm { .. } + | StatementKind::LlvmInlineAsm { .. } | StatementKind::Retag { .. } | StatementKind::Nop => {} } diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index a7c0efd63b1..4c46ac36f2a 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -289,7 +289,7 @@ impl<'tcx> generic::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> { self.kill_borrows_on_place(trans, &Place::from(local)); } - mir::StatementKind::InlineAsm(ref asm) => { + mir::StatementKind::LlvmInlineAsm(ref asm) => { for (output, kind) in asm.outputs.iter().zip(&asm.asm.outputs) { if !kind.is_indirect && !kind.is_rw { self.kill_borrows_on_place(trans, output); diff --git a/src/librustc_mir/dataflow/impls/storage_liveness.rs b/src/librustc_mir/dataflow/impls/storage_liveness.rs index 5341d661b1d..3f50866b590 100644 --- a/src/librustc_mir/dataflow/impls/storage_liveness.rs +++ b/src/librustc_mir/dataflow/impls/storage_liveness.rs @@ -124,7 +124,7 @@ impl<'mir, 'tcx> dataflow::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'mir, | StatementKind::SetDiscriminant { box place, .. } => { trans.gen(place.local); } - StatementKind::InlineAsm(asm) => { + StatementKind::LlvmInlineAsm(asm) => { for place in &*asm.outputs { trans.gen(place.local); } diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index 276aabec13d..8061765f66d 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -295,7 +295,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { StatementKind::FakeRead(_, ref place) => { self.create_move_path(place); } - StatementKind::InlineAsm(ref asm) => { + StatementKind::LlvmInlineAsm(ref asm) => { for (output, kind) in asm.outputs.iter().zip(&asm.asm.outputs) { if !kind.is_indirect { self.gather_init(output.as_ref(), InitKind::Deep); diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs index 6ec11d42f52..01446c15ff6 100644 --- a/src/librustc_mir/interpret/step.rs +++ b/src/librustc_mir/interpret/step.rs @@ -124,7 +124,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // size of MIR constantly. Nop => {} - InlineAsm { .. } => throw_unsup_format!("inline assembly is not supported"), + LlvmInlineAsm { .. } => throw_unsup_format!("inline assembly is not supported"), } self.stack[frame_idx].stmt += 1; diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index be461c0e03d..67ded01779b 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -488,7 +488,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> { StatementKind::FakeRead(..) | StatementKind::StorageLive(_) | StatementKind::StorageDead(_) - | StatementKind::InlineAsm { .. } + | StatementKind::LlvmInlineAsm { .. } | StatementKind::Retag { .. } | StatementKind::AscribeUserType(..) | StatementKind::Nop => {} diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 3ba60e69041..7d5f2860728 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -106,7 +106,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { // safe (at least as emitted during MIR construction) } - StatementKind::InlineAsm { .. } => self.require_unsafe( + StatementKind::LlvmInlineAsm { .. } => self.require_unsafe( "use of inline assembly", "inline assembly is entirely unchecked and can cause undefined behavior", UnsafetyViolationKind::General, diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 5a99ee27301..b2d21d7a84b 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -230,7 +230,7 @@ fn check_statement( // just an assignment StatementKind::SetDiscriminant { place, .. } => check_place(tcx, place, span, def_id, body), - StatementKind::InlineAsm { .. } => { + StatementKind::LlvmInlineAsm { .. } => { Err((span, "cannot use inline assembly in const fn".into())) } diff --git a/src/librustc_mir/transform/remove_noop_landing_pads.rs b/src/librustc_mir/transform/remove_noop_landing_pads.rs index 7ac9eccf46f..91f8b7b1c85 100644 --- a/src/librustc_mir/transform/remove_noop_landing_pads.rs +++ b/src/librustc_mir/transform/remove_noop_landing_pads.rs @@ -52,7 +52,7 @@ impl RemoveNoopLandingPads { StatementKind::Assign { .. } | StatementKind::SetDiscriminant { .. } - | StatementKind::InlineAsm { .. } + | StatementKind::LlvmInlineAsm { .. } | StatementKind::Retag { .. } => { return false; } diff --git a/src/librustc_mir/transform/simplify_try.rs b/src/librustc_mir/transform/simplify_try.rs index 3f28f033047..1c5f6762c68 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -172,7 +172,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyBranchSame { // so we cannot assume that the `unreachable` terminator itself is reachable. // FIXME(Centril): use a normalization pass instead of a check. || bb.statements.iter().any(|stmt| match stmt.kind { - StatementKind::InlineAsm(..) => true, + StatementKind::LlvmInlineAsm(..) => true, _ => false, }) }) diff --git a/src/librustc_mir/transform/unreachable_prop.rs b/src/librustc_mir/transform/unreachable_prop.rs index 27173e0c171..c5c84acb6b2 100644 --- a/src/librustc_mir/transform/unreachable_prop.rs +++ b/src/librustc_mir/transform/unreachable_prop.rs @@ -29,7 +29,7 @@ impl MirPass<'_> for UnreachablePropagation { // Accompanying testcases: mir-opt/unreachable_asm.rs and mir-opt/unreachable_asm_2.rs let asm_stmt_in_block = || { bb_data.statements.iter().any(|stmt: &Statement<'_>| match stmt.kind { - StatementKind::InlineAsm(..) => true, + StatementKind::LlvmInlineAsm(..) => true, _ => false, }) }; diff --git a/src/librustc_mir_build/build/expr/as_place.rs b/src/librustc_mir_build/build/expr/as_place.rs index d77cc49c94f..8fa7bc76990 100644 --- a/src/librustc_mir_build/build/expr/as_place.rs +++ b/src/librustc_mir_build/build/expr/as_place.rs @@ -255,7 +255,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::Return { .. } | ExprKind::Literal { .. } | ExprKind::StaticRef { .. } - | ExprKind::InlineAsm { .. } + | ExprKind::LlvmInlineAsm { .. } | ExprKind::Yield { .. } | ExprKind::Call { .. } => { // these are not places, so we need to make a temporary. diff --git a/src/librustc_mir_build/build/expr/as_rvalue.rs b/src/librustc_mir_build/build/expr/as_rvalue.rs index dc97f321a36..4c7ff504722 100644 --- a/src/librustc_mir_build/build/expr/as_rvalue.rs +++ b/src/librustc_mir_build/build/expr/as_rvalue.rs @@ -251,7 +251,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::Break { .. } | ExprKind::Continue { .. } | ExprKind::Return { .. } - | ExprKind::InlineAsm { .. } + | ExprKind::LlvmInlineAsm { .. } | ExprKind::PlaceTypeAscription { .. } | ExprKind::ValueTypeAscription { .. } => { // these do not have corresponding `Rvalue` variants, diff --git a/src/librustc_mir_build/build/expr/category.rs b/src/librustc_mir_build/build/expr/category.rs index cc139dee63f..f8cae205453 100644 --- a/src/librustc_mir_build/build/expr/category.rs +++ b/src/librustc_mir_build/build/expr/category.rs @@ -64,7 +64,7 @@ impl Category { | ExprKind::Repeat { .. } | ExprKind::Assign { .. } | ExprKind::AssignOp { .. } - | ExprKind::InlineAsm { .. } => Some(Category::Rvalue(RvalueFunc::AsRvalue)), + | ExprKind::LlvmInlineAsm { .. } => Some(Category::Rvalue(RvalueFunc::AsRvalue)), ExprKind::Literal { .. } | ExprKind::StaticRef { .. } => Some(Category::Constant), diff --git a/src/librustc_mir_build/build/expr/into.rs b/src/librustc_mir_build/build/expr/into.rs index 4583e244f49..62158d3b931 100644 --- a/src/librustc_mir_build/build/expr/into.rs +++ b/src/librustc_mir_build/build/expr/into.rs @@ -328,7 +328,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::AssignOp { .. } | ExprKind::Continue { .. } | ExprKind::Break { .. } - | ExprKind::InlineAsm { .. } + | ExprKind::LlvmInlineAsm { .. } | ExprKind::Return { .. } => { unpack!(block = this.stmt_expr(block, expr, None)); this.cfg.push_assign_unit(block, source_info, destination); diff --git a/src/librustc_mir_build/build/expr/stmt.rs b/src/librustc_mir_build/build/expr/stmt.rs index 882c5e85bb0..1dc530a7bc8 100644 --- a/src/librustc_mir_build/build/expr/stmt.rs +++ b/src/librustc_mir_build/build/expr/stmt.rs @@ -96,8 +96,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ExprKind::Return { value } => { this.break_scope(block, value, BreakableTarget::Return, source_info) } - ExprKind::InlineAsm { asm, outputs, inputs } => { - debug!("stmt_expr InlineAsm block_context.push(SubExpr) : {:?}", expr2); + ExprKind::LlvmInlineAsm { asm, outputs, inputs } => { + debug!("stmt_expr LlvmInlineAsm block_context.push(SubExpr) : {:?}", expr2); this.block_context.push(BlockFrame::SubExpr); let outputs = outputs .into_iter() @@ -115,7 +115,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, Statement { source_info, - kind: StatementKind::InlineAsm(box InlineAsm { + kind: StatementKind::LlvmInlineAsm(box LlvmInlineAsm { asm: asm.clone(), outputs, inputs, diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/hair/cx/expr.rs index 9f93b817e38..ba17e2a75aa 100644 --- a/src/librustc_mir_build/hair/cx/expr.rs +++ b/src/librustc_mir_build/hair/cx/expr.rs @@ -398,7 +398,7 @@ fn make_mirror_unadjusted<'a, 'tcx>( convert_path_expr(cx, expr, res) } - hir::ExprKind::InlineAsm(ref asm) => ExprKind::InlineAsm { + hir::ExprKind::LlvmInlineAsm(ref asm) => ExprKind::LlvmInlineAsm { asm: &asm.inner, outputs: asm.outputs_exprs.to_ref(), inputs: asm.inputs_exprs.to_ref(), diff --git a/src/librustc_mir_build/hair/mod.rs b/src/librustc_mir_build/hair/mod.rs index 77042240acf..ed60c79903d 100644 --- a/src/librustc_mir_build/hair/mod.rs +++ b/src/librustc_mir_build/hair/mod.rs @@ -277,8 +277,8 @@ crate enum ExprKind<'tcx> { literal: &'tcx Const<'tcx>, def_id: DefId, }, - InlineAsm { - asm: &'tcx hir::InlineAsmInner, + LlvmInlineAsm { + asm: &'tcx hir::LlvmInlineAsmInner, outputs: Vec<ExprRef<'tcx>>, inputs: Vec<ExprRef<'tcx>>, }, diff --git a/src/librustc_passes/liveness.rs b/src/librustc_passes/liveness.rs index 97f6457d397..93c2449aacc 100644 --- a/src/librustc_passes/liveness.rs +++ b/src/librustc_passes/liveness.rs @@ -532,7 +532,7 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr<'tcx>) { | hir::ExprKind::AssignOp(..) | hir::ExprKind::Struct(..) | hir::ExprKind::Repeat(..) - | hir::ExprKind::InlineAsm(..) + | hir::ExprKind::LlvmInlineAsm(..) | hir::ExprKind::Box(..) | hir::ExprKind::Yield(..) | hir::ExprKind::Type(..) @@ -1183,7 +1183,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { | hir::ExprKind::Yield(ref e, _) | hir::ExprKind::Repeat(ref e, _) => self.propagate_through_expr(&e, succ), - hir::ExprKind::InlineAsm(ref asm) => { + hir::ExprKind::LlvmInlineAsm(ref asm) => { let ia = &asm.inner; let outputs = asm.outputs_exprs; let inputs = asm.inputs_exprs; @@ -1408,7 +1408,7 @@ fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr<'tcx>) { } } - hir::ExprKind::InlineAsm(ref asm) => { + hir::ExprKind::LlvmInlineAsm(ref asm) => { for input in asm.inputs_exprs { this.visit_expr(input); } diff --git a/src/librustc_span/symbol.rs b/src/librustc_span/symbol.rs index bb41629ef09..54b404e1161 100644 --- a/src/librustc_span/symbol.rs +++ b/src/librustc_span/symbol.rs @@ -424,6 +424,7 @@ symbols! { LintPass, lint_reasons, literal, + llvm_asm, local_inner_macros, log_syntax, loop_break_value, diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index dffed9a836c..dfe70cb1d74 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -230,7 +230,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.check_expr_addr_of(kind, mutbl, oprnd, expected, expr) } ExprKind::Path(ref qpath) => self.check_expr_path(qpath, expr), - ExprKind::InlineAsm(ref asm) => { + ExprKind::LlvmInlineAsm(ref asm) => { for expr in asm.outputs_exprs.iter().chain(asm.inputs_exprs.iter()) { self.check_expr(expr); } diff --git a/src/librustc_typeck/expr_use_visitor.rs b/src/librustc_typeck/expr_use_visitor.rs index a45d8ce6823..4eb6a6bda02 100644 --- a/src/librustc_typeck/expr_use_visitor.rs +++ b/src/librustc_typeck/expr_use_visitor.rs @@ -220,7 +220,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { self.borrow_expr(&base, bk); } - hir::ExprKind::InlineAsm(ref ia) => { + hir::ExprKind::LlvmInlineAsm(ref ia) => { for (o, output) in ia.inner.outputs.iter().zip(ia.outputs_exprs) { if o.is_indirect { self.consume_expr(output); diff --git a/src/librustc_typeck/mem_categorization.rs b/src/librustc_typeck/mem_categorization.rs index 7d8bf71cf97..e76c67794e7 100644 --- a/src/librustc_typeck/mem_categorization.rs +++ b/src/librustc_typeck/mem_categorization.rs @@ -405,7 +405,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { | hir::ExprKind::Continue(..) | hir::ExprKind::Struct(..) | hir::ExprKind::Repeat(..) - | hir::ExprKind::InlineAsm(..) + | hir::ExprKind::LlvmInlineAsm(..) | hir::ExprKind::Box(..) | hir::ExprKind::Err => Ok(self.cat_rvalue(expr.hir_id, expr.span, expr_ty)), } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index d4110527054..09bc183cf20 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -274,6 +274,7 @@ #![feature(libc)] #![feature(link_args)] #![feature(linkage)] +#![feature(llvm_asm)] #![feature(log_syntax)] #![feature(maybe_uninit_ref)] #![feature(maybe_uninit_slice)] @@ -533,29 +534,9 @@ pub use core::{ // Re-export built-in macros defined through libcore. #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] pub use core::{ - // Unstable - asm, - // Stable - assert, - cfg, - column, - compile_error, - concat, - concat_idents, - env, - file, - format_args, - format_args_nl, - global_asm, - include, - include_bytes, - include_str, - line, - log_syntax, - module_path, - option_env, - stringify, - trace_macros, + asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, + format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, log_syntax, + module_path, option_env, stringify, trace_macros, }; #[stable(feature = "core_primitive", since = "1.43.0")] diff --git a/src/libstd/prelude/v1.rs b/src/libstd/prelude/v1.rs index 6712f5ba580..03686d789d7 100644 --- a/src/libstd/prelude/v1.rs +++ b/src/libstd/prelude/v1.rs @@ -39,8 +39,8 @@ pub use crate::result::Result::{self, Err, Ok}; #[doc(no_inline)] pub use core::prelude::v1::{ asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, - format_args_nl, global_asm, include, include_bytes, include_str, line, log_syntax, module_path, - option_env, stringify, trace_macros, + format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, log_syntax, + module_path, option_env, stringify, trace_macros, }; // FIXME: Attribute and derive macros are not documented because for them rustdoc generates diff --git a/src/libstd/sys/sgx/abi/mem.rs b/src/libstd/sys/sgx/abi/mem.rs index 500e62b1cb5..57fd7efdd49 100644 --- a/src/libstd/sys/sgx/abi/mem.rs +++ b/src/libstd/sys/sgx/abi/mem.rs @@ -22,7 +22,7 @@ extern "C" { #[unstable(feature = "sgx_platform", issue = "56975")] pub fn image_base() -> u64 { let base; - unsafe { asm!("lea IMAGE_BASE(%rip),$0":"=r"(base)) }; + unsafe { llvm_asm!("lea IMAGE_BASE(%rip),$0":"=r"(base)) }; base } diff --git a/src/libstd/sys/sgx/ext/arch.rs b/src/libstd/sys/sgx/ext/arch.rs index 5056e388112..0c97a87e2e4 100644 --- a/src/libstd/sys/sgx/ext/arch.rs +++ b/src/libstd/sys/sgx/ext/arch.rs @@ -31,7 +31,7 @@ pub fn egetkey(request: &Align512<[u8; 512]>) -> Result<Align16<[u8; 16]>, u32> let mut out = MaybeUninit::uninit(); let error; - asm!( + llvm_asm!( "enclu" : "={eax}"(error) : "{eax}"(ENCLU_EGETKEY), @@ -60,7 +60,7 @@ pub fn ereport( unsafe { let mut report = MaybeUninit::uninit(); - asm!( + llvm_asm!( "enclu" : /* no output registers */ : "{eax}"(ENCLU_EREPORT), diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index b004cd19020..74dd41fd501 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -267,7 +267,7 @@ pub fn dur2timeout(dur: Duration) -> c::DWORD { pub unsafe fn abort_internal() -> ! { #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { - asm!("int $$0x29" :: "{ecx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT + llvm_asm!("int $$0x29" :: "{ecx}"(7) ::: volatile); // 7 is FAST_FAIL_FATAL_APP_EXIT crate::intrinsics::unreachable(); } crate::intrinsics::abort(); diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 55f9df9caaf..933b647071f 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -20,7 +20,6 @@ #![crate_name = "test"] #![unstable(feature = "test", issue = "50297")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/", test(attr(deny(warnings))))] -#![feature(asm)] #![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc))] #![feature(rustc_private)] #![feature(nll)] diff --git a/src/test/ui/feature-gates/feature-gate-asm.stderr b/src/test/ui/feature-gates/feature-gate-asm.stderr index 265d38f83f5..4c75d19c99f 100644 --- a/src/test/ui/feature-gates/feature-gate-asm.stderr +++ b/src/test/ui/feature-gates/feature-gate-asm.stderr @@ -4,7 +4,7 @@ error[E0658]: use of unstable library feature 'asm': inline assembly is not stab LL | asm!(""); | ^^^ | - = note: see issue #29722 <https://github.com/rust-lang/rust/issues/29722> for more information + = note: see issue #70173 <https://github.com/rust-lang/rust/issues/70173> for more information = help: add `#![feature(asm)]` to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/feature-gates/feature-gate-asm2.stderr b/src/test/ui/feature-gates/feature-gate-asm2.stderr index 7ea7bdac441..eaf3aa402e3 100644 --- a/src/test/ui/feature-gates/feature-gate-asm2.stderr +++ b/src/test/ui/feature-gates/feature-gate-asm2.stderr @@ -4,7 +4,7 @@ error[E0658]: use of unstable library feature 'asm': inline assembly is not stab LL | println!("{:?}", asm!("")); | ^^^ | - = note: see issue #29722 <https://github.com/rust-lang/rust/issues/29722> for more information + = note: see issue #70173 <https://github.com/rust-lang/rust/issues/70173> for more information = help: add `#![feature(asm)]` to the crate attributes to enable error: aborting due to previous error |
