Skip to content

Commit

Permalink
fix Issue 12774 - ICE(optimize.c) Newing struct containing union caus…
Browse files Browse the repository at this point in the history
…es segfault
  • Loading branch information
9rnsr committed May 21, 2014
1 parent 3dff770 commit b5c2457
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/interpret.c
Expand Up @@ -3027,7 +3027,8 @@ class Interpreter : public Visitor
for (size_t i = 0; i < exps->dim; i++)
{
Expression *ex = (*e->arguments)[i];
ex = ex->interpret(istate);
if (ex)
ex = ex->interpret(istate);
if (exceptionOrCantInterpret(ex))
{
result = ex;
Expand Down
2 changes: 2 additions & 0 deletions src/optimize.c
Expand Up @@ -469,6 +469,8 @@ Expression *Expression_optimize(Expression *e, int result, bool keepLvalue)
for (size_t i = 0; i < e->arguments->dim; i++)
{
Expression *arg = (*e->arguments)[i];
if (!arg)
continue;
arg = arg->optimize(WANTvalue);
(*e->arguments)[i] = arg;
}
Expand Down
10 changes: 10 additions & 0 deletions test/runnable/structlit.d
Expand Up @@ -853,6 +853,14 @@ void test6937()
/********************************************/
// 12681

struct HasUnion12774
{
union
{
int a, b;
}
}

bool test12681()
{
immutable int x = 42;
Expand Down Expand Up @@ -881,6 +889,8 @@ bool test12681()
assert(s3.p == &x);
assert(s3.foo() == 42);

auto x12774 = new HasUnion12774();

return true;
}
static assert(test12681());
Expand Down

0 comments on commit b5c2457

Please sign in to comment.