mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Issue warnings if stack is not balanced after inline assembly block
This commit is contained in:
parent
e1ff8bebe1
commit
c3330faf21
@ -23,6 +23,7 @@
|
|||||||
#include <libsolidity/inlineasm/AsmCodeGen.h>
|
#include <libsolidity/inlineasm/AsmCodeGen.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <libdevcore/CommonIO.h>
|
||||||
#include <libevmasm/Assembly.h>
|
#include <libevmasm/Assembly.h>
|
||||||
#include <libevmasm/SourceLocation.h>
|
#include <libevmasm/SourceLocation.h>
|
||||||
#include <libevmasm/Instruction.h>
|
#include <libevmasm/Instruction.h>
|
||||||
@ -213,10 +214,31 @@ public:
|
|||||||
void operator()(assembly::Block const& _block)
|
void operator()(assembly::Block const& _block)
|
||||||
{
|
{
|
||||||
size_t numVariables = m_state.variables.size();
|
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));
|
std::for_each(_block.statements.begin(), _block.statements.end(), boost::apply_visitor(*this));
|
||||||
// pop variables
|
deposit = m_state.assembly.deposit() - deposit;
|
||||||
// we deliberately do not check stack height
|
|
||||||
m_state.assembly.setSourceLocation(_block.location);
|
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)
|
while (m_state.variables.size() > numVariables)
|
||||||
{
|
{
|
||||||
m_state.assembly.append(solidity::Instruction::POP);
|
m_state.assembly.append(solidity::Instruction::POP);
|
||||||
|
Loading…
Reference in New Issue
Block a user