Skip to content

Commit

Permalink
Merge pull request #3723 from 9rnsr/fix13021
Browse files Browse the repository at this point in the history
Issue 13021 - Constructing union with floating type and then accessing its field in one expression causes ICE
  • Loading branch information
WalterBright authored and 9rnsr committed Jul 7, 2014
1 parent 4f61bde commit f9a254c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/optimize.c
Expand Up @@ -437,8 +437,10 @@ Expression *Expression_optimize(Expression *e, int result, bool keepLvalue)
{
StructLiteralExp *sle = (StructLiteralExp *)ex;
VarDeclaration *vf = e->var->isVarDeclaration();
if (vf)
if (vf && !vf->overlapped)
{
/* Bugzilla 13021: Prevent optimization if vf has overlapped fields.
*/
ex = sle->getField(e->type, vf->offset);
if (ex && ex != EXP_CANT_INTERPRET)
{
Expand Down
39 changes: 39 additions & 0 deletions test/runnable/structlit.d
Expand Up @@ -1344,6 +1344,44 @@ void test12011()
static assert(S12011b.e == 1);
}

/********************************************/
// 13021

void test13021()
{
static union U1
{
float a;
int b;
}

static union U2
{
double a;
long b;
}

static union U3
{
real a;
struct B { long b1, b2; } // ICE happens only if B.sizeof == real.sizeof
B b;
}

static union U4
{
real a;
long[2] b; // ditto
}

auto f = U1(1.0); auto ok = f.b;

auto fail1 = U1(1.0).b; // OK <- Internal error: e2ir.c 1162
auto fail2 = U2(1.0).b; // OK <- Internal error: e2ir.c 1162
auto fail3 = U3(1.0).b; // OK <- Internal error: e2ir.c 1162
auto fail4 = U4(1.0).b; // OK <- Internal error: backend/el.c 2904
}

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

int main()
Expand Down Expand Up @@ -1388,6 +1426,7 @@ int main()
test11105();
test11147();
test11256();
test13021();

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

0 comments on commit f9a254c

Please sign in to comment.