Skip to content

Commit

Permalink
Merge pull request #2614 from WalterBright/fix10942
Browse files Browse the repository at this point in the history
fix Issue 10942 - ICE on 1087+ initializers (Internal error: backend\cgc...
  • Loading branch information
andralex committed Oct 9, 2013
2 parents 152c392 + 3f1ae3c commit 81249a3
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 34 deletions.
86 changes: 52 additions & 34 deletions src/tocvdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ unsigned cv4_memfunctypidx(FuncDeclaration *fd)
return cv4_typidx(t);
}

#define CV4_NAMELENMAX 0x3b9f // found by trial and error

unsigned cv4_Denum(EnumDeclaration *e)
{
//dbg_printf("cv4_Denum(%s)\n", e->toChars());
Expand All @@ -159,7 +161,7 @@ unsigned cv4_Denum(EnumDeclaration *e)
{
/* Optlink dies on longer ones, so just truncate
*/
if (fnamelen > 0xB000) // 0xB000 found by trial and error
if (fnamelen > CV4_NAMELENMAX)
{ fnamelen = fnamelen1; // back up
break; // and skip the rest
}
Expand Down Expand Up @@ -474,6 +476,11 @@ void StructDeclaration::toDebug()
{ Dsymbol *s = (*members)[i];
s->apply(&cv_mem_count, &mc);
}
if (config.fulltypes != CV8 && mc.fnamelen > CV4_NAMELENMAX)
{ // Too long, fail gracefully
mc.nfields = 0;
mc.fnamelen = 2;
}
unsigned nfields = mc.nfields;
unsigned fnamelen = mc.fnamelen;

Expand All @@ -486,9 +493,12 @@ void StructDeclaration::toDebug()
// And fill it in
TOWORD(p,config.fulltypes == CV8 ? LF_FIELDLIST_V2 : LF_FIELDLIST);
p += 2;
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
s->apply(&cv_mem_p, &p);
if (nfields)
{
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
s->apply(&cv_mem_p, &p);
}
}

//dbg_printf("fnamelen = %d, p-dt->data = %d\n",fnamelen,p-dt->data);
Expand Down Expand Up @@ -665,6 +675,11 @@ void ClassDeclaration::toDebug()
{ Dsymbol *s = (*members)[i];
s->apply(&cv_mem_count, &mc);
}
if (config.fulltypes != CV8 && mc.fnamelen > CV4_NAMELENMAX)
{ // Too long, fail gracefully
mc.nfields = 0;
mc.fnamelen = 2;
}
unsigned nfields = mc.nfields;
unsigned fnamelen = mc.fnamelen;

Expand All @@ -679,43 +694,46 @@ void ClassDeclaration::toDebug()
TOWORD(p,config.fulltypes == CV8 ? LF_FIELDLIST_V2 : LF_FIELDLIST);
p += 2;

if (addInBaseClasses)
if (nfields) // if we didn't overflow
{
// Add in base classes
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *bc = (*baseclasses)[i];
if (addInBaseClasses)
{
// Add in base classes
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *bc = (*baseclasses)[i];

idx_t typidx = cv4_typidx(bc->base->type->toCtype()->Tnext);
unsigned attribute = PROTtoATTR(bc->protection);
idx_t typidx = cv4_typidx(bc->base->type->toCtype()->Tnext);
unsigned attribute = PROTtoATTR(bc->protection);

unsigned elementlen;
switch (config.fulltypes)
{
case CV8:
TOWORD(p, LF_BCLASS_V2);
TOWORD(p + 2,attribute);
TOLONG(p + 4,typidx);
elementlen = 8;
break;
unsigned elementlen;
switch (config.fulltypes)
{
case CV8:
TOWORD(p, LF_BCLASS_V2);
TOWORD(p + 2,attribute);
TOLONG(p + 4,typidx);
elementlen = 8;
break;

case CV4:
TOWORD(p, LF_BCLASS);
TOWORD(p + 2,typidx);
TOWORD(p + 4,attribute);
elementlen = 6;
break;
}

case CV4:
TOWORD(p, LF_BCLASS);
TOWORD(p + 2,typidx);
TOWORD(p + 4,attribute);
elementlen = 6;
break;
cv4_storenumeric(p + elementlen, bc->offset);
elementlen += cv4_numericbytes(bc->offset);
elementlen = cv_align(p + elementlen, elementlen);
p += elementlen;
}

cv4_storenumeric(p + elementlen, bc->offset);
elementlen += cv4_numericbytes(bc->offset);
elementlen = cv_align(p + elementlen, elementlen);
p += elementlen;
}
}

for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
s->apply(&cv_mem_p, &p);
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
s->apply(&cv_mem_p, &p);
}
}

//dbg_printf("fnamelen = %d, p-dt->data = %d\n",fnamelen,p-dt->data);
Expand Down
26 changes: 26 additions & 0 deletions test/runnable/test10942.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// REQUIRED_ARGS: -g

import std.string;

string getEnum(size_t count)
{
string en;
en ~= "enum KeyCode\n { \n";

foreach (i; 0 .. count)
{
en ~= format(" memb_%s = %s,\n", i+1, i+1);
}

en ~= "} ";
return en;
}

// Linker warning: Warning 161: Unknown CV version, ignored
// mixin(getEnum(1024));

// ICE
mixin(getEnum(1087));

void main() { }

0 comments on commit 81249a3

Please sign in to comment.