Skip to content

Commit

Permalink
Add assertions and clarify asm-goto with noreturn
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Feb 24, 2024
1 parent 84bc9e9 commit 626a5f5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/asm.rs
Expand Up @@ -465,6 +465,7 @@ pub(crate) fn inline_asm_call<'ll>(
);

let call = if !labels.is_empty() {
assert!(catch_funclet.is_none());
bx.callbr(fty, None, None, v, inputs, dest.unwrap(), labels, None)
} else if let Some((catch, funclet)) = catch_funclet {
bx.invoke(fty, None, None, v, inputs, dest.unwrap(), catch, funclet)
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Expand Up @@ -265,6 +265,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
};

if operands.iter().any(|x| matches!(x, InlineAsmOperandRef::Label { .. })) {
assert!(unwind_target.is_none());
let ret_llbb = if let Some(target) = destination {
fx.llbb(target)
} else {
Expand Down
8 changes: 7 additions & 1 deletion src/doc/unstable-book/src/language-features/asm-goto.md
Expand Up @@ -21,4 +21,10 @@ unsafe {
}
```

The block must have unit type.
The block must have unit type or diverge.

When `label <block>` is used together with `noreturn` option, it means that the
assembly will not fallthrough. It's allowed to jump to a label within the
assembly. In this case, the entire `asm!` expression will have an unit type as
opposed to diverging, if not all label blocks diverge. The `asm!` expression
still diverges if `noreturn` option is used and all label blocks diverge.

0 comments on commit 626a5f5

Please sign in to comment.