diff options
Diffstat (limited to 'test/libsolidity/SolidityOptimizer.cpp')
-rw-r--r-- | test/libsolidity/SolidityOptimizer.cpp | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp index ecb44272..a53a2638 100644 --- a/test/libsolidity/SolidityOptimizer.cpp +++ b/test/libsolidity/SolidityOptimizer.cpp @@ -20,17 +20,21 @@ * Tests for the Solidity optimizer. */ -#include <string> -#include <tuple> -#include <memory> -#include <boost/test/unit_test.hpp> -#include <boost/lexical_cast.hpp> #include <test/libsolidity/SolidityExecutionFramework.h> + #include <libevmasm/CommonSubexpressionEliminator.h> +#include <libevmasm/PeepholeOptimiser.h> #include <libevmasm/ControlFlowGraph.h> #include <libevmasm/Assembly.h> #include <libevmasm/BlockDeduplicator.h> +#include <boost/test/unit_test.hpp> +#include <boost/lexical_cast.hpp> + +#include <string> +#include <tuple> +#include <memory> + using namespace std; using namespace dev::eth; @@ -1121,6 +1125,40 @@ BOOST_AUTO_TEST_CASE(block_deduplicator_loops) BOOST_CHECK_EQUAL(pushTags.size(), 1); } +BOOST_AUTO_TEST_CASE(clear_unreachable_code) +{ + AssemblyItems items{ + AssemblyItem(PushTag, 1), + Instruction::JUMP, + u256(0), + Instruction::SLOAD, + AssemblyItem(Tag, 2), + u256(5), + u256(6), + Instruction::SSTORE, + AssemblyItem(PushTag, 1), + Instruction::JUMP, + u256(5), + u256(6) + }; + AssemblyItems expectation{ + AssemblyItem(PushTag, 1), + Instruction::JUMP, + AssemblyItem(Tag, 2), + u256(5), + u256(6), + Instruction::SSTORE, + AssemblyItem(PushTag, 1), + Instruction::JUMP + }; + PeepholeOptimiser peepOpt(items); + BOOST_REQUIRE(peepOpt.optimise()); + BOOST_CHECK_EQUAL_COLLECTIONS( + items.begin(), items.end(), + expectation.begin(), expectation.end() + ); +} + BOOST_AUTO_TEST_CASE(computing_constants) { char const* sourceCode = R"( |