mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix for inlining inside conditions.
This commit is contained in:
parent
ba62831143
commit
d5cd02b8ed
@ -89,6 +89,9 @@ void InlineModifier::operator()(ForLoop& _loop)
|
|||||||
|
|
||||||
void InlineModifier::operator()(Block& _block)
|
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.
|
// This is only used if needed to minimize the number of move operations.
|
||||||
vector<Statement> modifiedStatements;
|
vector<Statement> modifiedStatements;
|
||||||
for (size_t i = 0; i < _block.statements.size(); ++i)
|
for (size_t i = 0; i < _block.statements.size(); ++i)
|
||||||
@ -110,6 +113,8 @@ void InlineModifier::operator()(Block& _block)
|
|||||||
}
|
}
|
||||||
if (!modifiedStatements.empty())
|
if (!modifiedStatements.empty())
|
||||||
_block.statements = std::move(modifiedStatements);
|
_block.statements = std::move(modifiedStatements);
|
||||||
|
|
||||||
|
saved.swap(m_statementsToPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InlineModifier::visit(Expression& _expression)
|
void InlineModifier::visit(Expression& _expression)
|
||||||
|
@ -344,37 +344,37 @@ BOOST_AUTO_TEST_CASE(pop_result)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(inside_condition)
|
BOOST_AUTO_TEST_CASE(inside_condition)
|
||||||
{
|
{
|
||||||
// This tests that breaking the expresison inside the condition works properly.
|
// This tests that breaking the expression inside the condition works properly.
|
||||||
BOOST_CHECK_EQUAL(
|
BOOST_CHECK_EQUAL(
|
||||||
fullInline(R"({
|
fullInline("{"
|
||||||
if gt(f(mload(1)), mload(0)) {
|
"if gt(f(mload(1)), mload(0)) {"
|
||||||
sstore(0, 2)
|
"sstore(0, 2)"
|
||||||
}
|
"}"
|
||||||
function f(a) -> r {
|
"function f(a) -> r {"
|
||||||
a := mload(a)
|
"a := mload(a)"
|
||||||
r := add(a, calldatasize())
|
"r := add(a, calldatasize())"
|
||||||
}
|
"}"
|
||||||
})", false),
|
"}", false),
|
||||||
format(R"({
|
format("{"
|
||||||
{
|
"{"
|
||||||
let _1 := mload(0)
|
"let _1 := mload(0)"
|
||||||
let f_a := mload(1)
|
"let f_a := mload(1)"
|
||||||
let f_r
|
"let f_r"
|
||||||
{
|
"{"
|
||||||
f_a := mload(f_a)
|
"f_a := mload(f_a)"
|
||||||
f_r := add(f_a, calldatasize())
|
"f_r := add(f_a, calldatasize())"
|
||||||
}
|
"}"
|
||||||
if gt(f_r, _1)
|
"if gt(f_r, _1)"
|
||||||
{
|
"{"
|
||||||
sstore(0, 2)
|
"sstore(0, 2)"
|
||||||
}
|
"}"
|
||||||
}
|
"}"
|
||||||
function f(a) -> r
|
"function f(a) -> r"
|
||||||
{
|
"{"
|
||||||
a := mload(a)
|
"a := mload(a)"
|
||||||
r := add(a, calldatasize())
|
"r := add(a, calldatasize())"
|
||||||
}
|
"}"
|
||||||
})", false)
|
"}", false)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user