Store all stack errors before they are thrown.

This commit is contained in:
chriseth
2019-02-04 17:32:05 +01:00
parent 77baf6caf7
commit 22c8d74a8a
3 changed files with 37 additions and 5 deletions
+7 -4
View File
@@ -769,21 +769,24 @@ void CodeTransform::generateAssignment(Identifier const& _variableName)
}
}
int CodeTransform::variableHeightDiff(Scope::Variable const& _var, YulString _varName, bool _forSwap) const
int CodeTransform::variableHeightDiff(Scope::Variable const& _var, YulString _varName, bool _forSwap)
{
solAssert(m_context->variableStackHeights.count(&_var), "");
int heightDiff = m_assembly.stackHeight() - m_context->variableStackHeights[&_var];
solAssert(heightDiff > (_forSwap ? 1 : 0), "Negative stack difference for variable.");
int limit = _forSwap ? 17 : 16;
if (heightDiff > limit)
// throw exception with variable name and height diff
BOOST_THROW_EXCEPTION(StackTooDeepError(_varName, heightDiff - limit) << errinfo_comment(
{
m_stackErrors.emplace_back(_varName, heightDiff - limit);
m_stackErrors.back() << errinfo_comment(
"Variable " +
_varName.str() +
" is " +
to_string(heightDiff - limit) +
" slot(s) too deep inside the stack."
));
);
BOOST_THROW_EXCEPTION(m_stackErrors.back());
}
return heightDiff;
}
+1 -1
View File
@@ -189,7 +189,7 @@ private:
/// Determines the stack height difference to the given variables. Throws
/// if it is not yet in scope or the height difference is too large. Returns
/// the (positive) stack height difference otherwise.
int variableHeightDiff(Scope::Variable const& _var, YulString _name, bool _forSwap) const;
int variableHeightDiff(Scope::Variable const& _var, YulString _name, bool _forSwap);
void expectDeposit(int _deposit, int _oldHeight) const;