Compatibility with StackCompressor and StackLimitEvader.

This commit is contained in:
Daniel Kirchner 2021-08-12 17:17:21 +02:00
parent c01a0bba17
commit 2e6d3e0a1b
3 changed files with 22 additions and 8 deletions

View File

@ -229,10 +229,7 @@ bool StackCompressor::run(
); );
bool usesOptimizedCodeGenerator = false; bool usesOptimizedCodeGenerator = false;
if (auto evmDialect = dynamic_cast<EVMDialect const*>(&_dialect)) if (auto evmDialect = dynamic_cast<EVMDialect const*>(&_dialect))
usesOptimizedCodeGenerator = usesOptimizedCodeGenerator = _optimizeStackAllocation && evmDialect->evmVersion().canOverchargeGasForCall();
_optimizeStackAllocation &&
evmDialect->evmVersion().canOverchargeGasForCall() &&
evmDialect->providesObjectAccess();
bool allowMSizeOptimzation = !MSizeFinder::containsMSize(_dialect, *_object.code); bool allowMSizeOptimzation = !MSizeFinder::containsMSize(_dialect, *_object.code);
if (usesOptimizedCodeGenerator) if (usesOptimizedCodeGenerator)
{ {

View File

@ -96,8 +96,7 @@ void OptimiserSuite::run(
bool usesOptimizedCodeGenerator = bool usesOptimizedCodeGenerator =
_optimizeStackAllocation && _optimizeStackAllocation &&
evmDialect && evmDialect &&
evmDialect->evmVersion().canOverchargeGasForCall() && evmDialect->evmVersion().canOverchargeGasForCall();
evmDialect->providesObjectAccess();
set<YulString> reservedIdentifiers = _externallyUsedIdentifiers; set<YulString> reservedIdentifiers = _externallyUsedIdentifiers;
reservedIdentifiers += _dialect.fixedFunctionNames(); reservedIdentifiers += _dialect.fixedFunctionNames();

View File

@ -29,6 +29,25 @@ using namespace std;
namespace solidity::yul::test namespace solidity::yul::test
{ {
namespace
{
bool triggersStackTooDeep(Stack _source, Stack const& _target)
{
bool result = false;
createStackLayout(_source, _target, [&](unsigned _i) {
if (_i > 16)
result = true;
}, [&](StackSlot const& _slot) {
if (canBeFreelyGenerated(_slot))
return;
if (auto depth = util::findOffset(_source | ranges::views::reverse, _slot); depth && *depth >= 16)
if (*depth >= 16)
result = true;
}, [&]() {});
return result;
}
}
BOOST_AUTO_TEST_SUITE(StackHelpers) BOOST_AUTO_TEST_SUITE(StackHelpers)
BOOST_AUTO_TEST_CASE(avoid_deep_dup) BOOST_AUTO_TEST_CASE(avoid_deep_dup)
@ -74,8 +93,7 @@ BOOST_AUTO_TEST_CASE(avoid_deep_dup)
VariableSlot{variableContainer[14]}, // While "optimal", bringing this slot up first will make the next unreachable. VariableSlot{variableContainer[14]}, // While "optimal", bringing this slot up first will make the next unreachable.
VariableSlot{variableContainer[0]} VariableSlot{variableContainer[0]}
}}; }};
auto unreachable = OptimizedEVMCodeTransform::tryCreateStackLayout(from, to, {}); BOOST_CHECK(!triggersStackTooDeep(from, to));
BOOST_CHECK(unreachable.empty());
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()