Skip to content

"asm_sub_register" could provide a bit more helpful information #121593

Closed

Description

Code

pub unsafe fn _mm_stream_si32(mem_addr: *mut i32, a: i32) {
    std::arch::asm!(
        "movnti [{mem_addr}], {a}",
        mem_addr = in(reg) mem_addr,
        a = in(reg) a,
    );
}

Current output

warning: formatting may not be suitable for sub-register argument
 --> src/lib.rs:3:31
  |
3 |         "movnti [{mem_addr}], {a}",
  |                               ^^^
4 |         mem_addr = in(reg) mem_addr,
5 |         a = in(reg) a,
  |                     - for this argument
  |
  = help: use `{1:e}` to have the register formatted as `eax`
  = help: or use `{1:r}` to keep the default formatting of `rax`
  = note: `#[warn(asm_sub_register)]` on by default

Desired output

warning: formatting may not be suitable for sub-register argument
 --> src/lib.rs:3:31
  |
3 |         "movnti [{mem_addr}], {a}",
  |                               ^^^
4 |         mem_addr = in(reg) mem_addr,
5 |         a = in(reg) a,
  |                     - for this argument
  |
  = help: use `{1:e}` to have the register formatted as `eax` (for 32bit values)
  = help: or use `{1:r}` to keep the default formatting of `rax` (for 64bit values)
  = note: `#[warn(asm_sub_register)]` on by default

Rationale and extra context

This is my first time writing inline assembly. I don't yet know all the Intel register class prefixes by hand. So telling me which prefix corresponds to which size would be very helpful. :)

Other cases

No response

Rust Version

$ rustc --version -v
rustc 1.78.0-nightly (8f359beca 2024-02-23)
binary: rustc
commit-hash: 8f359beca4e58bc3ae795a666301a8f47023044c
commit-date: 2024-02-23
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions