mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
A first stack shuffling unit test.
This commit is contained in:
parent
58dbeb8e92
commit
5449ad3c52
@ -145,6 +145,7 @@ set(libyul_sources
|
|||||||
libyul/Parser.cpp
|
libyul/Parser.cpp
|
||||||
libyul/StackLayoutGeneratorTest.cpp
|
libyul/StackLayoutGeneratorTest.cpp
|
||||||
libyul/StackLayoutGeneratorTest.h
|
libyul/StackLayoutGeneratorTest.h
|
||||||
|
libyul/StackShufflingTest.cpp
|
||||||
libyul/SyntaxTest.h
|
libyul/SyntaxTest.h
|
||||||
libyul/SyntaxTest.cpp
|
libyul/SyntaxTest.cpp
|
||||||
libyul/YulInterpreterTest.cpp
|
libyul/YulInterpreterTest.cpp
|
||||||
|
83
test/libyul/StackShufflingTest.cpp
Normal file
83
test/libyul/StackShufflingTest.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Unit tests for stack shuffling.
|
||||||
|
*/
|
||||||
|
#include <test/Common.h>
|
||||||
|
|
||||||
|
#include <libyul/backends/evm/StackHelpers.h>
|
||||||
|
#include <libyul/backends/evm/OptimizedEVMCodeTransform.h>
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace solidity::yul::test
|
||||||
|
{
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(StackHelpers)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(avoid_deep_dup)
|
||||||
|
{
|
||||||
|
vector<Scope::Variable> variableContainer;
|
||||||
|
for (size_t i = 0; i < 15; ++i)
|
||||||
|
variableContainer.emplace_back(Scope::Variable{YulString{}, YulString("v" + to_string(i))});
|
||||||
|
Stack from = {{
|
||||||
|
VariableSlot{variableContainer[0]},
|
||||||
|
VariableSlot{variableContainer[1]},
|
||||||
|
VariableSlot{variableContainer[2]},
|
||||||
|
VariableSlot{variableContainer[3]},
|
||||||
|
VariableSlot{variableContainer[4]},
|
||||||
|
VariableSlot{variableContainer[5]},
|
||||||
|
VariableSlot{variableContainer[6]},
|
||||||
|
VariableSlot{variableContainer[7]},
|
||||||
|
VariableSlot{variableContainer[8]},
|
||||||
|
VariableSlot{variableContainer[9]},
|
||||||
|
VariableSlot{variableContainer[10]},
|
||||||
|
VariableSlot{variableContainer[11]},
|
||||||
|
VariableSlot{variableContainer[12]},
|
||||||
|
VariableSlot{variableContainer[12]},
|
||||||
|
VariableSlot{variableContainer[13]},
|
||||||
|
VariableSlot{variableContainer[14]}
|
||||||
|
}};
|
||||||
|
Stack to = {{
|
||||||
|
VariableSlot{variableContainer[0]},
|
||||||
|
VariableSlot{variableContainer[1]},
|
||||||
|
VariableSlot{variableContainer[2]},
|
||||||
|
VariableSlot{variableContainer[3]},
|
||||||
|
VariableSlot{variableContainer[4]},
|
||||||
|
VariableSlot{variableContainer[5]},
|
||||||
|
VariableSlot{variableContainer[6]},
|
||||||
|
VariableSlot{variableContainer[7]},
|
||||||
|
VariableSlot{variableContainer[8]},
|
||||||
|
VariableSlot{variableContainer[9]},
|
||||||
|
VariableSlot{variableContainer[10]},
|
||||||
|
VariableSlot{variableContainer[11]},
|
||||||
|
VariableSlot{variableContainer[12]},
|
||||||
|
VariableSlot{variableContainer[12]},
|
||||||
|
VariableSlot{variableContainer[13]},
|
||||||
|
VariableSlot{variableContainer[14]},
|
||||||
|
VariableSlot{variableContainer[14]}, // While "optimal", bringing this slot up first will make the next unreachable.
|
||||||
|
VariableSlot{variableContainer[0]}
|
||||||
|
}};
|
||||||
|
auto unreachable = OptimizedEVMCodeTransform::tryCreateStackLayout(from, to, {});
|
||||||
|
BOOST_CHECK(unreachable.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
|
} // end namespaces
|
Loading…
Reference in New Issue
Block a user