Skip to content

Commit 90a273b

Browse files
committed
Auto merge of #90348 - Amanieu:asm_feature_gates, r=joshtriplett
Add features gates for experimental asm features This PR splits off parts of `asm!` into separate features because they are not ready for stabilization. Specifically this adds: - `asm_const` for `const` operands. - `asm_sym` for `sym` operands. - `asm_experimental_arch` for architectures other than x86, x86_64, arm, aarch64 and riscv. r? `@nagisa`
2 parents 88b4ea8 + 87d0d64 commit 90a273b

Some content is hidden

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

47 files changed

+253
-103
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use rustc_ast::*;
44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_errors::struct_span_err;
66
use rustc_hir as hir;
7-
use rustc_span::{Span, Symbol};
7+
use rustc_session::parse::feature_err;
8+
use rustc_span::{sym, Span, Symbol};
89
use rustc_target::asm;
910
use std::collections::hash_map::Entry;
1011
use std::fmt::Write;
@@ -18,6 +19,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1819
struct_span_err!(self.sess, sp, E0472, "inline assembly is unsupported on this target")
1920
.emit();
2021
}
22+
if let Some(asm_arch) = asm_arch {
23+
// Inline assembly is currently only stable for these architectures.
24+
let is_stable = matches!(
25+
asm_arch,
26+
asm::InlineAsmArch::X86
27+
| asm::InlineAsmArch::X86_64
28+
| asm::InlineAsmArch::Arm
29+
| asm::InlineAsmArch::AArch64
30+
| asm::InlineAsmArch::RiscV32
31+
| asm::InlineAsmArch::RiscV64
32+
);
33+
if !is_stable && !self.sess.features_untracked().asm_experimental_arch {
34+
feature_err(
35+
&self.sess.parse_sess,
36+
sym::asm_experimental_arch,
37+
sp,
38+
"inline assembly is not stable yet on this architecture",
39+
)
40+
.emit();
41+
}
42+
}
2143
if asm.options.contains(InlineAsmOptions::ATT_SYNTAX)
2244
&& !matches!(asm_arch, Some(asm::InlineAsmArch::X86 | asm::InlineAsmArch::X86_64))
2345
&& !self.sess.opts.actually_rustdoc
@@ -121,10 +143,30 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
121143
out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)),
122144
}
123145
}
124-
InlineAsmOperand::Const { ref anon_const } => hir::InlineAsmOperand::Const {
125-
anon_const: self.lower_anon_const(anon_const),
126-
},
146+
InlineAsmOperand::Const { ref anon_const } => {
147+
if !self.sess.features_untracked().asm_const {
148+
feature_err(
149+
&self.sess.parse_sess,
150+
sym::asm_const,
151+
*op_sp,
152+
"const operands for inline assembly are unstable",
153+
)
154+
.emit();
155+
}
156+
hir::InlineAsmOperand::Const {
157+
anon_const: self.lower_anon_const(anon_const),
158+
}
159+
}
127160
InlineAsmOperand::Sym { ref expr } => {
161+
if !self.sess.features_untracked().asm_sym {
162+
feature_err(
163+
&self.sess.parse_sess,
164+
sym::asm_sym,
165+
*op_sp,
166+
"sym operands for inline assembly are unstable",
167+
)
168+
.emit();
169+
}
128170
hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) }
129171
}
130172
};

compiler/rustc_feature/src/active.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,15 @@ declare_features! (
692692
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
693693
(active, doc_auto_cfg, "1.58.0", Some(43781), None),
694694

695+
/// Allows using `const` operands in inline assembly.
696+
(active, asm_const, "1.58.0", Some(72016), None),
697+
698+
/// Allows using `sym` operands in inline assembly.
699+
(active, asm_sym, "1.58.0", Some(72016), None),
700+
701+
/// Enables experimental inline assembly support for additional architectures.
702+
(active, asm_experimental_arch, "1.58.0", Some(72016), None),
703+
695704
// -------------------------------------------------------------------------
696705
// feature-group-end: actual feature gates
697706
// -------------------------------------------------------------------------

compiler/rustc_span/src/symbol.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ symbols! {
327327
as_ptr,
328328
as_str,
329329
asm,
330+
asm_const,
331+
asm_experimental_arch,
332+
asm_sym,
330333
assert,
331334
assert_inhabited,
332335
assert_macro,

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
#![feature(try_blocks)]
194194
#![feature(unboxed_closures)]
195195
#![feature(unsized_fn_params)]
196+
#![cfg_attr(not(bootstrap), feature(asm_const))]
196197
//
197198
// Target features:
198199
#![feature(aarch64_target_feature)]

src/doc/unstable-book/src/library-features/global-asm.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ are concatenated into one or assembled separately.
7575
constants defined in Rust to be used in assembly code:
7676

7777
```rust,no_run
78-
#![feature(global_asm)]
78+
#![feature(global_asm, asm_const)]
7979
# #[cfg(any(target_arch="x86", target_arch="x86_64"))]
8080
# mod x86 {
8181
const C: i32 = 1234;
@@ -96,7 +96,7 @@ override this by adding `options(att_syntax)` at the end of the macro
9696
arguments list:
9797

9898
```rust,no_run
99-
#![feature(global_asm)]
99+
#![feature(global_asm, asm_const)]
100100
# #[cfg(any(target_arch="x86", target_arch="x86_64"))]
101101
# mod x86 {
102102
global_asm!("movl ${}, %ecx", const 5, options(att_syntax));

src/test/assembly/asm/aarch64-types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// compile-flags: --target aarch64-unknown-linux-gnu
33
// needs-llvm-components: aarch64
44

5-
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
5+
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
66
#![crate_type = "rlib"]
77
#![no_core]
88
#![allow(asm_sub_register, non_camel_case_types)]

src/test/assembly/asm/arm-types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// compile-flags: -C target-feature=+neon
44
// needs-llvm-components: arm
55

6-
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
6+
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
77
#![crate_type = "rlib"]
88
#![no_core]
99
#![allow(asm_sub_register, non_camel_case_types)]

src/test/assembly/asm/bpf-types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// compile-flags: --target bpfel-unknown-none -C target_feature=+alu32
44
// needs-llvm-components: bpf
55

6-
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
6+
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
77
#![crate_type = "rlib"]
88
#![no_core]
99
#![allow(asm_sub_register, non_camel_case_types)]

src/test/assembly/asm/global_asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// assembly-output: emit-asm
33
// compile-flags: -C llvm-args=--x86-asm-syntax=intel
44

5-
#![feature(asm, global_asm)]
5+
#![feature(global_asm, asm_const)]
66
#![crate_type = "rlib"]
77

88
// CHECK: mov eax, eax

src/test/assembly/asm/hexagon-types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// compile-flags: --target hexagon-unknown-linux-musl
33
// needs-llvm-components: hexagon
44

5-
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
5+
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
66
#![crate_type = "rlib"]
77
#![no_core]
88
#![allow(asm_sub_register, non_camel_case_types)]

0 commit comments

Comments
 (0)