diff options
author | chriseth <c@ethdev.com> | 2015-06-06 21:31:22 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-06-06 21:39:14 +0800 |
commit | 55e1729852716ccffeada013453e3c40f0edaf28 (patch) | |
tree | c6dffb1c5641907876faaf2a9991918cfeeef4f0 | |
parent | cad767de61dc53b9b297f08ee09cb5a3c0821782 (diff) | |
download | dexon-solidity-55e1729852716ccffeada013453e3c40f0edaf28.tar.gz dexon-solidity-55e1729852716ccffeada013453e3c40f0edaf28.tar.zst dexon-solidity-55e1729852716ccffeada013453e3c40f0edaf28.zip |
Quick fix to not access inaccessible sequences.
-rw-r--r-- | CommonSubexpressionEliminator.cpp | 9 | ||||
-rw-r--r-- | CommonSubexpressionEliminator.h | 3 | ||||
-rw-r--r-- | KnownState.h | 1 |
3 files changed, 13 insertions, 0 deletions
diff --git a/CommonSubexpressionEliminator.cpp b/CommonSubexpressionEliminator.cpp index b2fa7311..fe86908f 100644 --- a/CommonSubexpressionEliminator.cpp +++ b/CommonSubexpressionEliminator.cpp @@ -46,6 +46,7 @@ vector<AssemblyItem> CommonSubexpressionEliminator::getOptimizedItems() targetStackContents[height] = m_state.stackElement(height, SourceLocation()); AssemblyItems items = CSECodeGenerator(m_state.expressionClasses(), m_storeOperations).generateCode( + m_initialState.sequenceNumber(), m_initialState.stackHeight(), initialStackContents, targetStackContents @@ -112,6 +113,7 @@ CSECodeGenerator::CSECodeGenerator( } AssemblyItems CSECodeGenerator::generateCode( + unsigned _initialSequenceNumber, int _initialStackHeight, map<int, Id> const& _initialStack, map<int, Id> const& _targetStackContents @@ -137,7 +139,14 @@ AssemblyItems CSECodeGenerator::generateCode( for (auto const& p: m_neededBy) for (auto id: {p.first, p.second}) if (unsigned seqNr = m_expressionClasses.representative(id).sequenceNumber) + { + if (seqNr < _initialSequenceNumber) + // Invalid sequenced operation. + // @todo quick fix for now. Proper fix needs to choose representative with higher + // sequence number during dependency analyis. + BOOST_THROW_EXCEPTION(StackTooDeepException()); sequencedExpressions.insert(make_pair(seqNr, id)); + } // Perform all operations on storage and memory in order, if they are needed. for (auto const& seqAndId: sequencedExpressions) diff --git a/CommonSubexpressionEliminator.h b/CommonSubexpressionEliminator.h index a35e31d9..f6c43c57 100644 --- a/CommonSubexpressionEliminator.h +++ b/CommonSubexpressionEliminator.h @@ -105,10 +105,13 @@ public: CSECodeGenerator(ExpressionClasses& _expressionClasses, StoreOperations const& _storeOperations); /// @returns the assembly items generated from the given requirements + /// @param _initialSequenceNumber starting sequence number, do not generate sequenced operations + /// before this number. /// @param _initialStack current contents of the stack (up to stack height of zero) /// @param _targetStackContents final contents of the stack, by stack height relative to initial /// @note should only be called once on each object. AssemblyItems generateCode( + unsigned _initialSequenceNumber, int _initialStackHeight, std::map<int, Id> const& _initialStack, std::map<int, Id> const& _targetStackContents diff --git a/KnownState.h b/KnownState.h index 9d28ef21..dd6185c6 100644 --- a/KnownState.h +++ b/KnownState.h @@ -94,6 +94,7 @@ public: /// Resets any knowledge. void reset() { resetStorage(); resetMemory(); resetStack(); } + unsigned sequenceNumber() const { return m_sequenceNumber; } /// Manually increments the storage and memory sequence number. void incrementSequenceNumber() { m_sequenceNumber += 2; } |