Clang compilation triggered "invalid operand for instruction" build error


Clang-14 compilation of User space c code leads to below build error.
core.c:1274:2: error: invalid operand for instruction
:1:2384: note: instantiated into assembly here
.core.c:1274:2: error: invalid operand for instruction

The exact line of code that triggered error is as given below.
scan_break_old( scanner, ctx) //prototype of function…please ignore exact name.
int ret = 0;
“Init_entry:” —> Error triggered here.
“sub $64, %rsp;”
“push %r12;”
“push %r13;”

“or %r15, %rcx;”
“jmp Save_Exit_entry;”
return ret;
Any input why inline assembler code execution failing with above build error?


It seems you didn’t use the right ". The changed code can be compiled correctly. Compiler Explorer

Dear Phoebe,

Seems the small piece of code is executed successfully in my system too with clang-14.0.6 compiler.
Let me attach full piece of code that is throwing error as i mentioned in my first comment and of course observed it in compiler explorer when i try to execute full piece of code.

complete-code.c (17.9 KB)

It seems the diagnose info failed to locate the right position due to no line ending in the whole assembly. The true ill assembly is movzx which should be replaced by movzbq or movzwq.

Dear Phoebe

Thank you for your input. That means ‘movzx’ is not recognized by clang compiler
where as confusion prevails in choosing between ‘movzbq’ or movzwq’ for operation between operands.? if register data length is byte size, then ‘movzbq’ should be used otherwise ‘movzwq’?


In movzx (%r10), %r13, the width of the memory location is ambiguous. There are two possible variants with a 64-bit destination: movzbq (1 byte memory location), or movzwq (2 byte memory location). (If the memory operand is 4 bytes, you would use a “mov” instead.) The GNU assembler will assume you meant movzbq, but clang requires explicitly specifying which one you mean.

Filed Unclear error message for incorrect "movzx" · Issue #59949 · llvm/llvm-project · GitHub to track improving the error message.