Skip to content

Commit 0178ba2

Browse files
committed
Make asm_goto_with_outputs a separate feature gate
1 parent 73f8309 commit 0178ba2

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
@@ -181,6 +181,8 @@ ast_lowering_underscore_expr_lhs_assign =
181181
.label = `_` not allowed here
182182
183183
ast_lowering_unstable_inline_assembly = inline assembly is not stable yet on this architecture
184+
ast_lowering_unstable_inline_assembly_label_operand_with_outputs =
185+
using both label and output operands for inline assembly is unstable
184186
ast_lowering_unstable_inline_assembly_label_operands =
185187
label operands for inline assembly are unstable
186188
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
@@ -239,15 +239,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
239239
}
240240
}
241241
InlineAsmOperand::Label { block } => {
242-
if !self.tcx.features().asm_goto() {
243-
feature_err(
244-
sess,
245-
sym::asm_goto,
246-
*op_sp,
247-
fluent::ast_lowering_unstable_inline_assembly_label_operands,
248-
)
249-
.emit();
250-
}
251242
hir::InlineAsmOperand::Label { block: self.lower_block(block, false) }
252243
}
253244
};
@@ -466,6 +457,41 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
466457
}
467458
}
468459

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

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ declare_features! (
378378
(unstable, asm_experimental_arch, "1.58.0", Some(93335)),
379379
/// Allows using `label` operands in inline assembly.
380380
(unstable, asm_goto, "1.78.0", Some(119364)),
381+
/// Allows using `label` operands in inline assembly together with output operands.
382+
(unstable, asm_goto_with_outputs, "CURRENT_RUSTC_VERSION", Some(119364)),
381383
/// Allows the `may_unwind` option in inline assembly.
382384
(unstable, asm_unwind, "1.58.0", Some(93334)),
383385
/// 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
@@ -417,6 +417,7 @@ symbols! {
417417
asm_const,
418418
asm_experimental_arch,
419419
asm_goto,
420+
asm_goto_with_outputs,
420421
asm_sym,
421422
asm_unwind,
422423
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 output 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 output 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)