Skip to content

Commit

Permalink
Update ControlFlowSideEffectsCollector.cpp
Browse files Browse the repository at this point in the history
There are errors in the function void ControlFlowBuilder::operator()(If const& _if) and function void ControlFlowBuilder::operator()(Switch const& _switch) when calculating CFG.
1. In the function void ControlFlowBuilder::operator()(If const& _if), the if.condion block is not the same block as the if.then block. The original code is calculated as one same block.
2. The switch.expression block are not the same block as all the cases block in cases, the original code is calculated as one same block.
This can cause some potential problems during the optimization phase.
  • Loading branch information
ChrisXXXXXXX authored and ekpyron committed Dec 1, 2022
1 parent 4100a59 commit feade14
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions libyul/ControlFlowSideEffectsCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ void ControlFlowBuilder::operator()(If const& _if)
{
visit(*_if.condition);
ControlFlowNode* node = m_currentNode;
(*this)(_if.body);

ControlFlowNode* ifEnd = newNode();
node->successors.emplace_back(ifEnd);

newConnectedNode();
node->successors.emplace_back(m_currentNode);
(*this)(_if.body);

m_currentNode->successors.emplace_back(ifEnd);
m_currentNode = ifEnd;
}

void ControlFlowBuilder::operator()(Switch const& _switch)
Expand All @@ -68,8 +74,8 @@ void ControlFlowBuilder::operator()(Switch const& _switch)
for (Case const& case_: _switch.cases)
{
m_currentNode = initialNode;
(*this)(case_.body);
newConnectedNode();
(*this)(case_.body);
m_currentNode->successors.emplace_back(finalNode);
}
m_currentNode = finalNode;
Expand Down Expand Up @@ -282,4 +288,3 @@ void ControlFlowSideEffectsCollector::recordReachabilityAndQueue(
if (m_processedNodes[&_function].insert(_node).second)
m_pendingNodes.at(&_function).push_front(_node);
}

0 comments on commit feade14

Please sign in to comment.