Is this a clang bug? (asm + register + aarch64)

Hi All,
I would expect the x2 argument register to be saved and restored when used beyond an asm block. The movs between x2 and x19 oddly seem to be in the wrong direction. Register x19 is later used with an unexpected value and the program segfaults. Is this a bug or the expected behaviour? The architecture is aarch64.


44cdc: aa1303e2 mov x2, x19
44ce0: f9401850 ldr x16, [x2,#48]
44ce4: 91002051 add x17, x2, #0x8
44ce8: f9000bf6 str x22, [sp,#16]
44cec: 90000041 adrp x1, 4c000 <…+0x2c94>
------volatile asm block with x2, x17 as inputs, x16 as output---------

Hi Alex,

I would expect the x2 argument register to be saved and restored when used
beyond an asm block. The movs between x2 and x19 oddly seem to be in the
wrong direction. Register x19 is later used with an unexpected value and
the program segfaults. Is this a bug or the expected behaviour? The
architecture is aarch64.

Nothing in the snippet you posted clobbers x2 so I'd expect that to be
valid code. If your inline asm block makes actual function calls then
it needs to mark the registers that don't get preserved as clobbered.
LLVM won't inspect the string looking for a function call or infer its
ABI.

Cheers.

Tim.

asm blocks don't behave like function calls, the default is that they
affect nothing. As far as Clang is concerned your asm block neither
uses nor clobbers x2 unless you say it does.

Tim.