Skip to content

x86 asm! accepts "lock" as a standalone instruction #82314

Closed
@jonas-schievink

Description

@jonas-schievink
#![feature(asm)]

#[no_mangle]
pub fn aaaaaaaaaaaaaaaaaa(x: &mut u32) {
    unsafe { asm!("lock"); }
    *x += 1;
}

This is not rejected, and, according to objdump, results in the following assembly (when optimizations are on):

0000000000000000 <aaaaaaaaaaaaaaaaaa>:
   0:	48 83 ec 08          	sub    $0x8,%rsp
   4:	f0 83 07 01          	lock addl $0x1,(%rdi)
   8:	58                   	pop    %rax
   9:	c3                   	ret    

I'd expect this to result in an error, since lock by itself isn't a valid instruction (it doesn't really seem desirable to let asm!() affect how rustc-produced instructions are decoded).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions