Skip to content

asm! macro does not mark variable as used #77915

Closed
@Soveu

Description

@Soveu

I tried this code:

unsafe fn rep_movsb(mut dest: *mut u8, mut src: *const u8, mut n: usize) -> *mut u8 {
    while n != 0 {
        asm!(
            "rep movsb",
            inout("rcx") n,
            inout("rsi") src,
            inout("rdi") dest,
        );
    }

    return dest;
}

I expected to see this happen:
Compiler doesn't generate any warnings

Instead, this happened:
Rustc says that src is unused, even though it is declared as inout in asm.
Adding arrows (inout("rsi") src => src) fixes it

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (8dae8cdcc 2020-10-12)
binary: rustc
commit-hash: 8dae8cdcc8fa879cea6a4bbbfa5b32e97be4c306
commit-date: 2020-10-12
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0

Metadata

Metadata

Assignees

Labels

A-inline-assemblyArea: Inline assembly (`asm!(…)`)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.F-asm`#![feature(asm)]` (not `llvm_asm`)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions