mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2103 from chriseth/sol_fix_sequenceError
Invalid sequence access.
This commit is contained in:
commit
dc462dcb6e
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user