clang x86 code generation/binary compatibility with GCC


I have this code:

void conv(long *pa, signed char b)
  *pa = static_cast<long>(b);

GCC 4.3.4 on SLES11, aswell as a recent GCC 4.7.1 compile this to:

  movsbq %sil, %rsi
  movq %rsi, (%rdi)

So the "signed char b" in sil is sign-extended to a 64 bit register.

clang emits this:

# BB#0: # %entry
  movslq %esi, %rax
  movq %rax, (%rdi)

clang is already passing char arguments in 32-bit registers sign-extended, and the generated code of this function relies on that. I have a case where this causes problems with jitted code that is calling such functions, and the assumption made by clang that the char has already been extended to 32 bit fails there.

Anyone can shine some light on this?

Thanks and best regards,

I believe LLVM is C ABI compliant. I don't know where it is documented but LLVM's assumption is caller must extend arguments to at least 32-bit.

See discussion here:

Looks like gcc does sign / zero extend its call arguments so there shouldn't any compatibility issue mixing llvm and gcc code.