Description
Bugzilla Link | 16830 |
Version | trunk |
OS | Windows NT |
Blocks | #21794 #24719 #13712 |
CC | @asl,@efriedma-quic,@duck-37 |
Extended Description
So far as I can tell, the only register you can't touch in MS inline asm is ebp, but LLVM's x86 backend requires a BasePtr register which is separate from the frame pointer in ebp. It happens to hard code the choice of esi in X86RegisterInfo.cpp:
// Use a callee-saved register as the base pointer. These registers must
// not conflict with any ABI requirements. For example, in 32-bit mode PIC
// requires GOT in the EBX register before function calls via PLT GOT pointer.
BasePtr = Is64Bit ? X86::RBX : X86::ESI;
This will blow up if the inline asm clobbers esi.
Test case straight from LLVM's own lib/Support/Host.cpp:
bool GetX86CpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
unsigned *rECX, unsigned *rEDX) {
__asm {
mov eax,value
cpuid
mov esi,rEAX
mov dword ptr [esi],eax
mov esi,rEBX
mov dword ptr [esi],ebx
mov esi,rECX
mov dword ptr [esi],ecx
mov esi,rEDX
mov dword ptr [esi],edx
}
return false;
}
This generates x86 asm like:
$ clang -cc1 -fms-compatibility t.cpp -o - -cxx-abi microsoft -S
...
"?GetX86CpuIDAndInfo@@YA_NIPAI000@Z":
pushl %ebp
movl %esp, %ebp
pushl %ebx
pushl %edi
pushl %esi
subl $28, %esp
movl %esp, %esi
...
#APP
.intel_syntax
mov eax,dword ptr [esi + 24]
cpuid
mov esi,dword ptr [esi + 20]
mov dword ptr [esi],eax
mov esi,dword ptr [esi + 16]
mov dword ptr [esi],ebx
mov esi,dword ptr [esi + 12]
mov dword ptr [esi],ecx
mov esi,dword ptr [esi + 8]
mov dword ptr [esi],edx
.att_syntax
#NO_APP