Skip to content

Inline asm!() with "i" constraint produces the wrong assembly due to (now-fixed) LLVM bug #68021

Closed
@stevecheckoway

Description

@stevecheckoway

Nightly rustc correctly handles the first of these two inline assembly statements but silently does the wrong thing with the second one (example on Compiler Explorer).

#![feature(asm)]
static FOO: usize = 0;

pub unsafe fn example() {
    asm!("movq $0, %rax" :: "i"(&FOO) :: "volatile");
    asm!("mov rbx, $0" :: "i"(&FOO) :: "intel", "volatile");
}

The issue is LLVM's call asm inteldialect had a bug that was fixed. I think the solution is to cherry-pick the LLVM fix.

You can see the problem directly using LLVM IR here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.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