diff options
author | chriseth <chris@ethereum.org> | 2016-11-25 23:57:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-25 23:57:59 +0800 |
commit | 0933a4ff1a2c589c2289610d0d8f2758b53b77d8 (patch) | |
tree | dd00266d92869eab8b781111e6a5961b779f46aa /test | |
parent | b179dfd1015f328676e36565b46f03bb74277af9 (diff) | |
parent | f5216249527a82834162d66f93f15a50346e38d4 (diff) | |
download | dexon-solidity-0933a4ff1a2c589c2289610d0d8f2758b53b77d8.tar dexon-solidity-0933a4ff1a2c589c2289610d0d8f2758b53b77d8.tar.gz dexon-solidity-0933a4ff1a2c589c2289610d0d8f2758b53b77d8.tar.bz2 dexon-solidity-0933a4ff1a2c589c2289610d0d8f2758b53b77d8.tar.lz dexon-solidity-0933a4ff1a2c589c2289610d0d8f2758b53b77d8.tar.xz dexon-solidity-0933a4ff1a2c589c2289610d0d8f2758b53b77d8.tar.zst dexon-solidity-0933a4ff1a2c589c2289610d0d8f2758b53b77d8.zip |
Merge pull request #1429 from ethereum/unreachablepeephole
Some dead code elimination
Diffstat (limited to 'test')
-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"( |