diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-10-11 13:52:49 +0200 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@qt.io> | 2018-11-13 11:52:44 +0000 |
commit | c4f82e59d5e9bd3df37c3f08657beb2aeac53161 (patch) | |
tree | 9593d893498444065fd52c0af64553a1a1f303b5 /src/qml/compiler/qv4codegen.cpp | |
parent | c765d5945b75a54d61297b8923497a034020337a (diff) |
Stop codegen after error
We won't use the bytecode anyway, and it prevents consistency checks
that come after the error from failing. Specifically: there might be
jumps that have no label defined.
Fixes: QTBUG-71738
Change-Id: I62a7e943b0156d42caccfa40507853de79e3b1ce
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 295ce08071..54aef16970 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -3083,34 +3083,36 @@ int Codegen::defineFunction(const QString &name, AST::Node *ast, statementList(body); - bytecodeGenerator->setLocation(ast->lastSourceLocation()); - _context->emitBlockFooter(this); - - if (_returnLabel || hasError || !functionEndsWithReturn) { - if (_returnLabel) - _returnLabel->link(); + if (!hasError) { + bytecodeGenerator->setLocation(ast->lastSourceLocation()); + _context->emitBlockFooter(this); + + if (_returnLabel || !functionEndsWithReturn) { + if (_returnLabel) + _returnLabel->link(); + + if (_returnLabel || requiresReturnValue) { + Instruction::LoadReg load; + load.reg = Moth::StackSlot::createRegister(_returnAddress); + bytecodeGenerator->addInstruction(load); + } else { + Reference::fromConst(this, Encode::undefined()).loadInAccumulator(); + } - if (_returnLabel || requiresReturnValue) { - Instruction::LoadReg load; - load.reg = Moth::StackSlot::createRegister(_returnAddress); - bytecodeGenerator->addInstruction(load); - } else { - Reference::fromConst(this, Encode::undefined()).loadInAccumulator(); + bytecodeGenerator->addInstruction(Instruction::Ret()); } - bytecodeGenerator->addInstruction(Instruction::Ret()); - } - - Q_ASSERT(_context == _functionContext); - bytecodeGenerator->finalize(_context); - _context->registerCountInFunction = bytecodeGenerator->registerCount(); - static const bool showCode = qEnvironmentVariableIsSet("QV4_SHOW_BYTECODE"); - if (showCode) { - qDebug() << "=== Bytecode for" << _context->name << "strict mode" << _context->isStrict - << "register count" << _context->registerCountInFunction << "implicit return" << requiresReturnValue; - QV4::Moth::dumpBytecode(_context->code, _context->locals.size(), _context->arguments.size(), - _context->line, _context->lineNumberMapping); - qDebug(); + Q_ASSERT(_context == _functionContext); + bytecodeGenerator->finalize(_context); + _context->registerCountInFunction = bytecodeGenerator->registerCount(); + static const bool showCode = qEnvironmentVariableIsSet("QV4_SHOW_BYTECODE"); + if (showCode) { + qDebug() << "=== Bytecode for" << _context->name << "strict mode" << _context->isStrict + << "register count" << _context->registerCountInFunction << "implicit return" << requiresReturnValue; + QV4::Moth::dumpBytecode(_context->code, _context->locals.size(), _context->arguments.size(), + _context->line, _context->lineNumberMapping); + qDebug(); + } } qSwap(_returnAddress, returnAddress); |