Skip to content

Commit

Permalink
fix Issue 14975 - DMD refuses to inline even trivial struct constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Sep 4, 2015
1 parent adc51b1 commit 5455721
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/expression.d
Expand Up @@ -8909,11 +8909,12 @@ public:
return new ErrorExp();
// Bugzilla 14556: Set concrete type to avoid further redundant semantic().
sle.type = e1.type;
/* Copy from the initializer symbol for larger symbols,
* otherwise the literals expressed as code get excessively large.

/* Constructor takes a mutable object, so don't use
* the immutable initializer symbol.
*/
if (sd.size(loc) > Target.ptrsize * 4 && !t1.needsNested())
sle.sinit = toInitializer(sd);
sle.sinit = null;

Expression e = sle;
if (CtorDeclaration cf = sd.ctor.isCtorDeclaration())
{
Expand Down
2 changes: 2 additions & 0 deletions src/func.d
Expand Up @@ -1753,6 +1753,7 @@ public:
Statement s = new ReturnStatement(loc, null);
s = s.semantic(sc2);
fbody = new CompoundStatement(loc, fbody, s);
hasReturnExp |= 1;
}
}
else if (fes)
Expand All @@ -1763,6 +1764,7 @@ public:
Expression e = new IntegerExp(0);
Statement s = new ReturnStatement(Loc(), e);
fbody = new CompoundStatement(Loc(), fbody, s);
hasReturnExp |= 1;
}
assert(!returnLabel);
}
Expand Down
17 changes: 17 additions & 0 deletions test/runnable/inline.d
Expand Up @@ -736,6 +736,22 @@ void test14753(string) { }

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

struct S14975 {
int bar;

pragma(inline, true) this(int bar) {
this.bar = bar;
}
}

void test14975() {
S14975 baz = 1;
if (baz.bar != 1)
assert(0);
}

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

int main()
{
test1();
Expand All @@ -760,6 +776,7 @@ int main()
test14306();
test14754();
test14606();
test14975();

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

0 comments on commit 5455721

Please sign in to comment.