Invalid operand for inline asm constraint 'i' when writing inline x86_64 assembly

1.9k views Asked by At

The code below used to build just fine back in April (Rust version ~1.6), but it doesn't anymore.

#![feature(asm)]

enum MyEnum { One = 1 }

fn main() {
    unsafe {
        asm!("nop" : : "i" (MyEnum::One as isize) : : ); // broken
    }
}

The error message does not point to any obvious changes that might be causing this.

1

There are 1 answers

2
Timothy Baldwin On BEST ANSWER

The value for the "i" constraint must be a compile-time constant and you are supplying it something that isn't. If you move the addition into Rust, you could use a register as well as a constant using the constraints "ri".

Whether something is a constant for the purpose of inline assembler can be affected by optimization options.