From ac0d1388008ed616ab7b35a5b3a27e7400decd46 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 29 Jul 2016 11:46:57 +0200 Subject: Test case. --- test/libsolidity/SolidityOptimizer.cpp | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp index 67b161b9..2e4ed4b3 100644 --- a/test/libsolidity/SolidityOptimizer.cpp +++ b/test/libsolidity/SolidityOptimizer.cpp @@ -1177,6 +1177,64 @@ BOOST_AUTO_TEST_CASE(computing_constants) ) == optimizedBytecode.cend()); } +BOOST_AUTO_TEST_CASE(inconsistency) +{ + // This is a test of a bug in the optimizer. + char const* sourceCode = R"( + contract Inconsistency { + struct Value { + uint badnum; + uint number; + } + + struct Container { + uint[] valueIndices; + Value[] values; + } + + Container[] containers; + uint[] valueIndices; + uint INDEX_ZERO = 0; + uint debug; + + // Called with params: containerIndex=0, valueIndex=0 + function levelIII(uint containerIndex, uint valueIndex) private { + Container container = containers[containerIndex]; + Value value = container.values[valueIndex]; + debug = container.valueIndices[value.number]; + } + function levelII() private { + for (uint i = 0; i < valueIndices.length; i++) { + levelIII(INDEX_ZERO, valueIndices[i]); + } + } + + function trigger() public returns (uint) { + containers.length++; + Container container = containers[0]; + + container.values.push(Value({ + badnum: 9000, + number: 0 + })); + + container.valueIndices.length++; + valueIndices.length++; + + levelII(); + return debug; + } + + function DoNotCallButDoNotDelete() public { + levelII(); + levelIII(1, 2); + } + } + )"; + compileBothVersions(sourceCode); + compareVersions("trigger()"); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 93ebaa4822571cd0a83906b4665f34c34d2343f7 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 29 Jul 2016 11:47:26 +0200 Subject: Reset knowledge in optimizer for path joins. --- libevmasm/Assembly.cpp | 3 ++- libevmasm/ControlFlowGraph.cpp | 5 ++++- libevmasm/ControlFlowGraph.h | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 7f7e1b9c..2024b1e9 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -322,7 +322,8 @@ Assembly& Assembly::optimise(bool _enable, bool _isCreation, size_t _runs) count++; { - ControlFlowGraph cfg(m_items); + // Control flow graph that resets knowledge at path joins. + ControlFlowGraph cfg(m_items, false); AssemblyItems optimisedItems; for (BasicBlock const& block: cfg.optimisedBlocks()) { diff --git a/libevmasm/ControlFlowGraph.cpp b/libevmasm/ControlFlowGraph.cpp index fc2144c7..61b24e4b 100644 --- a/libevmasm/ControlFlowGraph.cpp +++ b/libevmasm/ControlFlowGraph.cpp @@ -250,7 +250,10 @@ void ControlFlowGraph::gatherKnowledge() KnownStatePointer state = item.state; if (block.startState) { - state->reduceToCommonKnowledge(*block.startState, !item.blocksSeen.count(item.blockId)); + if (m_joinKnowledge) + state->reduceToCommonKnowledge(*block.startState, !item.blocksSeen.count(item.blockId)); + else + state->reset(); if (*state == *block.startState) continue; } diff --git a/libevmasm/ControlFlowGraph.h b/libevmasm/ControlFlowGraph.h index 4480ba49..a6a9df8e 100644 --- a/libevmasm/ControlFlowGraph.h +++ b/libevmasm/ControlFlowGraph.h @@ -94,7 +94,11 @@ class ControlFlowGraph public: /// Initializes the control flow graph. /// @a _items has to persist across the usage of this class. - ControlFlowGraph(AssemblyItems const& _items): m_items(_items) {} + /// @a _joinKnowledge if true, reduces state knowledge to common base at the join of two paths + explicit ControlFlowGraph(AssemblyItems const& _items, bool _joinKnowledge = true): + m_items(_items), + m_joinKnowledge(_joinKnowledge) + {} /// @returns vector of basic blocks in the order they should be used in the final code. /// Should be called only once. BasicBlocks optimisedBlocks(); @@ -112,6 +116,7 @@ private: unsigned m_lastUsedId = 0; AssemblyItems const& m_items; + bool m_joinKnowledge; std::map m_blocks; }; -- cgit v1.2.3 From e1e6f3ba139b53fa1eb55ad8a87317ce83f67f66 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 1 Aug 2016 15:33:01 +0200 Subject: Run the tests only three times. --- .travis.yml | 10 ++-------- scripts/tests.sh | 8 ++++++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 87932e8d..b723f81c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -82,15 +82,9 @@ before_script: && ./scripts/release.sh $ZIP_SUFFIX script: # There are a variety of reliability issues with the Solidity unit-tests at the time of - # writing, so we're actually running them 5 times in a row, to try to flush all of these + # writing, so we're actually running them 3 times in a row, to try to flush all of these # issues out as quickly as possible. See https://github.com/ethereum/solidity/issues/769 - - cd $TRAVIS_BUILD_DIR && ./scripts/tests.sh - - cd $TRAVIS_BUILD_DIR && ./scripts/tests.sh - - cd $TRAVIS_BUILD_DIR && ./scripts/tests.sh - - cd $TRAVIS_BUILD_DIR && ./scripts/tests.sh - - cd $TRAVIS_BUILD_DIR && ./scripts/tests.sh -after_success: - - cd $TRAVIS_BUILD_DIR && ./scripts/docs.sh + - cd $TRAVIS_BUILD_DIR && (./scripts/tests.sh || ./scripts/tests.sh || ./scripts/tests.sh) env: global: - ENCRYPTION_LABEL="296c219a3f41" diff --git a/scripts/tests.sh b/scripts/tests.sh index c342c65f..6ee816b0 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -26,6 +26,8 @@ # (c) 2016 solidity contributors. #------------------------------------------------------------------------------ +set -e + # There is an implicit assumption here that we HAVE to run from root directory. REPO_ROOT=$(pwd) @@ -59,7 +61,9 @@ while [ ! -S /tmp/test/geth.ipc ]; do sleep 2; done # need to check if this command-line support works for Windows too, when we # have implemented IPC Sockets support at all for Windows. export ETH_TEST_IPC=/tmp/test/geth.ipc -$REPO_ROOT/build/test/soltest +"$REPO_ROOT"/build/test/soltest ERROR_CODE=$? -pkill eth +pkill eth || true +sleep 4 +pgrep eth && pkill -9 eth || true exit $ERROR_CODE -- cgit v1.2.3