Add reference for asm-goto by nbdd0121 · Pull Request #1693 · rust-lang/reference

@nbdd0121 mentioned this pull request

Dec 4, 2024

@ojeda ojeda mentioned this pull request

Dec 4, 2024

48 tasks

Amanieu

traviscross

The asm-goto-with-outputs is still unstable, so in the reference it's
still mentioned as forbidden by a check rule.

@traviscross @nbdd0121

The latter now only means the entire block, while the former means the
assembly code specified within the block (thus excluding `label` blocks).

Darksonn

@nbdd0121 @Darksonn

Co-authored-by: Alice Ryhl <aliceryhl@google.com>
Update more cases where the phrasing could potentially have been
interpreted as affecting a `label` block.

@joshtriplett @nbdd0121

Let's make some clarifications of substance and editorial tweaks to
the changes for `asm_goto`.  We add an example, we change various
wording to be more clear -- in particular, we significantly revise the
section on `noreturn` to unify the statement of the rules -- and we
replace remaining uses of "asm code" with "assembly code" to match our
verbiage elsewhere.

The main clarification of substance is that for requirements that must
be upheld when falling through the assembly, such as he requirement to
restore the stack pointer, we must also note that the requirement must
be satisfied before jumping to any `label` blocks.

traviscross

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Mar 17, 2025
…rcote

Stabilize `asm_goto` feature gate

Stabilize `asm_goto` feature (tracked by rust-lang#119364). The issue will remain open and be updated to track `asm_goto_with_outputs`.

Reference PR: rust-lang/reference#1693

# Stabilization Report

This feature adds a `label <block>` operand type to `asm!`. `<block>` must be a block expression with type unit or never. The address of the block is substituted and the assembly may jump to the block. When block completes the `asm!` block returns and continues execution.

The block starts a new safety context and unsafe operations within must have additional `unsafe`s; the effect of `unsafe` that surrounds `asm!` block is cancelled. See rust-lang#119364 (comment) and rust-lang#131544.

It's currently forbidden to use `asm_goto` with output operands; that is still unstable under `asm_goto_with_outputs`.

Example:

```rust
unsafe {
    asm!(
        "jmp {}",
        label {
            println!("Jumped from asm!");
        }
    );
}
```

Tests:
- tests/ui/asm/x86_64/goto.rs
- tests/ui/asm/x86_64/goto-block-safe.stderr
- tests/ui/asm/x86_64/bad-options.rs
- tests/codegen/asm/goto.rs

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Mar 17, 2025
Rollup merge of rust-lang#133870 - nbdd0121:asm, r=traviscross,nnethercote

Stabilize `asm_goto` feature gate

Stabilize `asm_goto` feature (tracked by rust-lang#119364). The issue will remain open and be updated to track `asm_goto_with_outputs`.

Reference PR: rust-lang/reference#1693

# Stabilization Report

This feature adds a `label <block>` operand type to `asm!`. `<block>` must be a block expression with type unit or never. The address of the block is substituted and the assembly may jump to the block. When block completes the `asm!` block returns and continues execution.

The block starts a new safety context and unsafe operations within must have additional `unsafe`s; the effect of `unsafe` that surrounds `asm!` block is cancelled. See rust-lang#119364 (comment) and rust-lang#131544.

It's currently forbidden to use `asm_goto` with output operands; that is still unstable under `asm_goto_with_outputs`.

Example:

```rust
unsafe {
    asm!(
        "jmp {}",
        label {
            println!("Jumped from asm!");
        }
    );
}
```

Tests:
- tests/ui/asm/x86_64/goto.rs
- tests/ui/asm/x86_64/goto-block-safe.stderr
- tests/ui/asm/x86_64/bad-options.rs
- tests/codegen/asm/goto.rs

github-actions bot pushed a commit to rust-lang/miri that referenced this pull request

Mar 20, 2025
Stabilize `asm_goto` feature gate

Stabilize `asm_goto` feature (tracked by #119364). The issue will remain open and be updated to track `asm_goto_with_outputs`.

Reference PR: rust-lang/reference#1693

# Stabilization Report

This feature adds a `label <block>` operand type to `asm!`. `<block>` must be a block expression with type unit or never. The address of the block is substituted and the assembly may jump to the block. When block completes the `asm!` block returns and continues execution.

The block starts a new safety context and unsafe operations within must have additional `unsafe`s; the effect of `unsafe` that surrounds `asm!` block is cancelled. See rust-lang/rust#119364 (comment) and rust-lang/rust#131544.

It's currently forbidden to use `asm_goto` with output operands; that is still unstable under `asm_goto_with_outputs`.

Example:

```rust
unsafe {
    asm!(
        "jmp {}",
        label {
            println!("Jumped from asm!");
        }
    );
}
```

Tests:
- tests/ui/asm/x86_64/goto.rs
- tests/ui/asm/x86_64/goto-block-safe.stderr
- tests/ui/asm/x86_64/bad-options.rs
- tests/codegen/asm/goto.rs

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Mar 24, 2025

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Mar 24, 2025

@ojeda ojeda mentioned this pull request

Feb 8, 2026

57 tasks