Skip to content

Commit 1673331

Browse files
committed
Change InlineAsm to allow multiple targets instead
1 parent 929ea36 commit 1673331

File tree

22 files changed

+112
-91
lines changed

22 files changed

+112
-91
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
724724
operands,
725725
options: _,
726726
line_spans: _,
727-
destination: _,
727+
targets: _,
728728
unwind: _,
729729
} => {
730730
for op in operands {

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
163163
operands,
164164
options: _,
165165
line_spans: _,
166-
destination: _,
166+
targets: _,
167167
unwind: _,
168168
} => {
169169
for op in operands {

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16691669
self.assert_iscleanup(body, block_data, real_target, is_cleanup);
16701670
self.assert_iscleanup_unwind(body, block_data, unwind, is_cleanup);
16711671
}
1672-
TerminatorKind::InlineAsm { destination, unwind, .. } => {
1673-
if let Some(target) = destination {
1672+
TerminatorKind::InlineAsm { ref targets, unwind, .. } => {
1673+
for &target in targets {
16741674
self.assert_iscleanup(body, block_data, target, is_cleanup);
16751675
}
16761676
self.assert_iscleanup_unwind(body, block_data, unwind, is_cleanup);

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
445445
template,
446446
operands,
447447
options,
448-
destination,
448+
targets,
449449
line_spans: _,
450450
unwind: _,
451451
} => {
@@ -456,13 +456,25 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
456456
);
457457
}
458458

459+
let have_labels = if options.contains(InlineAsmOptions::NORETURN) {
460+
!targets.is_empty()
461+
} else {
462+
targets.len() > 1
463+
};
464+
if have_labels {
465+
fx.tcx.dcx().span_fatal(
466+
source_info.span,
467+
"cranelift doesn't support labels in inline assembly.",
468+
);
469+
}
470+
459471
crate::inline_asm::codegen_inline_asm_terminator(
460472
fx,
461473
source_info.span,
462474
template,
463475
operands,
464476
*options,
465-
*destination,
477+
targets.get(0).copied(),
466478
);
467479
}
468480
TerminatorKind::UnwindTerminate(reason) => {

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12761276
ref operands,
12771277
options,
12781278
line_spans,
1279-
destination,
1279+
ref targets,
12801280
unwind,
12811281
} => self.codegen_asm_terminator(
12821282
helper,
@@ -1286,7 +1286,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12861286
operands,
12871287
options,
12881288
line_spans,
1289-
destination,
1289+
targets.get(0).copied(),
12901290
unwind,
12911291
self.instance,
12921292
mergeable_succ(),

compiler/rustc_const_eval/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,6 @@ const_eval_non_const_fn_call =
214214
const_eval_non_const_impl =
215215
impl defined here, but it is not `const`
216216
217-
const_eval_noreturn_asm_returned =
218-
returned from noreturn inline assembly
219-
220217
const_eval_not_enough_caller_args =
221218
calling a function with fewer arguments than it requires
222219

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,17 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
373373
kind: Option<MemoryKind<Self::MemoryKind>>,
374374
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra, Self::Bytes>>>;
375375

376+
/// Evaluate the inline assembly.
377+
///
378+
/// This should take care of jumping to the next block (one of `targets`) when asm goto
379+
/// is triggered, `targets[0]` when the assembly falls through, or diverge in case of
380+
/// `InlineAsmOptions::NORETURN` being set.
376381
fn eval_inline_asm(
377382
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
378383
_template: &'tcx [InlineAsmTemplatePiece],
379384
_operands: &[mir::InlineAsmOperand<'tcx>],
380385
_options: InlineAsmOptions,
386+
_targets: &[mir::BasicBlock],
381387
) -> InterpResult<'tcx> {
382388
throw_unsup_format!("inline assembly is not supported")
383389
}

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::borrow::Cow;
22

3-
use rustc_ast::ast::InlineAsmOptions;
43
use rustc_middle::{
54
mir,
65
ty::{
@@ -224,15 +223,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
224223
terminator.kind
225224
),
226225

227-
InlineAsm { template, ref operands, options, destination, .. } => {
228-
M::eval_inline_asm(self, template, operands, options)?;
229-
if options.contains(InlineAsmOptions::NORETURN) {
230-
throw_ub_custom!(fluent::const_eval_noreturn_asm_returned);
231-
}
232-
self.go_to_block(
233-
destination
234-
.expect("InlineAsm terminators without noreturn must have a destination"),
235-
)
226+
InlineAsm { template, ref operands, options, ref targets, .. } => {
227+
M::eval_inline_asm(self, template, operands, options, targets)?;
236228
}
237229
}
238230

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
481481
self.check_edge(location, *real_target, EdgeKind::Normal);
482482
self.check_unwind_edge(location, *unwind);
483483
}
484-
TerminatorKind::InlineAsm { destination, unwind, .. } => {
485-
if let Some(destination) = destination {
486-
self.check_edge(location, *destination, EdgeKind::Normal);
484+
TerminatorKind::InlineAsm { targets, unwind, .. } => {
485+
for &target in targets {
486+
self.check_edge(location, target, EdgeKind::Normal);
487487
}
488488
self.check_unwind_edge(location, *unwind);
489489
}

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,13 +1651,13 @@ mod size_asserts {
16511651
use super::*;
16521652
use rustc_data_structures::static_assert_size;
16531653
// tidy-alphabetical-start
1654-
static_assert_size!(BasicBlockData<'_>, 136);
1654+
static_assert_size!(BasicBlockData<'_>, 144);
16551655
static_assert_size!(LocalDecl<'_>, 40);
16561656
static_assert_size!(SourceScopeData<'_>, 72);
16571657
static_assert_size!(Statement<'_>, 32);
16581658
static_assert_size!(StatementKind<'_>, 16);
1659-
static_assert_size!(Terminator<'_>, 104);
1660-
static_assert_size!(TerminatorKind<'_>, 88);
1659+
static_assert_size!(Terminator<'_>, 112);
1660+
static_assert_size!(TerminatorKind<'_>, 96);
16611661
static_assert_size!(VarDebugInfo<'_>, 88);
16621662
// tidy-alphabetical-end
16631663
}

0 commit comments

Comments
 (0)