Skip to content

Commit

Permalink
fix Issue 14560 - Strange -inline behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jun 13, 2015
1 parent fbb6e2a commit 9f88697
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ Statement *inlineAsStatement(Statement *s, InlineDoState *ids)
{
//printf("ReturnStatement::inlineAsStatement() '%s'\n", s->exp ? s->exp->toChars() : "");
ids->foundReturn = true;
result = new ReturnStatement(s->loc, s->exp ? doInline(s->exp, ids) : NULL);
if (s->exp) // Bugzilla 14560: 'return' must not leave in the expand result
result = new ReturnStatement(s->loc, doInline(s->exp, ids));
}

void visit(ImportStatement *s)
Expand Down Expand Up @@ -1718,6 +1719,11 @@ bool canInline(FuncDeclaration *fd, int hasthis, int hdrscan, int statementsToo)
(!(fd->hasReturnExp & 1) || statementsToo) &&
!hdrscan)
goto Lno;

/* Bugzilla 14560: If fd returns void, all explicit `return;`s
* must not appear in the expanded result.
* See also ReturnStatement::inlineAsStatement().
*/
}

// cannot inline constructor calls because we need to convert:
Expand Down
17 changes: 17 additions & 0 deletions test/runnable/inline14560.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// PERMUTE_ARGS: -inline -release -g -O

auto serialize(T)(T value)
{
foreach (i; value) { }

return; // important
// By this ReturnStatement with NULL exp wrongly appears in the
// expanded result of serialize(["test"]) call in main(), it will
// return from main() without setting exit code.
}

int main()
{
serialize(["test"]);
return 0;
}

0 comments on commit 9f88697

Please sign in to comment.