-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Closed
Labels
A-inline-assemblyArea: Inline assembly (`asm!(…)`)Area: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant 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.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Description
#![feature(asm)]
fn main() {
let foo = 42u;
unsafe { asm!("lea rax, $0" :: "m"(foo) : "rax" : "intel"); }
}Expected result: rax contains the address of foo
However:
unknown operand type!
UNREACHABLE executed at /build/buildd/rust-nightly-201408090406~39bafb0~trusty/src/llvm/lib/Target/X86/X86AsmPrinter.cpp:208!
Aborted (core dumped)
Using a struct instead of an uint:
#![feature(asm)]
struct Foo(u64, u64);
fn main() {
let foo = Foo(42, 1337);
unsafe { asm!("lea rax, $0" :: "m"(foo) : "rax" : "intel"); }
}Now the compiler doesn't crash. But the emitted lea instruction references the memory location of the address of foo instead of foo itself:
; create foo
mov QWORD PTR [rbp-0x10],0x2a
mov QWORD PTR [rbp-0x8],0x539
; the (broken) implementation of the "m" constraint
lea rax,[rbp-0x10] ; this instruction should not be emitted
mov QWORD PTR [rbp-0x18],rax ; this instruction should not be emitted
; the actual inline asm
lea rax,[rbp-0x18] ; this should be: lea rax, [rbp-0x10]So basically "m"(foo) generates the code for "m"(&foo) if foo is a struct.
Metadata
Metadata
Assignees
Labels
A-inline-assemblyArea: Inline assembly (`asm!(…)`)Area: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant 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.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.