aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-06-10 15:58:59 +0800
committerchriseth <c@ethdev.com>2015-06-10 15:58:59 +0800
commita72e357c4eb5b8d4052fd3df6288f0b2f13b7a0e (patch)
treead5146d3868b724b0fa7a576757c7709bffd8e29
parent6cc76baeaca0b9da785d089081709a1e680aac5a (diff)
downloaddexon-solidity-a72e357c4eb5b8d4052fd3df6288f0b2f13b7a0e.tar.gz
dexon-solidity-a72e357c4eb5b8d4052fd3df6288f0b2f13b7a0e.tar.zst
dexon-solidity-a72e357c4eb5b8d4052fd3df6288f0b2f13b7a0e.zip
Improved exception safety in CSE.
Fixes #2135
-rw-r--r--CommonSubexpressionEliminator.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/CommonSubexpressionEliminator.cpp b/CommonSubexpressionEliminator.cpp
index fadf2776..2c4742d6 100644
--- a/CommonSubexpressionEliminator.cpp
+++ b/CommonSubexpressionEliminator.cpp
@@ -35,6 +35,19 @@ vector<AssemblyItem> CommonSubexpressionEliminator::getOptimizedItems()
{
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> targetStackContents;
int minHeight = m_state.stackHeight() + 1;
@@ -52,15 +65,7 @@ vector<AssemblyItem> CommonSubexpressionEliminator::getOptimizedItems()
targetStackContents
);
if (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;
}