From 3f48c655e52faa8682357107b629bc834def8b8e Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 21 Nov 2016 11:54:41 +0100 Subject: [PATCH 1/2] Update version. --- CMakeLists.txt | 2 +- docs/conf.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20c96869bde7..992ce3920c9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ include(EthPolicy) eth_policy() # project name and version should be set after cmake_policy CMP0048 -set(PROJECT_VERSION "0.4.5") +set(PROJECT_VERSION "0.4.6") project(solidity VERSION ${PROJECT_VERSION}) # Let's find our dependencies diff --git a/docs/conf.py b/docs/conf.py index e17d5fd8fff2..bf0accb9eec5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -56,9 +56,9 @@ def setup(sphinx): # built documents. # # The short X.Y version. -version = '0.4.5' +version = '0.4.6' # The full version, including alpha/beta/rc tags. -release = '0.4.5-develop' +release = '0.4.6-develop' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From 7fb7d5ae39a4bd5e0852db1fe5d21fdd4a0fd80f Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 22 Nov 2016 14:55:09 +0100 Subject: [PATCH 2/2] Optimizer: Clear state for JUMPDESTs. --- Changelog.md | 5 +++ libevmasm/Assembly.cpp | 61 +++++++++++--------------- test/libsolidity/SolidityOptimizer.cpp | 20 +++++++++ 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/Changelog.md b/Changelog.md index abd8d593a458..eb1e5e72d5c0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,8 @@ +### 0.4.6 (2016-11-22) + +Bugfixes: + * Optimizer: Knowledge about state was not correctly cleared for JUMPDESTs + ### 0.4.5 (2016-11-21) Features: diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index a3037456424e..c394afa24507 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -360,46 +360,35 @@ map Assembly::optimiseInternal(bool _enable, bool _isCreation, size_ auto iter = m_items.begin(); while (iter != m_items.end()) { - auto end = iter; - while (end != m_items.end()) - if (SemanticInformation::altersControlFlow(*end++)) - break; - KnownState emptyState; CommonSubexpressionEliminator eliminator(emptyState); - auto blockIter = iter; - auto const blockEnd = end; - while (blockIter < blockEnd) + auto orig = iter; + iter = eliminator.feedItems(iter, m_items.end()); + bool shouldReplace = false; + AssemblyItems optimisedChunk; + try + { + optimisedChunk = eliminator.getOptimizedItems(); + shouldReplace = (optimisedChunk.size() < size_t(iter - orig)); + } + catch (StackTooDeepException const&) + { + // This might happen if the opcode reconstruction is not as efficient + // as the hand-crafted code. + } + catch (ItemNotAvailableException const&) { - auto orig = blockIter; - blockIter = eliminator.feedItems(blockIter, blockEnd); - bool shouldReplace = false; - AssemblyItems optimisedChunk; - try - { - optimisedChunk = eliminator.getOptimizedItems(); - shouldReplace = (optimisedChunk.size() < size_t(blockIter - orig)); - } - catch (StackTooDeepException const&) - { - // This might happen if the opcode reconstruction is not as efficient - // as the hand-crafted code. - } - catch (ItemNotAvailableException const&) - { - // This might happen if e.g. associativity and commutativity rules - // reorganise the expression tree, but not all leaves are available. - } - - if (shouldReplace) - { - count++; - optimisedItems += optimisedChunk; - } - else - copy(orig, blockIter, back_inserter(optimisedItems)); + // This might happen if e.g. associativity and commutativity rules + // reorganise the expression tree, but not all leaves are available. } - iter = end; + + if (shouldReplace) + { + count++; + optimisedItems += optimisedChunk; + } + else + copy(orig, iter, back_inserter(optimisedItems)); } if (optimisedItems.size() < m_items.size()) { diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp index 4991cf24f6d8..017fc0e92229 100644 --- a/test/libsolidity/SolidityOptimizer.cpp +++ b/test/libsolidity/SolidityOptimizer.cpp @@ -1246,6 +1246,26 @@ BOOST_AUTO_TEST_CASE(dead_code_elimination_across_assemblies) compareVersions("test()"); } +BOOST_AUTO_TEST_CASE(invalid_state_at_control_flow_join) +{ + char const* sourceCode = R"( + contract Test { + uint256 public totalSupply = 100; + function f() returns (uint r) { + if (false) + r = totalSupply; + totalSupply -= 10; + } + function test() returns (uint) { + f(); + return this.totalSupply(); + } + } + )"; + compileBothVersions(sourceCode); + compareVersions("test()"); +} + BOOST_AUTO_TEST_SUITE_END() }