Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
stevecheckoway opened this issue Jan 8, 2020 · 3 comments
Labels
A-inline-assembly Area: inline asm!(..) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@stevecheckoway
Copy link

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.

@varkor varkor added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 8, 2020
@jonas-schievink jonas-schievink added A-inline-assembly Area: inline asm!(..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 8, 2020
@Centril Centril added the requires-nightly This issue requires a nightly compiler in some way. label Jan 8, 2020
@Amanieu
Copy link
Member

Amanieu commented May 22, 2020

This issue does not apply to the new asm! (RFC 2850) which uses sym operands. Note that sym operands only produce the raw symbol name, you are responsible for adding offset as needed.

The legacy llvm_asm! is deprecated and is no longer maintained.

@Amanieu Amanieu closed this as completed May 22, 2020
@stevecheckoway
Copy link
Author

Thanks. I'll take a look at the new asm!.

@Amanieu
Copy link
Member

Amanieu commented May 22, 2020

I believe we got the LLVM bug fix when we upgraded to LLVM 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: inline asm!(..) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants