Closed
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.