- fixed: Tacking on a return statement should only be done if the function has branches that actually reach the end. Otherwise it may interfere with return type deduction.

- used the return check to optimize out unneeded jumps at the end of an if statement's first block.
This commit is contained in:
Christoph Oelckers 2016-11-05 18:05:57 +01:00
commit 1b77a8f491
4 changed files with 65 additions and 5 deletions

View file

@ -2464,15 +2464,15 @@ FxExpression *ZCCCompiler::ConvertAST(PClass *cls, ZCC_TreeNode *ast)
// This must be done here so that we can check for a trailing return statement.
auto x = new FxCompoundStatement(*ast);
auto compound = static_cast<ZCC_CompoundStmt *>(ast);
bool isreturn = false;
//bool isreturn = false;
auto node = compound->Content;
if (node != nullptr) do
{
x->Add(ConvertNode(node));
isreturn = node->NodeType == AST_ReturnStmt;
//isreturn = node->NodeType == AST_ReturnStmt;
node = static_cast<decltype(node)>(node->SiblingNext);
} while (node != compound->Content);
if (!isreturn) x->Add(new FxReturnStatement(nullptr, *ast));
//if (!isreturn) x->Add(new FxReturnStatement(nullptr, *ast));
return x;
}
}