aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <g@ethdev.com>2015-06-07 13:19:51 +0800
committerGav Wood <g@ethdev.com>2015-06-07 13:19:51 +0800
commitdc462dcb6e41da200557434a33461705d039bdc8 (patch)
tree6b6d5ace7bb14bb4702914d8c7188f14db4a09dd
parent7bdd1b1d4ae46920ae54aaa61c40b411a75f15b9 (diff)
parent55e1729852716ccffeada013453e3c40f0edaf28 (diff)
downloaddexon-solidity-dc462dcb6e41da200557434a33461705d039bdc8.tar.gz
dexon-solidity-dc462dcb6e41da200557434a33461705d039bdc8.tar.zst
dexon-solidity-dc462dcb6e41da200557434a33461705d039bdc8.zip
Merge pull request #2103 from chriseth/sol_fix_sequenceError
Invalid sequence access.
-rw-r--r--CommonSubexpressionEliminator.cpp9
-rw-r--r--CommonSubexpressionEliminator.h3
-rw-r--r--KnownState.h1
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; }