Skip to content

Commit

Permalink
Merge pull request #5397 from WalterBright/changeToMiLayout
Browse files Browse the repository at this point in the history
fix Issue 15644 - Switch object layout ABI to MI style
  • Loading branch information
andralex committed Feb 4, 2016
2 parents 942bb43 + a54e89d commit 708f174
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 50 deletions.
7 changes: 1 addition & 6 deletions src/dclass.d
Expand Up @@ -1162,8 +1162,7 @@ public:
}

// Add vptr's for any interfaces implemented by this class
if (cpp)
structsize += setBaseInterfaceOffsets(structsize);
structsize += setBaseInterfaceOffsets(structsize);

uint offset = structsize;
for (size_t i = 0; i < members.dim; i++)
Expand All @@ -1174,10 +1173,6 @@ public:
if (sizeok == SIZEOKfwd)
return;

// Add vptr's for any interfaces implemented by this class
if (!cpp)
structsize += setBaseInterfaceOffsets(structsize);

sizeok = SIZEOKdone;

// Calculate fields[i].overlapped
Expand Down
60 changes: 17 additions & 43 deletions src/todt.c
Expand Up @@ -688,7 +688,7 @@ static dt_t **membersToDt(AggregateDeclaration *ad, dt_t **pdt,
{
assert(cd2);
unsigned csymoffset = baseVtblOffset(cd2, b);
//printf(" cd2 %s csymoffset = %d\n", cd2 ? cd2->toChars() : "null", csymoffset);
//printf(" cd2 %s csymoffset = x%x\n", cd2 ? cd2->toChars() : "null", csymoffset);
if (csymoffset != ~0)
{
pdt = dtxoff(pdt, toSymbol(cd2), csymoffset);
Expand All @@ -709,26 +709,24 @@ static dt_t **membersToDt(AggregateDeclaration *ad, dt_t **pdt,
}
}

if (cd->cpp)
{
// Interface vptr initializations
toSymbol(cd); // define csym
// Interface vptr initializations
toSymbol(cd); // define csym

BaseClass **pb;
if (!ppb)
pb = cd->vtblInterfaces->data;
else
pb = *ppb;
BaseClass **pb;
if (!ppb)
{
pb = cd->vtblInterfaces->data;
ppb = &pb;
}

for (size_t i = 0; i < cd->interfaces.length; ++i)
{
BaseClass *b = *pb;
if (offset < b->offset)
pdt = dtnzeros(pdt, b->offset - offset);
pdt = membersToDt(cd->interfaces.ptr[i]->sym, pdt, elements, firstFieldIndex, concreteType, &pb);
//printf("b->offset = %d, b->sym->structsize = %d\n", (int)b->offset, (int)b->sym->structsize);
offset = b->offset + b->sym->structsize;
}
for (size_t i = 0; i < cd->interfaces.length; ++i)
{
BaseClass *b = **ppb;
if (offset < b->offset)
pdt = dtnzeros(pdt, b->offset - offset);
pdt = membersToDt(cd->interfaces.ptr[i]->sym, pdt, elements, firstFieldIndex, concreteType, ppb);
//printf("b->offset = %d, b->sym->structsize = %d\n", (int)b->offset, (int)b->sym->structsize);
offset = b->offset + b->sym->structsize;
}
}
else
Expand Down Expand Up @@ -820,30 +818,6 @@ static dt_t **membersToDt(AggregateDeclaration *ad, dt_t **pdt,
offset = vd->offset + vd->type->size();
}

if (cd && !cd->cpp)
{
// Interface vptr initializations
toSymbol(cd); // define csym

for (size_t i = 0; i < cd->vtblInterfaces->dim; i++)
{
BaseClass *b = (*cd->vtblInterfaces)[i];
for (ClassDeclaration *cd2 = concreteType; 1; cd2 = cd2->baseClass)
{
assert(cd2);
unsigned csymoffset = baseVtblOffset(cd2, b);
if (csymoffset != ~0)
{
if (offset < b->offset)
pdt = dtnzeros(pdt, b->offset - offset);
pdt = dtxoff(pdt, toSymbol(cd2), csymoffset);
break;
}
}
offset = b->offset + Target::ptrsize;
}
}

if (offset < ad->structsize)
pdt = dtnzeros(pdt, ad->structsize - offset);

Expand Down
2 changes: 1 addition & 1 deletion test/compilable/test15618.d
Expand Up @@ -16,4 +16,4 @@ class Derived : Base, Interface
}

static assert(Derived.x.offsetof == (void*).sizeof * 2);
static assert(Derived.y.offsetof == (void*).sizeof * 3);
static assert(Derived.y.offsetof == (void*).sizeof * 4);

0 comments on commit 708f174

Please sign in to comment.