Skip to content

Commit 2f4da62

Browse files
committed
Auto merge of rust-lang#91728 - Amanieu:stable_asm, r=joshtriplett
Stabilize asm! and global_asm! Tracking issue: rust-lang#72016 It's been almost 2 years since the original [RFC](rust-lang/rfcs#2850) was posted and we're finally ready to stabilize this feature! The main changes in this PR are: - Removing `asm!` and `global_asm!` from the prelude as per the decision in rust-lang#87228. - Stabilizing the `asm` and `global_asm` features. - Removing the unstable book pages for `asm` and `global_asm`. The contents are moved to the [reference](rust-lang/reference#1105) and [rust by example](rust-lang/rust-by-example#1483). - All links to these pages have been removed to satisfy the link checker. In a later PR these will be replaced with links to the reference or rust by example. - Removing the automatic suggestion for using `llvm_asm!` instead of `asm!` if you're still using the old syntax, since it doesn't work anymore with `asm!` no longer being in the prelude. This only affects code that predates the old LLVM-style `asm!` being renamed to `llvm_asm!`. - Updating `stdarch` and `compiler-builtins`. - Updating all the tests. r? `@joshtriplett`
2 parents 404c847 + d6f4da9 commit 2f4da62

File tree

141 files changed

+753
-1915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+753
-1915
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,9 @@ dependencies = [
680680

681681
[[package]]
682682
name = "compiler_builtins"
683-
version = "0.1.55"
683+
version = "0.1.65"
684684
source = "registry+https://github.com/rust-lang/crates.io-index"
685-
checksum = "c9ac60765140c97aaf531dae151a287646b0805ec725805da9e2a3ee31cd501c"
685+
checksum = "ed37ea958309f2451e1cea7fd2b37aa56b1894c9a9fbdbbe6a194f7b78f0362d"
686686
dependencies = [
687687
"cc",
688688
"rustc-std-workspace-core",

compiler/rustc_builtin_macros/src/asm.rs

-13
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,6 @@ fn parse_args<'a>(
4242
ecx.struct_span_err(sp, "the legacy LLVM-style asm! syntax is no longer supported");
4343
err.note("consider migrating to the new asm! syntax specified in RFC 2873");
4444
err.note("alternatively, switch to llvm_asm! to keep your code working as it is");
45-
46-
// Find the span of the "asm!" so that we can offer an automatic suggestion
47-
let asm_span = sp.from_inner(InnerSpan::new(0, 4));
48-
if let Ok(s) = ecx.source_map().span_to_snippet(asm_span) {
49-
if s == "asm!" {
50-
err.span_suggestion(
51-
asm_span,
52-
"replace with",
53-
"llvm_asm!".into(),
54-
Applicability::MachineApplicable,
55-
);
56-
}
57-
}
5845
return Err(err);
5946
}
6047

compiler/rustc_codegen_cranelift/src/inline_asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Codegen of [`asm!`] invocations.
1+
//! Codegen of `asm!` invocations.
22
33
use crate::prelude::*;
44

compiler/rustc_codegen_gcc/tests/run/asm.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// Run-time:
44
// status: 0
55

6-
#![feature(asm, global_asm)]
7-
86
global_asm!("
97
.global add_asm
108
add_asm:

compiler/rustc_hir/src/def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub enum DefKind {
113113
Field,
114114
/// Lifetime parameter: the `'a` in `struct Foo<'a> { ... }`
115115
LifetimeParam,
116-
/// A use of [`global_asm!`].
116+
/// A use of `global_asm!`.
117117
GlobalAsm,
118118
Impl,
119119
Closure,

compiler/rustc_lint/src/builtin.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3147,7 +3147,8 @@ declare_lint! {
31473147
/// ### Example
31483148
///
31493149
/// ```rust,compile_fail
3150-
/// #![feature(asm)]
3150+
/// use std::arch::asm;
3151+
///
31513152
/// fn main() {
31523153
/// unsafe {
31533154
/// asm!("foo: bar");
@@ -3164,10 +3165,7 @@ declare_lint! {
31643165
/// of this, GNU assembler [local labels] *must* be used instead of labels
31653166
/// with a name. Using named labels might cause assembler or linker errors.
31663167
///
3167-
/// See the [unstable book] for more details.
3168-
///
31693168
/// [local labels]: https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels
3170-
/// [unstable book]: https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels
31713169
pub NAMED_ASM_LABELS,
31723170
Deny,
31733171
"named labels in inline assembly",

compiler/rustc_lint/src/context.rs

-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,6 @@ pub trait LintContext: Sized {
772772
}
773773
BuiltinLintDiagnostics::NamedAsmLabel(help) => {
774774
db.help(&help);
775-
db.note("see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information");
776775
}
777776
}
778777
// Rewrap `db`, and pass control to the user.

compiler/rustc_lint_defs/src/builtin.rs

+11-37
Original file line numberDiff line numberDiff line change
@@ -2419,8 +2419,9 @@ declare_lint! {
24192419
///
24202420
/// ### Example
24212421
///
2422-
/// ```rust,ignore (fails on system llvm)
2423-
/// #![feature(asm)]
2422+
/// ```rust,ignore (fails on non-x86_64)
2423+
/// #[cfg(target_arch="x86_64")]
2424+
/// use std::arch::asm;
24242425
///
24252426
/// fn main() {
24262427
/// #[cfg(target_arch="x86_64")]
@@ -2430,19 +2431,7 @@ declare_lint! {
24302431
/// }
24312432
/// ```
24322433
///
2433-
/// This will produce:
2434-
///
2435-
/// ```text
2436-
/// warning: formatting may not be suitable for sub-register argument
2437-
/// --> src/main.rs:6:19
2438-
/// |
2439-
/// 6 | asm!("mov {0}, {0}", in(reg) 0i16);
2440-
/// | ^^^ ^^^ ---- for this argument
2441-
/// |
2442-
/// = note: `#[warn(asm_sub_register)]` on by default
2443-
/// = help: use the `x` modifier to have the register formatted as `ax`
2444-
/// = help: or use the `r` modifier to keep the default formatting of `rax`
2445-
/// ```
2434+
/// {{produces}}
24462435
///
24472436
/// ### Explanation
24482437
///
@@ -2455,10 +2444,6 @@ declare_lint! {
24552444
/// register size, to alert you of possibly using the incorrect width. To
24562445
/// fix this, add the suggested modifier to the template, or cast the
24572446
/// value to the correct size.
2458-
///
2459-
/// See [register template modifiers] for more details.
2460-
///
2461-
/// [register template modifiers]: https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#register-template-modifiers
24622447
pub ASM_SUB_REGISTER,
24632448
Warn,
24642449
"using only a subset of a register for inline asm inputs",
@@ -2470,34 +2455,22 @@ declare_lint! {
24702455
///
24712456
/// ### Example
24722457
///
2473-
/// ```rust,ignore (fails on system llvm)
2474-
/// #![feature(asm)]
2458+
/// ```rust,ignore (fails on non-x86_64)
2459+
/// #[cfg(target_arch="x86_64")]
2460+
/// use std::arch::asm;
24752461
///
24762462
/// fn main() {
24772463
/// #[cfg(target_arch="x86_64")]
24782464
/// unsafe {
24792465
/// asm!(
24802466
/// ".att_syntax",
2481-
/// "movl {0}, {0}", in(reg) 0usize
2467+
/// "movq %{0}, %{0}", in(reg) 0usize
24822468
/// );
24832469
/// }
24842470
/// }
24852471
/// ```
24862472
///
2487-
/// This will produce:
2488-
///
2489-
/// ```text
2490-
/// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
2491-
/// --> test.rs:7:14
2492-
/// |
2493-
/// 7 | ".att_syntax",
2494-
/// | ^^^^^^^^^^^
2495-
/// 8 | "movq {0}, {0}", out(reg) _,
2496-
/// 9 | );
2497-
/// | - help: add option: `, options(att_syntax)`
2498-
/// |
2499-
/// = note: `#[warn(bad_asm_style)]` on by default
2500-
/// ```
2473+
/// {{produces}}
25012474
///
25022475
/// ### Explanation
25032476
///
@@ -2739,7 +2712,8 @@ declare_lint! {
27392712
///
27402713
/// ```rust
27412714
/// #![feature(naked_functions)]
2742-
/// #![feature(asm)]
2715+
///
2716+
/// use std::arch::asm;
27432717
///
27442718
/// #[naked]
27452719
/// pub fn default_abi() -> u32 {

library/core/src/lib.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@
153153
#![feature(abi_unadjusted)]
154154
#![feature(allow_internal_unsafe)]
155155
#![feature(allow_internal_unstable)]
156-
#![feature(asm)]
157156
#![feature(associated_type_bounds)]
158157
#![feature(auto_traits)]
159158
#![feature(cfg_target_has_atomic)]
@@ -373,26 +372,14 @@ pub mod arch {
373372
pub use crate::core_arch::arch::*;
374373

375374
/// Inline assembly.
376-
///
377-
/// Read the [unstable book] for the usage.
378-
///
379-
/// [unstable book]: ../../unstable-book/library-features/asm.html
380-
#[unstable(
381-
feature = "asm",
382-
issue = "72016",
383-
reason = "inline assembly is not stable enough for use and is subject to change"
384-
)]
375+
#[stable(feature = "asm", since = "1.59.0")]
385376
#[rustc_builtin_macro]
386377
pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
387378
/* compiler built-in */
388379
}
389380
390381
/// Module-level inline assembly.
391-
#[unstable(
392-
feature = "global_asm",
393-
issue = "35119",
394-
reason = "`global_asm!` is not stable enough for use and is subject to change"
395-
)]
382+
#[stable(feature = "global_asm", since = "1.59.0")]
396383
#[rustc_builtin_macro]
397384
pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
398385
/* compiler built-in */

library/core/src/num/dec2flt/fpu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub use fpu_precision::set_precision;
1010
// computations are performed in the desired precision.
1111
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
1212
mod fpu_precision {
13+
use core::arch::asm;
1314
use core::mem::size_of;
1415

1516
/// A structure used to preserve the original value of the FPU control word, so that it can be

library/core/src/prelude/v1.rs

-16
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,6 @@ pub use crate::{
6969
#[doc(no_inline)]
7070
pub use crate::concat_bytes;
7171

72-
#[unstable(
73-
feature = "asm",
74-
issue = "72016",
75-
reason = "inline assembly is not stable enough for use and is subject to change"
76-
)]
77-
#[doc(no_inline)]
78-
pub use crate::arch::asm;
79-
80-
#[unstable(
81-
feature = "global_asm",
82-
issue = "35119",
83-
reason = "`global_asm!` is not stable enough for use and is subject to change"
84-
)]
85-
#[doc(no_inline)]
86-
pub use crate::arch::global_asm;
87-
8872
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
8973
#[allow(deprecated, deprecated_in_future)]
9074
#[doc(no_inline)]

library/panic_abort/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![feature(std_internals)]
1515
#![feature(staged_api)]
1616
#![feature(rustc_attrs)]
17-
#![feature(asm)]
1817
#![feature(c_unwind)]
1918

2019
#[cfg(target_os = "android")]
@@ -69,11 +68,11 @@ pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMe
6968
const FAST_FAIL_FATAL_APP_EXIT: usize = 7;
7069
cfg_if::cfg_if! {
7170
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
72-
asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
71+
core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
7372
} else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] {
74-
asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
73+
core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
7574
} else if #[cfg(target_arch = "aarch64")] {
76-
asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
75+
core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
7776
} else {
7877
core::intrinsics::abort();
7978
}

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ panic_unwind = { path = "../panic_unwind", optional = true }
1616
panic_abort = { path = "../panic_abort" }
1717
core = { path = "../core" }
1818
libc = { version = "0.2.108", default-features = false, features = ['rustc-dep-of-std'] }
19-
compiler_builtins = { version = "0.1.55" }
19+
compiler_builtins = { version = "0.1.65" }
2020
profiler_builtins = { path = "../profiler_builtins", optional = true }
2121
unwind = { path = "../unwind" }
2222
hashbrown = { version = "0.11", default-features = false, features = ['rustc-dep-of-std'] }

library/std/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@
233233
#![feature(allow_internal_unstable)]
234234
#![feature(arbitrary_self_types)]
235235
#![feature(array_error_internals)]
236-
#![feature(asm)]
237236
#![feature(assert_matches)]
238237
#![feature(associated_type_bounds)]
239238
#![feature(async_stream)]
@@ -287,7 +286,6 @@
287286
#![feature(gen_future)]
288287
#![feature(generator_trait)]
289288
#![feature(get_mut_unchecked)]
290-
#![feature(global_asm)]
291289
#![feature(hashmap_internals)]
292290
#![feature(int_error_internals)]
293291
#![feature(integer_atomics)]

library/std/src/os/fortanix_sgx/arch.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![unstable(feature = "sgx_platform", issue = "56975")]
66

77
use crate::mem::MaybeUninit;
8+
use core::arch::asm;
89

910
/// Wrapper struct to force 16-byte alignment.
1011
#[repr(align(16))]

library/std/src/prelude/v1.rs

-16
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,6 @@ pub use core::prelude::v1::{
5454
#[doc(no_inline)]
5555
pub use core::prelude::v1::concat_bytes;
5656

57-
#[unstable(
58-
feature = "asm",
59-
issue = "72016",
60-
reason = "inline assembly is not stable enough for use and is subject to change"
61-
)]
62-
#[doc(no_inline)]
63-
pub use core::prelude::v1::asm;
64-
65-
#[unstable(
66-
feature = "global_asm",
67-
issue = "35119",
68-
reason = "`global_asm!` is not stable enough for use and is subject to change"
69-
)]
70-
#[doc(no_inline)]
71-
pub use core::prelude::v1::global_asm;
72-
7357
// FIXME: Attribute and internal derive macros are not documented because for them rustdoc generates
7458
// dead links which fail link checker testing.
7559
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]

library/std/src/sys/sgx/abi/mem.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::arch::asm;
2+
13
// Do not remove inline: will result in relocation failure
24
#[inline(always)]
35
pub(crate) unsafe fn rel_ptr<T>(offset: u64) -> *const T {

library/std/src/sys/sgx/abi/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![cfg_attr(test, allow(unused))] // RT initialization logic is not compiled for test
22

33
use crate::io::Write;
4+
use core::arch::global_asm;
45
use core::sync::atomic::{AtomicUsize, Ordering};
56

67
// runtime features

library/std/src/sys/solid/abi/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ pub fn breakpoint_program_exited(tid: usize) {
1010
match () {
1111
// SOLID_BP_PROGRAM_EXITED = 15
1212
#[cfg(target_arch = "arm")]
13-
() => asm!("bkpt #15", in("r0") tid),
13+
() => core::arch::asm!("bkpt #15", in("r0") tid),
1414
#[cfg(target_arch = "aarch64")]
15-
() => asm!("hlt #15", in("x0") tid),
15+
() => core::arch::asm!("hlt #15", in("x0") tid),
1616
}
1717
}
1818
}
@@ -23,9 +23,9 @@ pub fn breakpoint_abort() {
2323
match () {
2424
// SOLID_BP_CSABORT = 16
2525
#[cfg(target_arch = "arm")]
26-
() => asm!("bkpt #16"),
26+
() => core::arch::asm!("bkpt #16"),
2727
#[cfg(target_arch = "aarch64")]
28-
() => asm!("hlt #16"),
28+
() => core::arch::asm!("hlt #16"),
2929
}
3030
}
3131
}

library/std/src/sys/windows/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,13 @@ pub fn abort_internal() -> ! {
288288
unsafe {
289289
cfg_if::cfg_if! {
290290
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
291-
asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
291+
core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
292292
crate::intrinsics::unreachable();
293293
} else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] {
294-
asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
294+
core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
295295
crate::intrinsics::unreachable();
296296
} else if #[cfg(target_arch = "aarch64")] {
297-
asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
297+
core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
298298
crate::intrinsics::unreachable();
299299
}
300300
}

src/doc/unstable-book/src/compiler-flags/sanitizer.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto).
199199
## Example
200200
201201
```text
202-
#![feature(asm, naked_functions)]
202+
#![feature(naked_functions)]
203203
204+
use std::arch::asm;
204205
use std::mem;
205206
206207
fn add_one(x: i32) -> i32 {

0 commit comments

Comments
 (0)