Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize asm_const #128570

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ ast_lowering_underscore_expr_lhs_assign =
.label = `_` not allowed here

ast_lowering_unstable_inline_assembly = inline assembly is not stable yet on this architecture
ast_lowering_unstable_inline_assembly_const_operands =
const operands for inline assembly are unstable
ast_lowering_unstable_inline_assembly_label_operands =
label operands for inline assembly are unstable
ast_lowering_unstable_may_unwind = the `may_unwind` option is unstable
Expand Down
17 changes: 3 additions & 14 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
out_expr: out_expr.as_ref().map(|expr| self.lower_expr(expr)),
}
}
InlineAsmOperand::Const { anon_const } => {
if !self.tcx.features().asm_const {
feature_err(
sess,
sym::asm_const,
*op_sp,
fluent::ast_lowering_unstable_inline_assembly_const_operands,
)
.emit();
}
hir::InlineAsmOperand::Const {
anon_const: self.lower_anon_const_to_anon_const(anon_const),
}
}
InlineAsmOperand::Const { anon_const } => hir::InlineAsmOperand::Const {
anon_const: self.lower_anon_const_to_anon_const(anon_const),
},
InlineAsmOperand::Sym { sym } => {
let static_def_id = self
.resolver
Expand Down
15 changes: 6 additions & 9 deletions compiler/rustc_codegen_gcc/tests/run/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
// Run-time:
// status: 0

#![feature(asm_const)]

#[cfg(target_arch="x86_64")]
#[cfg(target_arch = "x86_64")]
use std::arch::{asm, global_asm};

#[cfg(target_arch="x86_64")]
#[cfg(target_arch = "x86_64")]
global_asm!(
"
.global add_asm
Expand All @@ -22,7 +20,7 @@ extern "C" {
fn add_asm(a: i64, b: i64) -> i64;
}

#[cfg(target_arch="x86_64")]
#[cfg(target_arch = "x86_64")]
pub unsafe fn mem_cpy(dst: *mut u8, src: *const u8, len: usize) {
asm!(
"rep movsb",
Expand All @@ -33,7 +31,7 @@ pub unsafe fn mem_cpy(dst: *mut u8, src: *const u8, len: usize) {
);
}

#[cfg(target_arch="x86_64")]
#[cfg(target_arch = "x86_64")]
fn asm() {
unsafe {
asm!("nop");
Expand Down Expand Up @@ -178,9 +176,8 @@ fn asm() {
assert_eq!(array1, array2);
}

#[cfg(not(target_arch="x86_64"))]
fn asm() {
}
#[cfg(not(target_arch = "x86_64"))]
fn asm() {}

fn main() {
asm();
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ declare_features! (
(accepted, adx_target_feature, "1.61.0", Some(44839)),
/// Allows explicit discriminants on non-unit enum variants.
(accepted, arbitrary_enum_discriminant, "1.66.0", Some(60553)),
/// Allows using `const` operands in inline assembly.
(accepted, asm_const, "CURRENT_RUSTC_VERSION", Some(93332)),
/// Allows using `sym` operands in inline assembly.
(accepted, asm_sym, "1.66.0", Some(93333)),
/// Allows the definition of associated constants in `trait` or `impl` blocks.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,6 @@ declare_features! (
(unstable, alloc_error_handler, "1.29.0", Some(51540)),
/// Allows trait methods with arbitrary self types.
(unstable, arbitrary_self_types, "1.23.0", Some(44874)),
/// Allows using `const` operands in inline assembly.
(unstable, asm_const, "1.58.0", Some(93332)),
/// Enables experimental inline assembly support for additional architectures.
(unstable, asm_experimental_arch, "1.58.0", Some(93335)),
/// Allows using `label` operands in inline assembly.
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@
//
// Language features:
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(asm_const))]
#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))]
#![feature(abi_unadjusted)]
#![feature(adt_const_params)]
#![feature(allow_internal_unsafe)]
#![feature(allow_internal_unstable)]
#![feature(asm_const)]
#![feature(auto_traits)]
#![feature(cfg_sanitize)]
#![feature(cfg_target_has_atomic)]
Expand Down
11 changes: 0 additions & 11 deletions src/doc/unstable-book/src/language-features/asm-const.md

This file was deleted.

1 change: 0 additions & 1 deletion tests/assembly/asm/global_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//@ compile-flags: -C llvm-args=--x86-asm-syntax=intel
//@ compile-flags: -C symbol-mangling-version=v0

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

use std::arch::global_asm;
Expand Down
2 changes: 1 addition & 1 deletion tests/assembly/asm/msp430-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@ compile-flags: --target msp430-none-elf
//@ needs-llvm-components: msp430

#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch, asm_const)]
#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(non_camel_case_types)]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/asm/aarch64/bad-reg.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//@ only-aarch64
//@ compile-flags: -C target-feature=+neon

#![feature(asm_const)]

use std::arch::asm;

fn main() {
Expand Down
44 changes: 22 additions & 22 deletions tests/ui/asm/aarch64/bad-reg.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error: invalid register class `foo`: unknown register class
--> $DIR/bad-reg.rs:14:20
--> $DIR/bad-reg.rs:12:20
|
LL | asm!("{}", in(foo) foo);
| ^^^^^^^^^^^

error: invalid register `foo`: unknown register
--> $DIR/bad-reg.rs:16:18
--> $DIR/bad-reg.rs:14:18
|
LL | asm!("", in("foo") foo);
| ^^^^^^^^^^^^^

error: invalid asm template modifier for this register class
--> $DIR/bad-reg.rs:18:15
--> $DIR/bad-reg.rs:16:15
|
LL | asm!("{:z}", in(reg) foo);
| ^^^^ ----------- argument
Expand All @@ -21,7 +21,7 @@ LL | asm!("{:z}", in(reg) foo);
= note: the `reg` register class supports the following template modifiers: `w`, `x`

error: invalid asm template modifier for this register class
--> $DIR/bad-reg.rs:20:15
--> $DIR/bad-reg.rs:18:15
|
LL | asm!("{:r}", in(vreg) foo);
| ^^^^ ------------ argument
Expand All @@ -31,7 +31,7 @@ LL | asm!("{:r}", in(vreg) foo);
= note: the `vreg` register class supports the following template modifiers: `b`, `h`, `s`, `d`, `q`, `v`

error: invalid asm template modifier for this register class
--> $DIR/bad-reg.rs:22:15
--> $DIR/bad-reg.rs:20:15
|
LL | asm!("{:r}", in(vreg_low16) foo);
| ^^^^ ------------------ argument
Expand All @@ -41,117 +41,117 @@ LL | asm!("{:r}", in(vreg_low16) foo);
= note: the `vreg_low16` register class supports the following template modifiers: `b`, `h`, `s`, `d`, `q`, `v`

error: asm template modifiers are not allowed for `const` arguments
--> $DIR/bad-reg.rs:24:15
--> $DIR/bad-reg.rs:22:15
|
LL | asm!("{:a}", const 0);
| ^^^^ ------- argument
| |
| template modifier

error: asm template modifiers are not allowed for `sym` arguments
--> $DIR/bad-reg.rs:26:15
--> $DIR/bad-reg.rs:24:15
|
LL | asm!("{:a}", sym main);
| ^^^^ -------- argument
| |
| template modifier

error: invalid register `x29`: the frame pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:28:18
--> $DIR/bad-reg.rs:26:18
|
LL | asm!("", in("x29") foo);
| ^^^^^^^^^^^^^

error: invalid register `sp`: the stack pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:30:18
--> $DIR/bad-reg.rs:28:18
|
LL | asm!("", in("sp") foo);
| ^^^^^^^^^^^^

error: invalid register `xzr`: the zero register cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:32:18
--> $DIR/bad-reg.rs:30:18
|
LL | asm!("", in("xzr") foo);
| ^^^^^^^^^^^^^

error: invalid register `x19`: x19 is used internally by LLVM and cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:34:18
--> $DIR/bad-reg.rs:32:18
|
LL | asm!("", in("x19") foo);
| ^^^^^^^^^^^^^

error: register class `preg` can only be used as a clobber, not as an input or output
--> $DIR/bad-reg.rs:37:18
--> $DIR/bad-reg.rs:35:18
|
LL | asm!("", in("p0") foo);
| ^^^^^^^^^^^^

error: register class `preg` can only be used as a clobber, not as an input or output
--> $DIR/bad-reg.rs:41:20
--> $DIR/bad-reg.rs:39:20
|
LL | asm!("{}", in(preg) foo);
| ^^^^^^^^^^^^

error: register class `preg` can only be used as a clobber, not as an input or output
--> $DIR/bad-reg.rs:44:20
--> $DIR/bad-reg.rs:42:20
|
LL | asm!("{}", out(preg) _);
| ^^^^^^^^^^^

error: register `w0` conflicts with register `x0`
--> $DIR/bad-reg.rs:50:32
--> $DIR/bad-reg.rs:48:32
|
LL | asm!("", in("x0") foo, in("w0") bar);
| ------------ ^^^^^^^^^^^^ register `w0`
| |
| register `x0`

error: register `x0` conflicts with register `x0`
--> $DIR/bad-reg.rs:52:32
--> $DIR/bad-reg.rs:50:32
|
LL | asm!("", in("x0") foo, out("x0") bar);
| ------------ ^^^^^^^^^^^^^ register `x0`
| |
| register `x0`
|
help: use `lateout` instead of `out` to avoid conflict
--> $DIR/bad-reg.rs:52:18
--> $DIR/bad-reg.rs:50:18
|
LL | asm!("", in("x0") foo, out("x0") bar);
| ^^^^^^^^^^^^

error: register `q0` conflicts with register `v0`
--> $DIR/bad-reg.rs:55:32
--> $DIR/bad-reg.rs:53:32
|
LL | asm!("", in("v0") foo, in("q0") bar);
| ------------ ^^^^^^^^^^^^ register `q0`
| |
| register `v0`

error: register `q0` conflicts with register `v0`
--> $DIR/bad-reg.rs:57:32
--> $DIR/bad-reg.rs:55:32
|
LL | asm!("", in("v0") foo, out("q0") bar);
| ------------ ^^^^^^^^^^^^^ register `q0`
| |
| register `v0`
|
help: use `lateout` instead of `out` to avoid conflict
--> $DIR/bad-reg.rs:57:18
--> $DIR/bad-reg.rs:55:18
|
LL | asm!("", in("v0") foo, out("q0") bar);
| ^^^^^^^^^^^^

error: type `i32` cannot be used with this register class
--> $DIR/bad-reg.rs:37:27
--> $DIR/bad-reg.rs:35:27
|
LL | asm!("", in("p0") foo);
| ^^^
|
= note: register class `preg` supports these types:

error: type `i32` cannot be used with this register class
--> $DIR/bad-reg.rs:41:29
--> $DIR/bad-reg.rs:39:29
|
LL | asm!("{}", in(preg) foo);
| ^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/asm/aarch64/const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//@ run-pass
//@ needs-asm-support

#![feature(asm_const)]

use std::arch::{asm, global_asm};

fn const_generic<const X: usize>() -> usize {
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/asm/aarch64/parse-error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ only-aarch64

#![feature(asm_const)]

use std::arch::{asm, global_asm};

fn main() {
Expand Down
Loading
Loading