Merge pull request #5075 from ethereum/fixInliner

[Yul] Fix inliner
This commit is contained in:
chriseth 2018-10-01 13:10:54 +02:00 committed by GitHub
commit a17d480fc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -89,6 +89,9 @@ void InlineModifier::operator()(ForLoop& _loop)
void InlineModifier::operator()(Block& _block)
{
vector<Statement> saved;
saved.swap(m_statementsToPrefix);
// This is only used if needed to minimize the number of move operations.
vector<Statement> modifiedStatements;
for (size_t i = 0; i < _block.statements.size(); ++i)
@ -110,6 +113,8 @@ void InlineModifier::operator()(Block& _block)
}
if (!modifiedStatements.empty())
_block.statements = std::move(modifiedStatements);
saved.swap(m_statementsToPrefix);
}
void InlineModifier::visit(Expression& _expression)

View File

@ -342,5 +342,40 @@ BOOST_AUTO_TEST_CASE(pop_result)
);
}
BOOST_AUTO_TEST_CASE(inside_condition)
{
// This tests that breaking the expression inside the condition works properly.
BOOST_CHECK_EQUAL(
fullInline("{"
"if gt(f(mload(1)), mload(0)) {"
"sstore(0, 2)"
"}"
"function f(a) -> r {"
"a := mload(a)"
"r := add(a, calldatasize())"
"}"
"}", false),
format("{"
"{"
"let _1 := mload(0)"
"let f_a := mload(1)"
"let f_r"
"{"
"f_a := mload(f_a)"
"f_r := add(f_a, calldatasize())"
"}"
"if gt(f_r, _1)"
"{"
"sstore(0, 2)"
"}"
"}"
"function f(a) -> r"
"{"
"a := mload(a)"
"r := add(a, calldatasize())"
"}"
"}", false)
);
}
BOOST_AUTO_TEST_SUITE_END()