bebbo / gcc

Bebbo's gcc-6-branch for m68k-amigaos
GNU General Public License v2.0
33 stars 11 forks source link

C++ with vtable and regparm=N seems to cause mismatch between callsite and subroutine #210

Closed erique closed 9 months ago

erique commented 9 months ago

When a class method is called via vtable, and -mregparm is used, the callsite passes this in a0, while the subroutine assumes this being passed on the stack.

CEX: http://franke.ms/cex/z/xTj5Yr

Subroutine TheClass::Reset() is called like

void* r = static_cast<TheClass*>(c)->Reset(); // 'this' passed via a0

which translates to

        move.l (a2),a0
        move.l (a0),a1
        move.l d0,a0
        jsr (a1)

While TheClass::Reset() itself will try to use this from the stack:

__ZN8TheClass5ResetEv:
        move.l (4,sp),d0
        move.l d0,a0
        clr.b (4,a0)
        rts

( This example works fine in x86 GCC : https://godbolt.org/z/Exncnjqh4 )

bebbo commented 9 months ago

confirmed: http://franke.ms/cex/z/5v88oo

erique commented 9 months ago

confirmed working - thanks!