Skip to content

Commit

Permalink
Merge pull request #4205 from 9rnsr/fix13831
Browse files Browse the repository at this point in the history
Issue 13831 - DMD crash on newing struct with overlapped fields in CTFE
  • Loading branch information
WalterBright committed Dec 11, 2014
2 parents 95e4aa8 + 5266a05 commit 048a508
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/ctfeexpr.c
Expand Up @@ -1848,7 +1848,8 @@ void assignInPlace(Expression *dest, Expression *src)
assert(o->op == e->op);
assignInPlace(o, e);
}
else if (e->type->ty == Tsarray && o->type->ty == Tsarray && e->op != TOKvoid)
else if (e->type->ty == Tsarray && e->op != TOKvoid &&
o->type->ty == Tsarray)
{
assignInPlace(o, e);
}
Expand Down
5 changes: 4 additions & 1 deletion src/interpret.c
Expand Up @@ -2796,7 +2796,7 @@ class Interpreter : public Visitor
void visit(StructLiteralExp *e)
{
#if LOG
printf("%s StructLiteralExp::interpret() %s\n", e->loc.toChars(), e->toChars());
printf("%s StructLiteralExp::interpret() %s ownedByCtfe = %d\n", e->loc.toChars(), e->toChars(), e->ownedByCtfe);
#endif
if (e->ownedByCtfe)
{
Expand Down Expand Up @@ -2944,6 +2944,9 @@ class Interpreter : public Visitor
if (e->member)
{
Expression *se = e->newtype->defaultInitLiteral(e->loc);
se = interpret(se, istate);
if (exceptionOrCant(se))
return;
result = interpret(e->member, istate, e->arguments, se);
}
else
Expand Down
29 changes: 29 additions & 0 deletions test/compilable/interpret3.d
Expand Up @@ -5982,6 +5982,35 @@ struct S10937
enum test10937 = S10937(7);
enum west10937 = S10937(2);

/**************************************************
13831
**************************************************/

struct Vector13831()
{
}

struct Coord13831
{
union
{
struct { short x; }
Vector13831!() vector;
}
}

struct Chunk13831
{
this(Coord13831)
{
coord = coord;
}

Coord13831 coord;

static const Chunk13831* unknownChunk = new Chunk13831(Coord13831());
}

/**************************************************
7732
**************************************************/
Expand Down

0 comments on commit 048a508

Please sign in to comment.