http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55171



--- Comment #4 from Adam Mitz <mitza at ociweb dot com> 2012-11-07 21:10:26 UTC 
---

The generated code for the thunk is incorrect in that it re-uses the %eax

register, clobbering the original "this" value:



Dump of assembler code for function _ZTv0_n16_NK7Derived3fooEv:

=> 0x004019d1 <+0>:     mov    0x4(%esp),%eax

   0x004019d5 <+4>:     mov    (%eax),%eax

   0x004019d7 <+6>:     add    -0x10(%eax),%eax

   0x004019da <+9>:     mov    %eax,0x4(%esp)

   0x004019de <+13>:    jmp    0x401932 <Derived::foo() const>



vtable = *base_this

derived_this = vtable + *(vtable - 16)



The same thunk on Linux uses both %eax and %ecx:



Dump of assembler code for function _ZTv0_n16_NK7Derived3fooEv:

=> 0x08048eab <+0>:     mov    0x8(%esp),%eax

   0x08048eaf <+4>:     mov    (%eax),%ecx

   0x08048eb1 <+6>:     add    -0x10(%ecx),%eax

   0x08048eb4 <+9>:     mov    %eax,0x8(%esp)

   0x08048eb8 <+13>:    jmp    0x8048e08 <Derived::foo() const>



vtable = *base_this

derived_this = base_this + (*vtable - 16)



The MinGW version must either clobber a scratch register like %ecx or %edx, or

if this isn't possible (fastcall/thiscall?), save to the stack and restore.

Reply via email to