Skip to content

Commit

Permalink
Merge pull request #4744 from 9rnsr/fix14699
Browse files Browse the repository at this point in the history
Issue 14699 - ICE: segfaults on array with zero size
  • Loading branch information
WalterBright committed Jun 17, 2015
2 parents 67b8271 + ae2cd8c commit 94a6afd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -7870,7 +7870,7 @@ Expression *TypeStruct::defaultInitLiteral(Loc loc)
error(loc, "circular reference to '%s'", vd->toPrettyChars());
return new ErrorExp();
}
if (vd->offset < offset)
if (vd->offset < offset || vd->type->size() == 0)
e = NULL;
else if (vd->init)
{
Expand Down
6 changes: 5 additions & 1 deletion src/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,11 @@ bool StructDeclaration::fill(Loc loc, Expressions *elements, bool ctorinit)
if (elements && vx)
{
Expression *e;
if (vx->init)
if (vx->type->size() == 0)
{
e = NULL;
}
else if (vx->init)
{
assert(!vx->init->isVoidInitializer());
e = vx->getConstInitializer(false);
Expand Down
11 changes: 8 additions & 3 deletions src/todt.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,15 @@ dt_t **Type_toDt(Type *t, dt_t **pdt)

dt_t **toDtElem(TypeSArray *tsa, dt_t **pdt, Expression *e)
{
//printf("TypeSArray::toDtElem()\n");
size_t len = tsa->dim->toInteger();
if (len)
//printf("TypeSArray::toDtElem() tsa = %s\n", tsa->toChars());
if (tsa->size(Loc()) == 0)
{
pdt = dtnzeros(pdt, 0);
}
else
{
size_t len = tsa->dim->toInteger();
assert(len);
pdt = dtend(pdt);
Type *tnext = tsa->next;
Type *tbn = tnext->toBasetype();
Expand Down
14 changes: 14 additions & 0 deletions test/runnable/testdt.d
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ void test13505()
auto s = S13505();
}

/******************************************/
// 14699

struct S14699a { ubyte[0][10] values; }
struct S14699b { S14699a tbl; }
// +/

ubyte[0][1] sa14699;

void test14699()
{
//auto p = &sa14699; // Cannot work in Win32 (OMF)
}

/******************************************/

int main()
Expand Down

0 comments on commit 94a6afd

Please sign in to comment.