Skip to content

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

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.

Activity

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

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. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions