[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
Mon Apr 3 19:16:13 UTC 2023


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

--- Comment #5 from naydef <naydef at abv.bg> ---
I've made the following example (without the patch the generated executable
crashes):

app.d
--------------------------------------
extern(C++) interface BaseInterface1
{
public:
    int func1();
    int func2();
}

extern(C++) abstract class BaseInterface2
{
public:
    int func3() {return 3;}
    int func4() {return 4;}
}

extern(C++) class MainClass : BaseInterface2, BaseInterface1
{
    override int func1() {return 1;}
    override int func2() {return 2;}
}

extern(C++) void cppFunc1(BaseInterface1 obj);


void main()
{
    BaseInterface1 cls = new MainClass();
    cppFunc1(cls);
}
--------------------------------------

app2.cpp
--------------------------------------
class BaseInterface1
{
public:
    virtual int func1();
    virtual int func2();
};

class BaseInterface2
{
public:
    virtual int func3();
    virtual int func4();
};

class MainClass : BaseInterface2, BaseInterface1
{
    virtual int func1();
    virtual int func2();
};

void cppFunc1(BaseInterface1* obj)
{
    int a = obj->func1();
    int b = obj->func2();
}
--------------------------------------

The executable is generated with the following command:
gcc -m32 -O -c app2.cpp -o app2.o;dmd app.d app2.o -m32

Feel free to comment on the code.

--


More information about the Digitalmars-d-bugs mailing list