Browse Source

- corrected delete in case we have more than one locals

- added a test
cl-refactor
liana 10 years ago
parent
commit
7651909bdf
  1. 4
      libsolidity/ExpressionCompiler.cpp
  2. 8
      test/SolidityEndToEndTest.cpp

4
libsolidity/ExpressionCompiler.cpp

@ -810,9 +810,9 @@ void ExpressionCompiler::LValue::setToZero(Expression const& _expression) const
if (stackDiff > 16) if (stackDiff > 16)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_expression.getLocation()) BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_expression.getLocation())
<< errinfo_comment("Stack too deep.")); << errinfo_comment("Stack too deep."));
solAssert(stackDiff <= m_size, ""); solAssert(stackDiff >= m_size - 1, "");
for (unsigned i = 0; i < m_size; ++i) for (unsigned i = 0; i < m_size; ++i)
*m_context << u256(0) << eth::swapInstruction(stackDiff + (m_size - i) ) *m_context << u256(0) << eth::swapInstruction(stackDiff + 1 - i)
<< eth::Instruction::POP; << eth::Instruction::POP;
break; break;
} }

8
test/SolidityEndToEndTest.cpp

@ -847,15 +847,17 @@ BOOST_AUTO_TEST_CASE(deleteLocals)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(
contract test { contract test {
function delLocal() returns (uint res){ function delLocal() returns (uint res1, uint res2){
uint v = 5; uint v = 5;
uint w = 6; uint w = 6;
uint x = 7;
delete v; delete v;
res = w; res1 = w;
res2 = x;
} }
})"; })";
compileAndRun(sourceCode); compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("delLocal()") == encodeArgs(6)); BOOST_CHECK(callContractFunction("delLocal()") == encodeArgs(6, 7));
} }
BOOST_AUTO_TEST_CASE(constructor) BOOST_AUTO_TEST_CASE(constructor)

Loading…
Cancel
Save