Skip to content

Commit 0d28a09

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 b06e1f3 commit 0d28a09

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/inline-assembly.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ format_string := STRING_LITERAL / RAW_STRING_LITERAL
5454
dir_spec := "in" / "out" / "lateout" / "inout" / "inlateout"
5555
reg_spec := <register class> / "\"" <explicit register> "\""
5656
operand_expr := expr / "_" / expr "=>" expr / expr "=>" "_"
57-
reg_operand := [ident "="] dir_spec "(" reg_spec ")" operand_expr / sym <path> / const <expr>
57+
reg_operand := [ident "="] dir_spec "(" reg_spec ")" operand_expr / sym <path> / const <expr> / label <block>
5858
clobber_abi := "clobber_abi(" <abi> *("," <abi>) [","] ")"
5959
option := "pure" / "nomem" / "readonly" / "preserves_flags" / "noreturn" / "nostack" / "att_syntax" / "raw"
6060
options := "options(" option *("," option) [","] ")"
@@ -176,6 +176,13 @@ r[asm.operand-type.supported-operands.sym]
176176
- The type of the expression may be any integer type, but defaults to `i32` just like integer literals.
177177
- The value of the expression is formatted as a string and substituted directly into the asm template string.
178178

179+
r[asm.operand-type.supported-operands.label]
180+
* `label <block>`
181+
- The address of the block is substituted into the asm template string. The assembly block may jump to the substituted addresses.
182+
- After execution of the block, the `asm!` expression returns.
183+
- The type of the block must be unit or `!` (never).
184+
- 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.
185+
179186
r[asm.operand-type.left-to-right]
180187
Operand expressions are evaluated from left to right, just like function call arguments.
181188
After the `asm!` has executed, outputs are written to in left to right order.
@@ -546,6 +553,8 @@ r[asm.options.supported-options.noreturn]
546553
- `noreturn`: The `asm!` block never returns, and its return type is defined as `!` (never).
547554
Behavior is undefined if execution falls through past the end of the asm code.
548555
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.
556+
- 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.
557+
The entire `asm!` block will have unit type in this case, unless all label blocks diverge, in which case the return type is `!`.
549558

550559
r[asm.options.supported-options.nostack]
551560
- `nostack`: The `asm!` block does not push data to the stack, or write to the stack red-zone (if supported by the target).
@@ -569,7 +578,10 @@ r[asm.options.checks.pure]
569578
- It is a compile-time error to specify `pure` on an asm block with no outputs or only discarded outputs (`_`).
570579

571580
r[asm.options.checks.noreturn]
572-
- It is a compile-time error to specify `noreturn` on an asm block with outputs.
581+
- It is a compile-time error to specify `noreturn` on an asm block with outputs and without labels.
582+
583+
r[asm.options.checks.label-with-outputs]
584+
- It is a compile-time error to specify label on an asm block with outputs.
573585

574586
r[asm.options.global_asm-restriction]
575587
`global_asm!` only supports the `att_syntax` and `raw` options.

0 commit comments

Comments
 (0)