diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2016-10-20 08:09:28 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2016-10-20 20:25:28 +0800 |
commit | c3330faf210ee06464dbc71a7946e069033299ac (patch) | |
tree | b7950c3403a3c4af1b9e070b220ee2487c43e069 /libsolidity | |
parent | e1ff8bebe1e9468ac7ea2d1d221a22381052c653 (diff) | |
download | dexon-solidity-c3330faf210ee06464dbc71a7946e069033299ac.tar dexon-solidity-c3330faf210ee06464dbc71a7946e069033299ac.tar.gz dexon-solidity-c3330faf210ee06464dbc71a7946e069033299ac.tar.bz2 dexon-solidity-c3330faf210ee06464dbc71a7946e069033299ac.tar.lz dexon-solidity-c3330faf210ee06464dbc71a7946e069033299ac.tar.xz dexon-solidity-c3330faf210ee06464dbc71a7946e069033299ac.tar.zst dexon-solidity-c3330faf210ee06464dbc71a7946e069033299ac.zip |
Issue warnings if stack is not balanced after inline assembly block
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/inlineasm/AsmCodeGen.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp index 53d19b0a..5d920cb7 100644 --- a/libsolidity/inlineasm/AsmCodeGen.cpp +++ b/libsolidity/inlineasm/AsmCodeGen.cpp @@ -23,6 +23,7 @@ #include <libsolidity/inlineasm/AsmCodeGen.h> #include <memory> #include <functional> +#include <libdevcore/CommonIO.h> #include <libevmasm/Assembly.h> #include <libevmasm/SourceLocation.h> #include <libevmasm/Instruction.h> @@ -213,10 +214,31 @@ public: void operator()(assembly::Block const& _block) { size_t numVariables = m_state.variables.size(); + int deposit = m_state.assembly.deposit(); std::for_each(_block.statements.begin(), _block.statements.end(), boost::apply_visitor(*this)); - // pop variables - // we deliberately do not check stack height + deposit = m_state.assembly.deposit() - deposit; + m_state.assembly.setSourceLocation(_block.location); + + // issue warnings for stack height discrepancies + if (deposit < 0) + { + m_state.addError( + Error::Type::Warning, + "Inline assembly block is not balanced. It takes " + toString(-deposit) + " item(s) from the stack.", + _block.location + ); + } + else if (deposit > 0) + { + m_state.addError( + Error::Type::Warning, + "Inline assembly block is not balanced. It leaves " + toString(deposit) + " item(s) on the stack.", + _block.location + ); + } + + // pop variables while (m_state.variables.size() > numVariables) { m_state.assembly.append(solidity::Instruction::POP); |