Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 20a8be8

Browse files
committedDec 23, 2024
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 ede56d1 commit 20a8be8

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed
 

‎src/inline-assembly.md

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

183+
r[asm.operand-type.supported-operands.label]
184+
* `label <block>`
185+
- The address of the block is substituted into the asm template string. The assembly block may jump to the substituted addresses.
186+
- After execution of the block, the `asm!` expression returns.
187+
- The type of the block must be unit or `!` (never).
188+
- 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.
189+
183190
r[asm.operand-type.left-to-right]
184191
Operand expressions are evaluated from left to right, just like function call arguments.
185192
After the `asm!` has executed, outputs are written to in left to right order.
@@ -553,6 +560,8 @@ r[asm.options.supported-options.noreturn]
553560
- `noreturn`: The `asm!` block never returns, and its return type is defined as `!` (never).
554561
Behavior is undefined if execution falls through past the end of the asm code.
555562
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.
563+
- 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.
564+
The entire `asm!` block will have unit type in this case, unless all label blocks diverge, in which case the return type is `!`.
556565

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

578587
r[asm.options.checks.noreturn]
579-
- It is a compile-time error to specify `noreturn` on an asm block with outputs.
588+
- It is a compile-time error to specify `noreturn` on an asm block with outputs and without labels.
589+
590+
r[asm.options.checks.label-with-outputs]
591+
- It is a compile-time error to specify label on an asm block with outputs.
580592

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

0 commit comments

Comments
 (0)
Failed to load comments.