Skip to content

Commit

Permalink
Make asm_goto_with_outputs a separate feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Oct 11, 2024
1 parent 394acf3 commit cd8a355
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 11 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ 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_label_operand_with_outputs =
using both label and outputs operands for inline assembly is 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
44 changes: 35 additions & 9 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}
InlineAsmOperand::Label { block } => {
if !self.tcx.features().asm_goto {
feature_err(
sess,
sym::asm_goto,
*op_sp,
fluent::ast_lowering_unstable_inline_assembly_label_operands,
)
.emit();
}
hir::InlineAsmOperand::Label { block: self.lower_block(block, false) }
}
};
Expand Down Expand Up @@ -464,6 +455,41 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}

// Feature gate checking for asm goto.
if let Some((_, op_sp)) =
operands.iter().find(|(op, _)| matches!(op, hir::InlineAsmOperand::Label { .. }))
{
if !self.tcx.features().asm_goto {
feature_err(
sess,
sym::asm_goto,
*op_sp,
fluent::ast_lowering_unstable_inline_assembly_label_operands,
)
.emit();
}

// In addition, check if an output operand is used.
// This is gated behind an additional feature.
let output_operand_used = operands.iter().any(|(op, _)| {
matches!(
op,
hir::InlineAsmOperand::Out { expr: Some(_), .. }
| hir::InlineAsmOperand::InOut { .. }
| hir::InlineAsmOperand::SplitInOut { out_expr: Some(_), .. }
)
});
if output_operand_used && !self.tcx.features().asm_goto_with_outputs {
feature_err(
sess,
sym::asm_goto_with_outputs,
*op_sp,
fluent::ast_lowering_unstable_inline_assembly_label_operand_with_outputs,
)
.emit();
}
}

let operands = self.arena.alloc_from_iter(operands);
let template = self.arena.alloc_from_iter(asm.template.iter().cloned());
let template_strs = self.arena.alloc_from_iter(
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ declare_features! (
(unstable, asm_experimental_arch, "1.58.0", Some(93335)),
/// Allows using `label` operands in inline assembly.
(unstable, asm_goto, "1.78.0", Some(119364)),
/// Allows using `label` operands in inline assembly together with output operands.
(unstable, asm_goto_with_outputs, "CURRENT_RUSTC_VERSION", Some(119364)),
/// Allows the `may_unwind` option in inline assembly.
(unstable, asm_unwind, "1.58.0", Some(93334)),
/// Allows users to enforce equality of associated constants `TraitImpl<AssocConst=3>`.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ symbols! {
asm_const,
asm_experimental_arch,
asm_goto,
asm_goto_with_outputs,
asm_sym,
asm_unwind,
assert,
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/asm-goto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@ only-x86_64

#![crate_type = "rlib"]
#![feature(asm_goto)]
#![feature(asm_goto, asm_goto_with_outputs)]

use std::arch::asm;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/asm/x86_64/goto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//@ needs-asm-support

#![deny(unreachable_code)]
#![feature(asm_goto)]
#![feature(asm_goto, asm_goto_with_outputs)]

use std::arch::asm;

Expand Down
13 changes: 13 additions & 0 deletions tests/ui/feature-gates/feature-gate-asm_goto_with_outputs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ only-x86_64

#![feature(asm_goto)]

use std::arch::asm;

fn main() {
let mut _out: u64;
unsafe {
asm!("mov {}, 1", "jmp {}", out(reg) _out, label {});
//~^ ERROR using both label and outputs operands for inline assembly is unstable
}
}
13 changes: 13 additions & 0 deletions tests/ui/feature-gates/feature-gate-asm_goto_with_outputs.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0658]: using both label and outputs operands for inline assembly is unstable
--> $DIR/feature-gate-asm_goto_with_outputs.rs:10:52
|
LL | asm!("mov {}, 1", "jmp {}", out(reg) _out, label {});
| ^^^^^^^^
|
= note: see issue #119364 <https://github.com/rust-lang/rust/issues/119364> for more information
= help: add `#![feature(asm_goto_with_outputs)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0658`.

0 comments on commit cd8a355

Please sign in to comment.