Skip to content

Spec: class ABI is wrong about order of interfaces vptr and class fields #22782

@dkorpel

Description

@dkorpel

https://dlang.org/spec/abi.html#classes

It says interfaces come right after __monitor before any inherited class fields, but everything from the base class always comes before everything from the derived class. The table rows should be swapped.

Demonstration program:

interface H { void h(); }
interface I { void f(); }
interface J { void g(); }

class C : H
{
	ulong[2] x = 0x11111111;

	override void h() {}
}

class D : C, I, J
{
	ulong[2] y = 0x22222222;

    override void f() {}
    override void g() {}
}

import std;

void main()
{
    D c = new D();

	foreach (i; 0 .. 9)
	{
		writeln(i, " ", *cast(void**) ((cast(void*) c) + i*8));
	}
}
0 55C933DD85B0 // vptr
1 null         // Object.__monitor
2 55C933DD83E8 // C's interface H.vptr
3 11111111     // C fields
4 11111111           
5 55C933DD8578 // D's interface I.vptr
6 55C933DD8588 // D's interface J.vptr
7 22222222     // D fields
8 22222222

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions