Browse Source

Improved exception safety in CSE.

Fixes #2135
cl-refactor
chriseth 10 years ago
parent
commit
eb6e4f0674
  1. 21
      libevmasm/CommonSubexpressionEliminator.cpp

21
libevmasm/CommonSubexpressionEliminator.cpp

@ -35,6 +35,19 @@ vector<AssemblyItem> CommonSubexpressionEliminator::getOptimizedItems()
{ {
optimizeBreakingItem(); optimizeBreakingItem();
KnownState nextInitialState = m_state;
if (m_breakingItem)
nextInitialState.feedItem(*m_breakingItem);
KnownState nextState = nextInitialState;
ScopeGuard reset([&]()
{
m_breakingItem = nullptr;
m_storeOperations.clear();
m_initialState = move(nextInitialState);
m_state = move(nextState);
});
map<int, Id> initialStackContents; map<int, Id> initialStackContents;
map<int, Id> targetStackContents; map<int, Id> targetStackContents;
int minHeight = m_state.stackHeight() + 1; int minHeight = m_state.stackHeight() + 1;
@ -52,15 +65,7 @@ vector<AssemblyItem> CommonSubexpressionEliminator::getOptimizedItems()
targetStackContents targetStackContents
); );
if (m_breakingItem) if (m_breakingItem)
{
items.push_back(*m_breakingItem); items.push_back(*m_breakingItem);
m_state.feedItem(*m_breakingItem);
}
// cleanup
m_initialState = m_state;
m_breakingItem = nullptr;
m_storeOperations.clear();
return items; return items;
} }

Loading…
Cancel
Save