diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-08-04 14:24:32 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-08-18 09:56:55 +0000 |
commit | acce7faa54ae1837527ca574a174b9adba2265ac (patch) | |
tree | af03a2a5c2d612264a18c3f932756c67ca5f5062 /src | |
parent | 4f9875a10ff67aafebe227e9f5ea1b7b97abb52e (diff) |
Stop generating instructions when encountering a throw/return
Any code in a block or a SourceElementList that comes after a throw or
a return is unreachable and doesn't need any code generated. Also do not
generate an extra return for a function that ends with a throw.
Change-Id: I448e8172766ecfe9a2c5b8cff63ebad8b0657701
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index c795841f00..362f85c67e 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -369,6 +369,11 @@ void Codegen::sourceElements(SourceElements *ast) sourceElement(it->element); if (hasError) return; + if (StatementSourceElement *sse = AST::cast<StatementSourceElement *>(it->element)) { + if (AST::cast<ThrowStatement *>(sse->statement) || + AST::cast<ReturnStatement *>(sse->statement)) + return; + } } } @@ -384,6 +389,12 @@ void Codegen::statementList(StatementList *ast) requiresReturnValue = _requiresReturnValue; statement(it->statement); requiresReturnValue = false; + if (it->statement->kind == Statement::Kind_ThrowStatement || + it->statement->kind == Statement::Kind_BreakStatement || + it->statement->kind == Statement::Kind_ContinueStatement || + it->statement->kind == Statement::Kind_ReturnStatement) + // any code after those statements is unreachable + break; } requiresReturnValue = _requiresReturnValue; } @@ -1793,6 +1804,8 @@ static bool endsWithReturn(Node *node) return false; if (AST::cast<ReturnStatement *>(node)) return true; + if (AST::cast<ThrowStatement *>(node)) + return true; if (Program *p = AST::cast<Program *>(node)) return endsWithReturn(p->elements); if (SourceElements *se = AST::cast<SourceElements *>(node)) { |