[Issue 23814] [Codegen] Calling member function of extern(C++) class with multiple inheritance doesn't preserve the EBX register in some cases

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 29 17:14:52 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23814

--- Comment #1 from naydef <naydef at abv.bg> ---
Corrected the code (previous one will not generate the bad code for the call):

extern(C++) interface BaseInterface1
{
public:
    const(char)* func1();
    const(char)* func2();
}

extern(C++) abstract class BaseInterface2
{
public:
    const(char)* func3() {return "func3";}
    const(char)* func4() {return "func4";}
}

extern(C++) class MainClass : BaseInterface2, BaseInterface1
{
    override const(char)* func1() {return "func1_overriden";}
    override const(char)* func2() {return "func2_overriden";}
    override const(char)* func3() {return "func3_overriden";}
    override const(char)* func4() {return "func4_overriden";}
}


void main()
{
    BaseInterface1 cls = new MainClass();

    import core.stdc.stdio;
    printf("We'll now call func4");

    cls.func1();
}


Assembly code

The assembly of the callee (IDA):
-----------------------------------------------------------
.text:00034790 _THUNK0         proc near               ; DATA XREF:
.data:off_87304↓o
.text:00034790
.text:00034790 arg_0           = dword ptr  4
.text:00034790
.text:00034790                 sub     [esp+arg_0], 4
.text:00034795                 call    $+5
.text:0003479A
.text:0003479A loc_3479A:                              ; DATA XREF: _THUNK0+B↓o
.text:0003479A                 pop     ebx
.text:0003479B                 add     ebx, (offset _GLOBAL_OFFSET_TABLE_ -
offset loc_3479A)
.text:000347A1                 jmp     _ZN9MainClass5func1Ev ;
MainClass::func1(void)
.text:000347A1 _THUNK0         endp

-----------------------------------------------------------

Code of the caller:

-----------------------------------------------------------
.text:000348C5                 lea     ecx, (aWeLlNowCallFun - 86FF4h)[eax] ;
"We'll now call func4"
.text:000348CB                 push    ecx
.text:000348CC                 mov     ebx, [ebp+_LOCALGOT6]
.text:000348CF                 call    _printf
.text:000348D4                 add     esp, 10h
.text:000348D7                 sub     esp, 0Ch
.text:000348DA                 push    [ebp+cls]
.text:000348DD                 mov     ebx, [ebp+_LOCALGOT6]
.text:000348E0                 mov     edx, [ebp+cls]
.text:000348E3                 mov     eax, [edx]
.text:000348E5                 call    ds:(_GLOBAL_OFFSET_TABLE_ - 86FF4h)[eax]
;  Call to cls.func1
.text:000348E7                 add     esp, 10h

-----------------------------------------------------------


Issue appears with DMD 2.102.2 compiling on Linux with dub parameter --arch=x86

--


More information about the Digitalmars-d-bugs mailing list