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

+46-4
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

+9
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

+3
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

+1
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

+2-2
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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)]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//[mips64] compile-flags: --target mips64-unknown-linux-gnuabi64
66
//[mips64] needs-llvm-components: mips
77

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// compile-flags: --crate-type cdylib
44
// needs-llvm-components: nvptx
55

6-
#![feature(no_core, lang_items, rustc_attrs)]
6+
#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)]
77
#![no_core]
88

99
#[rustc_builtin_macro]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//[powerpc64] compile-flags: --target powerpc64-unknown-linux-gnu
77
//[powerpc64] needs-llvm-components: powerpc
88

9-
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
9+
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
1010
#![crate_type = "rlib"]
1111
#![no_core]
1212
#![allow(asm_sub_register, non_camel_case_types)]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//[riscv32] needs-llvm-components: riscv
77
// compile-flags: -C target-feature=+d
88

9-
#![feature(no_core, lang_items, rustc_attrs)]
9+
#![feature(no_core, lang_items, rustc_attrs, asm_sym)]
1010
#![crate_type = "rlib"]
1111
#![no_core]
1212
#![allow(asm_sub_register)]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//[s390x] compile-flags: --target s390x-unknown-linux-gnu
44
//[s390x] needs-llvm-components: systemz
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/wasm-types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// compile-flags: --crate-type cdylib
44
// needs-llvm-components: webassembly
55

6-
#![feature(no_core, lang_items, rustc_attrs)]
6+
#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)]
77
#![no_core]
88

99
#[rustc_builtin_macro]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// compile-flags: -C llvm-args=--x86-asm-syntax=intel
88
// compile-flags: -C target-feature=+avx512bw
99

10-
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
10+
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
1111
#![crate_type = "rlib"]
1212
#![no_core]
1313
#![allow(asm_sub_register, non_camel_case_types)]

src/test/codegen/asm-powerpc-clobbers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//[powerpc64le] needs-llvm-components: powerpc
88

99
#![crate_type = "rlib"]
10-
#![feature(no_core, rustc_attrs, lang_items)]
10+
#![feature(no_core, rustc_attrs, lang_items, asm_experimental_arch)]
1111
#![no_core]
1212

1313
#[lang = "sized"]

src/test/ui/asm/aarch64/bad-reg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// only-aarch64
22
// compile-flags: -C target-feature=+fp
33

4-
#![feature(asm)]
4+
#![feature(asm, asm_const, asm_sym)]
55

66
fn main() {
77
let mut foo = 0;

src/test/ui/asm/aarch64/const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// revisions: mirunsafeck thirunsafeck
44
// [thirunsafeck]compile-flags: -Z thir-unsafeck
55

6-
#![feature(asm, global_asm)]
6+
#![feature(asm, global_asm, asm_const)]
77

88
fn const_generic<const X: usize>() -> usize {
99
unsafe {

src/test/ui/asm/aarch64/parse-error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// only-aarch64
22

3-
#![feature(asm, global_asm)]
3+
#![feature(asm, global_asm, asm_const)]
44

55
fn main() {
66
let mut foo = 0;

src/test/ui/asm/aarch64/sym.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// only-linux
33
// run-pass
44

5-
#![feature(asm, thread_local)]
5+
#![feature(asm, thread_local, asm_sym)]
66

77
extern "C" fn f1() -> i32 {
88
111
@@ -75,5 +75,7 @@ fn main() {
7575
std::thread::spawn(|| {
7676
assert_eq!(static_addr!(S1), &S1 as *const u32);
7777
assert_eq!(static_tls_addr!(S2), &S2 as *const u32);
78-
}).join().unwrap();
78+
})
79+
.join()
80+
.unwrap();
7981
}

src/test/ui/asm/aarch64/type-check-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// only-aarch64
22

3-
#![feature(asm, repr_simd, never_type)]
3+
#![feature(asm, repr_simd, never_type, asm_sym)]
44

55
#[repr(simd)]
66
#[derive(Clone, Copy)]

src/test/ui/asm/aarch64/type-check-3.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// only-aarch64
22
// compile-flags: -C target-feature=+neon
33

4-
#![feature(asm, global_asm, repr_simd, stdsimd)]
4+
#![feature(asm, global_asm, repr_simd, stdsimd, asm_const)]
55

66
use std::arch::aarch64::float64x2_t;
77

88
#[repr(simd)]
99
#[derive(Copy, Clone)]
10-
struct Simd256bit(f64, f64,f64, f64);
10+
struct Simd256bit(f64, f64, f64, f64);
1111

1212
fn main() {
1313
let f64x2: float64x2_t = unsafe { std::mem::transmute(0i128) };
@@ -42,7 +42,6 @@ fn main() {
4242
asm!("{:b}", in(vreg) 0u64);
4343
asm!("{:d}", in(vreg_low16) f64x2);
4444

45-
4645
// Template modifier suggestions for sub-registers
4746

4847
asm!("{}", in(reg) 0u8);

0 commit comments

Comments
 (0)