Skip to content

Commit

Permalink
Merge pull request #3675 from 9rnsr/fix12937
Browse files Browse the repository at this point in the history
Issue 12937 - ICE with void static array initializing
  • Loading branch information
WalterBright committed Jun 18, 2014
2 parents 539db52 + 4fc3f3a commit 76199e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/optimize.c
Expand Up @@ -528,9 +528,13 @@ Expression *Expression_optimize(Expression *e, int result, bool keepLvalue)

if ((e->e1->op == TOKstring || e->e1->op == TOKarrayliteral) &&
(e->type->ty == Tpointer || e->type->ty == Tarray) &&
e->e1->type->toBasetype()->nextOf()->size() == e->type->nextOf()->size()
)
e->e1->type->toBasetype()->nextOf()->size() == e->type->nextOf()->size())
{
// Bugzilla 12937: If target type is void array, trying to paint
// e->e1 with that type will cause infinite recursive optimization.
if (e->type->nextOf()->ty == Tvoid)
return;

ret = e->e1->castTo(NULL, e->type);
//printf(" returning1 %s\n", ret->toChars());
return;
Expand Down
10 changes: 10 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -6914,6 +6914,15 @@ void test12498()
string x = t;
}

/***************************************************/
// 12937

void test12937()
{
void[1] sa2 = cast(void[])[cast(ubyte)1]; // ICE!
assert((cast(ubyte[])sa2[])[0] == 1);
}

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

int main()
Expand Down Expand Up @@ -7200,6 +7209,7 @@ int main()
test11181();
test11317();
test12153();
test12937();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 76199e5

Please sign in to comment.