Report all stack errors in the EVM code transform.

This commit is contained in:
Daniel Kirchner
2020-07-16 17:38:04 +02:00
committed by chriseth
parent f9753a5101
commit 579e4b5a69
5 changed files with 27 additions and 48 deletions
+19 -28
View File
@@ -435,31 +435,24 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
m_context->functionExitPoints.push(
CodeTransformContext::JumpInfo{m_assembly.newLabelId(), m_assembly.stackHeight()}
);
try
CodeTransform subTransform(
m_assembly,
m_info,
_function.body,
m_allowStackOpt,
m_dialect,
m_builtinContext,
m_evm15,
m_identifierAccess,
m_useNamedLabelsForFunctions,
m_context
);
subTransform(_function.body);
for (auto& stackError: subTransform.m_stackErrors)
{
CodeTransform(
m_assembly,
m_info,
_function.body,
m_allowStackOpt,
m_dialect,
m_builtinContext,
m_evm15,
m_identifierAccess,
m_useNamedLabelsForFunctions,
m_context
)(_function.body);
}
catch (StackTooDeepError const& _error)
{
// This exception will be re-thrown after the end of the surrounding block.
// It enables us to see which functions compiled successfully and which did not.
// Even if we emit actual code, add an illegal instruction to make sure that tests
// will catch it.
StackTooDeepError error(_error);
if (error.functionName.empty())
error.functionName = _function.name;
stackError(std::move(error), static_cast<int>(height));
if (stackError.functionName.empty())
stackError.functionName = _function.name;
m_stackErrors.emplace_back(std::move(stackError));
}
m_assembly.appendLabel(m_context->functionExitPoints.top().label);
@@ -605,9 +598,6 @@ void CodeTransform::operator()(Block const& _block)
finalizeBlock(_block, blockStartStackHeight);
m_scope = originalScope;
if (!m_stackErrors.empty())
BOOST_THROW_EXCEPTION(m_stackErrors.front());
}
AbstractAssembly::LabelID CodeTransform::functionEntryID(YulString _name, Scope::Function const& _function)
@@ -728,7 +718,8 @@ size_t CodeTransform::variableHeightDiff(Scope::Variable const& _var, YulString
to_string(heightDiff - limit) +
" slot(s) too deep inside the stack."
);
BOOST_THROW_EXCEPTION(m_stackErrors.back());
// TODO: maybe make this return something special that results in producing INVALID instead.
return _forSwap ? 2 : 1;
}
return heightDiff;
}