Skip to content

Commit

Permalink
Add features gates for experimental asm features
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Nov 7, 2021
1 parent 3831aaa commit eb32c00
Show file tree
Hide file tree
Showing 42 changed files with 243 additions and 98 deletions.
50 changes: 46 additions & 4 deletions compiler/rustc_ast_lowering/src/asm.rs
Expand Up @@ -4,7 +4,8 @@ use rustc_ast::*;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_span::{Span, Symbol};
use rustc_session::parse::feature_err;
use rustc_span::{sym, Span, Symbol};
use rustc_target::asm;
use std::collections::hash_map::Entry;
use std::fmt::Write;
Expand All @@ -18,6 +19,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
struct_span_err!(self.sess, sp, E0472, "inline assembly is unsupported on this target")
.emit();
}
if let Some(asm_arch) = asm_arch {
// Inline assembly is currently only stable for these architectures.
let is_stable = matches!(
asm_arch,
asm::InlineAsmArch::X86
| asm::InlineAsmArch::X86_64
| asm::InlineAsmArch::Arm
| asm::InlineAsmArch::AArch64
| asm::InlineAsmArch::RiscV32
| asm::InlineAsmArch::RiscV64
);
if !is_stable && !self.sess.features_untracked().asm_experimental_arch {
feature_err(
&self.sess.parse_sess,
sym::asm_experimental_arch,
sp,
"inline assembly is not stable yet on this architecture",
)
.emit();
}
}
if asm.options.contains(InlineAsmOptions::ATT_SYNTAX)
&& !matches!(asm_arch, Some(asm::InlineAsmArch::X86 | asm::InlineAsmArch::X86_64))
&& !self.sess.opts.actually_rustdoc
Expand Down Expand Up @@ -121,10 +143,30 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)),
}
}
InlineAsmOperand::Const { ref anon_const } => hir::InlineAsmOperand::Const {
anon_const: self.lower_anon_const(anon_const),
},
InlineAsmOperand::Const { ref anon_const } => {
if !self.sess.features_untracked().asm_const {
feature_err(
&self.sess.parse_sess,
sym::asm_const,
*op_sp,
"const operands for inline assembly are unstable",
)
.emit();
}
hir::InlineAsmOperand::Const {
anon_const: self.lower_anon_const(anon_const),
}
}
InlineAsmOperand::Sym { ref expr } => {
if !self.sess.features_untracked().asm_sym {
feature_err(
&self.sess.parse_sess,
sym::asm_sym,
*op_sp,
"sym operands for inline assembly are unstable",
)
.emit();
}
hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) }
}
};
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_feature/src/active.rs
Expand Up @@ -692,6 +692,15 @@ declare_features! (
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
(active, doc_auto_cfg, "1.58.0", Some(43781), None),

/// Allows using `const` operands in inline assembly.
(active, asm_const, "1.58.0", Some(72016), None),

/// Allows using `sym` operands in inline assembly.
(active, asm_sym, "1.58.0", Some(72016), None),

/// Enables experimental inline assembly support for additional architectures.
(active, asm_experimental_arch, "1.58.0", Some(72016), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Expand Up @@ -327,6 +327,9 @@ symbols! {
as_ptr,
as_str,
asm,
asm_const,
asm_experimental_arch,
asm_sym,
assert,
assert_inhabited,
assert_macro,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Expand Up @@ -193,6 +193,7 @@
#![feature(try_blocks)]
#![feature(unboxed_closures)]
#![feature(unsized_fn_params)]
#![cfg_attr(not(bootstrap), feature(asm_const))]
//
// Target features:
#![feature(aarch64_target_feature)]
Expand Down
4 changes: 2 additions & 2 deletions src/doc/unstable-book/src/library-features/global-asm.md
Expand Up @@ -75,7 +75,7 @@ are concatenated into one or assembled separately.
constants defined in Rust to be used in assembly code:

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

```rust,no_run
#![feature(global_asm)]
#![feature(global_asm, asm_const)]
# #[cfg(any(target_arch="x86", target_arch="x86_64"))]
# mod x86 {
global_asm!("movl ${}, %ecx", const 5, options(att_syntax));
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/aarch64-types.rs
Expand Up @@ -2,7 +2,7 @@
// compile-flags: --target aarch64-unknown-linux-gnu
// needs-llvm-components: aarch64

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/arm-types.rs
Expand Up @@ -3,7 +3,7 @@
// compile-flags: -C target-feature=+neon
// needs-llvm-components: arm

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/bpf-types.rs
Expand Up @@ -3,7 +3,7 @@
// compile-flags: --target bpfel-unknown-none -C target_feature=+alu32
// needs-llvm-components: bpf

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/global_asm.rs
Expand Up @@ -2,7 +2,7 @@
// assembly-output: emit-asm
// compile-flags: -C llvm-args=--x86-asm-syntax=intel

#![feature(asm, global_asm)]
#![feature(global_asm, asm_const)]
#![crate_type = "rlib"]

// CHECK: mov eax, eax
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/hexagon-types.rs
Expand Up @@ -2,7 +2,7 @@
// compile-flags: --target hexagon-unknown-linux-musl
// needs-llvm-components: hexagon

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/mips-types.rs
Expand Up @@ -5,7 +5,7 @@
//[mips64] compile-flags: --target mips64-unknown-linux-gnuabi64
//[mips64] needs-llvm-components: mips

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/nvptx-types.rs
Expand Up @@ -3,7 +3,7 @@
// compile-flags: --crate-type cdylib
// needs-llvm-components: nvptx

#![feature(no_core, lang_items, rustc_attrs)]
#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)]
#![no_core]

#[rustc_builtin_macro]
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/powerpc-types.rs
Expand Up @@ -6,7 +6,7 @@
//[powerpc64] compile-flags: --target powerpc64-unknown-linux-gnu
//[powerpc64] needs-llvm-components: powerpc

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/riscv-types.rs
Expand Up @@ -6,7 +6,7 @@
//[riscv32] needs-llvm-components: riscv
// compile-flags: -C target-feature=+d

#![feature(no_core, lang_items, rustc_attrs)]
#![feature(no_core, lang_items, rustc_attrs, asm_sym)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/s390x-types.rs
Expand Up @@ -3,7 +3,7 @@
//[s390x] compile-flags: --target s390x-unknown-linux-gnu
//[s390x] needs-llvm-components: systemz

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/wasm-types.rs
Expand Up @@ -3,7 +3,7 @@
// compile-flags: --crate-type cdylib
// needs-llvm-components: webassembly

#![feature(no_core, lang_items, rustc_attrs)]
#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)]
#![no_core]

#[rustc_builtin_macro]
Expand Down
2 changes: 1 addition & 1 deletion src/test/assembly/asm/x86-types.rs
Expand Up @@ -7,7 +7,7 @@
// compile-flags: -C llvm-args=--x86-asm-syntax=intel
// compile-flags: -C target-feature=+avx512bw

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/asm-powerpc-clobbers.rs
Expand Up @@ -7,7 +7,7 @@
//[powerpc64le] needs-llvm-components: powerpc

#![crate_type = "rlib"]
#![feature(no_core, rustc_attrs, lang_items)]
#![feature(no_core, rustc_attrs, lang_items, asm_experimental_arch)]
#![no_core]

#[lang = "sized"]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/asm/aarch64/bad-reg.rs
@@ -1,7 +1,7 @@
// only-aarch64
// compile-flags: -C target-feature=+fp

#![feature(asm)]
#![feature(asm, asm_const, asm_sym)]

fn main() {
let mut foo = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/asm/aarch64/const.rs
Expand Up @@ -3,7 +3,7 @@
// revisions: mirunsafeck thirunsafeck
// [thirunsafeck]compile-flags: -Z thir-unsafeck

#![feature(asm, global_asm)]
#![feature(asm, global_asm, asm_const)]

fn const_generic<const X: usize>() -> usize {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/asm/aarch64/parse-error.rs
@@ -1,6 +1,6 @@
// only-aarch64

#![feature(asm, global_asm)]
#![feature(asm, global_asm, asm_const)]

fn main() {
let mut foo = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/asm/aarch64/sym.rs
Expand Up @@ -2,7 +2,7 @@
// only-linux
// run-pass

#![feature(asm, thread_local)]
#![feature(asm, thread_local, asm_sym)]

extern "C" fn f1() -> i32 {
111
Expand Down Expand Up @@ -75,5 +75,7 @@ fn main() {
std::thread::spawn(|| {
assert_eq!(static_addr!(S1), &S1 as *const u32);
assert_eq!(static_tls_addr!(S2), &S2 as *const u32);
}).join().unwrap();
})
.join()
.unwrap();
}
2 changes: 1 addition & 1 deletion src/test/ui/asm/aarch64/type-check-2.rs
@@ -1,6 +1,6 @@
// only-aarch64

#![feature(asm, repr_simd, never_type)]
#![feature(asm, repr_simd, never_type, asm_sym)]

#[repr(simd)]
#[derive(Clone, Copy)]
Expand Down
5 changes: 2 additions & 3 deletions src/test/ui/asm/aarch64/type-check-3.rs
@@ -1,13 +1,13 @@
// only-aarch64
// compile-flags: -C target-feature=+neon

#![feature(asm, global_asm, repr_simd, stdsimd)]
#![feature(asm, global_asm, repr_simd, stdsimd, asm_const)]

use std::arch::aarch64::float64x2_t;

#[repr(simd)]
#[derive(Copy, Clone)]
struct Simd256bit(f64, f64,f64, f64);
struct Simd256bit(f64, f64, f64, f64);

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


// Template modifier suggestions for sub-registers

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

0 comments on commit eb32c00

Please sign in to comment.