Skip to content

Commit 914f796

Browse files
committed
Add reference for asm-goto
The asm-goto-with-outputs is still unstable, so in the reference it's still mentioned as forbidden by a check rule.
1 parent de2d528 commit 914f796

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/inline-assembly.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ format_string := STRING_LITERAL / RAW_STRING_LITERAL
5252
dir_spec := "in" / "out" / "lateout" / "inout" / "inlateout"
5353
reg_spec := <register class> / "\"" <explicit register> "\""
5454
operand_expr := expr / "_" / expr "=>" expr / expr "=>" "_"
55-
reg_operand := [ident "="] dir_spec "(" reg_spec ")" operand_expr / sym <path> / const <expr>
55+
reg_operand := [ident "="] dir_spec "(" reg_spec ")" operand_expr / sym <path> / const <expr> / label <block>
5656
clobber_abi := "clobber_abi(" <abi> *("," <abi>) [","] ")"
5757
option := "pure" / "nomem" / "readonly" / "preserves_flags" / "noreturn" / "nostack" / "att_syntax" / "raw"
5858
options := "options(" option *("," option) [","] ")"
@@ -354,6 +354,23 @@ assert_eq!(y, [3, 2, 0, 1]);
354354
# }
355355
```
356356

357+
r[asm.operand-type.supported-operands.label]
358+
* `label <block>`
359+
- The address of the block is substituted into the asm template string. The assembly block may jump to the substituted addresses.
360+
- After execution of the block, the `asm!` expression returns.
361+
- The type of the block must be unit or `!` (never).
362+
- The block starts new safety context; despite the outer `unsafe` needed for `asm!`, you need an extra `unsafe` to perform unsafe operations inside the block.
363+
364+
```rust
365+
# #[cfg(target_arch = "x86_64")]
366+
unsafe {
367+
core::arch::asm!("jmp {}", label {
368+
println!("Hello from inline assembly label");
369+
});
370+
}
371+
```
372+
373+
357374
r[asm.operand-type.left-to-right]
358375
Operand expressions are evaluated from left to right, just like function call arguments.
359376
After the `asm!` has executed, outputs are written to in left to right order.
@@ -1080,6 +1097,8 @@ r[asm.options.supported-options.noreturn]
10801097
- `noreturn`: The `asm!` block never returns, and its return type is defined as `!` (never).
10811098
Behavior is undefined if execution falls through past the end of the asm code.
10821099
A `noreturn` asm block behaves just like a function which doesn't return; notably, local variables in scope are not dropped before it is invoked.
1100+
- When labels are present, `noreturn` means the execution of the `asm!` block never falls through; the asm block may only exit by jumping to one of the specified blocks.
1101+
The entire `asm!` block will have unit type in this case, unless all label blocks diverge, in which case the return type is `!`.
10831102

10841103
<!-- no_run: This test aborts at runtime -->
10851104
```rust,no_run
@@ -1164,7 +1183,10 @@ unsafe { core::arch::asm!("", options(pure)); }
11641183
```
11651184

11661185
r[asm.options.checks.noreturn]
1167-
- It is a compile-time error to specify `noreturn` on an asm block with outputs.
1186+
- It is a compile-time error to specify `noreturn` on an asm block with outputs and without labels.
1187+
1188+
r[asm.options.checks.label-with-outputs]
1189+
- It is a compile-time error to specify label on an asm block with outputs.
11681190

11691191
```rust,compile_fail
11701192
# #[cfg(target_arch = "x86_64")] {

0 commit comments

Comments
 (0)