From fb2b3bb2b9949f343025b48d611cde7ceef40930 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 22 May 2019 16:08:49 +0200 Subject: [PATCH] Reduce misleading stack height error message. --- libyul/AsmAnalysis.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index 12f440d1d..ef6c8706c 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -399,9 +399,11 @@ bool AsmAnalyzer::operator()(If const& _if) { bool success = true; + int const initialHeight = m_stackHeight; if (!expectExpression(*_if.condition)) success = false; - m_stackHeight--; + + m_stackHeight = initialHeight; if (!(*this)(_if.body)) success = false; @@ -417,6 +419,7 @@ bool AsmAnalyzer::operator()(Switch const& _switch) bool success = true; + int const initialHeight = m_stackHeight; if (!expectExpression(*_switch.expression)) success = false; @@ -476,7 +479,7 @@ bool AsmAnalyzer::operator()(Switch const& _switch) success = false; } - m_stackHeight--; + m_stackHeight = initialHeight; m_info.stackHeightInfo[&_switch] = m_stackHeight; return success; @@ -488,6 +491,8 @@ bool AsmAnalyzer::operator()(ForLoop const& _for) Scope* outerScope = m_currentScope; + int const initialHeight = m_stackHeight; + bool success = true; if (!(*this)(_for.pre)) success = false; @@ -498,6 +503,7 @@ bool AsmAnalyzer::operator()(ForLoop const& _for) if (!expectExpression(*_for.condition)) success = false; + m_stackHeight--; // backup outer for-loop & create new state @@ -510,7 +516,7 @@ bool AsmAnalyzer::operator()(ForLoop const& _for) if (!(*this)(_for.post)) success = false; - m_stackHeight -= scope(&_for.pre).numberOfVariables(); + m_stackHeight = initialHeight; m_info.stackHeightInfo[&_for] = m_stackHeight; m_currentScope = outerScope; m_currentForLoop = outerForLoop;