Odd error with the "X" inline assembly constraint

Segher Boessenkool segher@kernel.crashing.org
Fri Jan 5 18:46:12 GMT 2024


On Fri, Jan 05, 2024 at 05:30:51PM +0100, David Brown via Gcc-help wrote:
> However, when I use just "asm ("" : "+X" (x));", I get an error message 
> "error: inconsistent operand constraints in an 'asm'".  I have no idea 
> why this is an issue.

The C constraint means "Any operand whatsoever is allowed."  Here you
are saying to use it both as input and as output, and GCC does not know
how to reload wherever it chose to put it.

Using "X" for outputs is strange already, fwiw, but tieing it to an
input is, hrm, let's call it "creative" :-)

> I'd imagine that the "X" operand doesn't see much use in real inline 
> assembly

It is used rather often.  But usually for inputs, and (as you found out)
trying to use if for an input and for an output at the same time does
not work reliably.

"+" really creates two operands, and ties them together.  Writing
  asm("oink" : "+X"(bla));
is shorthand for
  asm("oink" : "=X"(bla) : "0"(bla));


Segher


More information about the Gcc-help mailing list