Skip to content

Commit

Permalink
Merge pull request #4683 from 9rnsr/fix14606
Browse files Browse the repository at this point in the history
 [REG2.067.0] Issue 14606 - Bad code with -inline and structs
  • Loading branch information
WalterBright committed May 31, 2015
2 parents 7dd1d17 + 10fc5c4 commit 58047b0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/e2ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -2658,7 +2658,7 @@ elem *toElem(Expression *e, IRState *irs)
es = el_una(OPaddr, TYnptr, es);
es->Ety = TYnptr;
e = el_bin(OPeq, TYnptr, es, e);
// BUG: type is struct, and e2 is TOKint64
assert(!(t1b->ty == Tstruct && ae->e2->op == TOKint64));

el_setLoc(e, ae->loc);
result = e;
Expand Down Expand Up @@ -2716,6 +2716,8 @@ elem *toElem(Expression *e, IRState *irs)
{
if (ae->e2->op == TOKint64)
{
assert(ae->op == TOKblit);

/* Implement:
* (struct = 0)
* with:
Expand Down
15 changes: 9 additions & 6 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -11299,13 +11299,16 @@ Expression *AssignExp::semantic(Scope *sc)
* initializer
*/
AssignExp *ae = this;
if (sd->zeroInit == 1)
ae->e2 = new IntegerExp(loc, 0, Type::tint32);
else if (sd->isNested())
ae->e2 = t1->defaultInitLiteral(loc);
if (sd->zeroInit == 1 && !sd->isNested())
{
// Bugzilla 14606: Always use BlitExp for the special expression: (struct = 0)
ae = new BlitExp(ae->loc, ae->e1, new IntegerExp(loc, 0, Type::tint32));
}
else
ae->e2 = t1->defaultInit(loc);
// Keep ae->op == TOKconstruct
{
// Keep ae->op == TOKconstruct
ae->e2 = sd->isNested() ? t1->defaultInitLiteral(loc) : t1->defaultInit(loc);
}
ae->type = e1x->type;

/* Replace __ctmp being constructed with e1.
Expand Down
36 changes: 36 additions & 0 deletions test/runnable/inline.d
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,41 @@ void test14306() {
fun(t);
}

/**********************************/
// 14606

struct S14606
{
this(long stdTime)
{
_stdTime = stdTime;
}

long _stdTime;
}

S14606 getS14606()
{
S14606 sysTime = S14606(0);
return sysTime;
}

struct T14606
{
this(string)
{
uint[3] arr;
s = getS14606();
}

S14606 s;
}

void test14606()
{
auto t = T14606(null);
}

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

int main()
Expand All @@ -646,6 +681,7 @@ int main()
test11394();
test13503();
test14306();
test14606();

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

0 comments on commit 58047b0

Please sign in to comment.