[cfe-dev] clang x86 code generation/binary compatibility with GCC
Richtarsky, Martin
martin.richtarsky at sap.com
Fri Oct 12 07:55:36 PDT 2012
Hi,
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:
.cfi_startproc
movsbq %sil, %rsi
movq %rsi, (%rdi)
ret
.cfi_endproc
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)
ret
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,
Martin
More information about the cfe-dev
mailing list