mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
Rename asm! to llvm_asm!
asm! is left as a wrapper around llvm_asm! to maintain compatibility.
This commit is contained in:
parent
2fbb07525e
commit
d162d096dd
@ -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).
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)]
|
||||
|
@ -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",
|
||||
|
@ -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.
|
||||
|
@ -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")]
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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.
|
||||
|
@ -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));
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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> {
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
@ -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 };
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,9 +1,10 @@
|
||||
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"
|
||||
llvm_asm!("xor %eax, %eax"
|
||||
:
|
||||
: "=test"("a")
|
||||
);
|
||||
|
@ -1,9 +1,10 @@
|
||||
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"
|
||||
llvm_asm!("xor %eax, %eax"
|
||||
:
|
||||
: "+test"("a")
|
||||
);
|
||||
|
@ -1,9 +1,9 @@
|
||||
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"
|
||||
llvm_asm!("mov $$0x200, %eax"
|
||||
:
|
||||
:
|
||||
: "{eax}"
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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>,
|
||||
|
@ -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>],
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1529,7 +1529,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
StatementKind::FakeRead(..)
|
||||
| StatementKind::StorageLive(..)
|
||||
| StatementKind::StorageDead(..)
|
||||
| StatementKind::InlineAsm { .. }
|
||||
| StatementKind::LlvmInlineAsm { .. }
|
||||
| StatementKind::Retag { .. }
|
||||
| StatementKind::Nop => {}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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 => {}
|
||||
|
@ -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,
|
||||
|
@ -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()))
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ impl RemoveNoopLandingPads {
|
||||
|
||||
StatementKind::Assign { .. }
|
||||
| StatementKind::SetDiscriminant { .. }
|
||||
| StatementKind::InlineAsm { .. }
|
||||
| StatementKind::LlvmInlineAsm { .. }
|
||||
| StatementKind::Retag { .. } => {
|
||||
return false;
|
||||
}
|
||||
|
@ -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,
|
||||
})
|
||||
})
|
||||
|
@ -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,
|
||||
})
|
||||
};
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -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),
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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(),
|
||||
|
@ -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>>,
|
||||
},
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -424,6 +424,7 @@ symbols! {
|
||||
LintPass,
|
||||
lint_reasons,
|
||||
literal,
|
||||
llvm_asm,
|
||||
local_inner_macros,
|
||||
log_syntax,
|
||||
loop_break_value,
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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)),
|
||||
}
|
||||
|
@ -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")]
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
|
@ -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();
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user