Skip to content

Commit b8b6962

Browse files
committed
Make asm_goto_with_outputs a separate feature gate
1 parent d12b15b commit b8b6962

File tree

8 files changed

+68
-11
lines changed

8 files changed

+68
-11
lines changed

compiler/rustc_ast_lowering/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ ast_lowering_underscore_expr_lhs_assign =
175175
.label = `_` not allowed here
176176
177177
ast_lowering_unstable_inline_assembly = inline assembly is not stable yet on this architecture
178+
ast_lowering_unstable_inline_assembly_label_operand_with_outputs =
179+
using both label and outputs operands for inline assembly is unstable
178180
ast_lowering_unstable_inline_assembly_label_operands =
179181
label operands for inline assembly are unstable
180182
ast_lowering_unstable_may_unwind = the `may_unwind` option is unstable

compiler/rustc_ast_lowering/src/asm.rs

+35-9
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
237237
}
238238
}
239239
InlineAsmOperand::Label { block } => {
240-
if !self.tcx.features().asm_goto() {
241-
feature_err(
242-
sess,
243-
sym::asm_goto,
244-
*op_sp,
245-
fluent::ast_lowering_unstable_inline_assembly_label_operands,
246-
)
247-
.emit();
248-
}
249240
hir::InlineAsmOperand::Label { block: self.lower_block(block, false) }
250241
}
251242
};
@@ -464,6 +455,41 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
464455
}
465456
}
466457

458+
// Feature gate checking for asm goto.
459+
if let Some((_, op_sp)) =
460+
operands.iter().find(|(op, _)| matches!(op, hir::InlineAsmOperand::Label { .. }))
461+
{
462+
if !self.tcx.features().asm_goto() {
463+
feature_err(
464+
sess,
465+
sym::asm_goto,
466+
*op_sp,
467+
fluent::ast_lowering_unstable_inline_assembly_label_operands,
468+
)
469+
.emit();
470+
}
471+
472+
// In addition, check if an output operand is used.
473+
// This is gated behind an additional feature.
474+
let output_operand_used = operands.iter().any(|(op, _)| {
475+
matches!(
476+
op,
477+
hir::InlineAsmOperand::Out { expr: Some(_), .. }
478+
| hir::InlineAsmOperand::InOut { .. }
479+
| hir::InlineAsmOperand::SplitInOut { out_expr: Some(_), .. }
480+
)
481+
});
482+
if output_operand_used && !self.tcx.features().asm_goto_with_outputs() {
483+
feature_err(
484+
sess,
485+
sym::asm_goto_with_outputs,
486+
*op_sp,
487+
fluent::ast_lowering_unstable_inline_assembly_label_operand_with_outputs,
488+
)
489+
.emit();
490+
}
491+
}
492+
467493
let operands = self.arena.alloc_from_iter(operands);
468494
let template = self.arena.alloc_from_iter(asm.template.iter().cloned());
469495
let template_strs = self.arena.alloc_from_iter(

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ declare_features! (
375375
(unstable, asm_experimental_arch, "1.58.0", Some(93335)),
376376
/// Allows using `label` operands in inline assembly.
377377
(unstable, asm_goto, "1.78.0", Some(119364)),
378+
/// Allows using `label` operands in inline assembly together with output operands.
379+
(unstable, asm_goto_with_outputs, "CURRENT_RUSTC_VERSION", Some(119364)),
378380
/// Allows the `may_unwind` option in inline assembly.
379381
(unstable, asm_unwind, "1.58.0", Some(93334)),
380382
/// Allows users to enforce equality of associated constants `TraitImpl<AssocConst=3>`.

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ symbols! {
418418
asm_const,
419419
asm_experimental_arch,
420420
asm_goto,
421+
asm_goto_with_outputs,
421422
asm_sym,
422423
asm_unwind,
423424
assert,

tests/codegen/asm/goto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ only-x86_64
33

44
#![crate_type = "rlib"]
5-
#![feature(asm_goto)]
5+
#![feature(asm_goto, asm_goto_with_outputs)]
66

77
use std::arch::asm;
88

tests/ui/asm/x86_64/goto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//@ needs-asm-support
44

55
#![deny(unreachable_code)]
6-
#![feature(asm_goto)]
6+
#![feature(asm_goto, asm_goto_with_outputs)]
77

88
use std::arch::asm;
99

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ only-x86_64
2+
3+
#![feature(asm_goto)]
4+
5+
use std::arch::asm;
6+
7+
fn main() {
8+
let mut _out: u64;
9+
unsafe {
10+
asm!("mov {}, 1", "jmp {}", out(reg) _out, label {});
11+
//~^ ERROR using both label and outputs operands for inline assembly is unstable
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: using both label and outputs operands for inline assembly is unstable
2+
--> $DIR/feature-gate-asm_goto_with_outputs.rs:10:52
3+
|
4+
LL | asm!("mov {}, 1", "jmp {}", out(reg) _out, label {});
5+
| ^^^^^^^^
6+
|
7+
= note: see issue #119364 <https://github.com/rust-lang/rust/issues/119364> for more information
8+
= help: add `#![feature(asm_goto_with_outputs)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)