Skip to content

Commit 1d1db51

Browse files
committed
Fix revert pruner modifying function flows wrong
1 parent 424edcc commit 1d1db51

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

libsolidity/analysis/ControlFlowBuilder.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,37 +260,51 @@ bool ControlFlowBuilder::visit(PlaceholderStatement const&)
260260

261261
bool ControlFlowBuilder::visit(FunctionCall const& _functionCall)
262262
{
263+
solAssert(!!m_revertNode, "");
263264
solAssert(!!m_currentNode, "");
264265
solAssert(!!_functionCall.expression().annotation().type, "");
265266

266267
if (auto functionType = dynamic_cast<FunctionType const*>(_functionCall.expression().annotation().type))
267268
switch (functionType->kind())
268269
{
269270
case FunctionType::Kind::Revert:
270-
solAssert(!!m_revertNode, "");
271271
visitNode(_functionCall);
272272
_functionCall.expression().accept(*this);
273273
ASTNode::listAccept(_functionCall.arguments(), *this);
274+
274275
connect(m_currentNode, m_revertNode);
276+
275277
m_currentNode = newLabel();
276278
return false;
277279
case FunctionType::Kind::Require:
278280
case FunctionType::Kind::Assert:
279281
{
280-
solAssert(!!m_revertNode, "");
281282
visitNode(_functionCall);
282283
_functionCall.expression().accept(*this);
283284
ASTNode::listAccept(_functionCall.arguments(), *this);
285+
284286
connect(m_currentNode, m_revertNode);
287+
285288
auto nextNode = newLabel();
289+
286290
connect(m_currentNode, nextNode);
287291
m_currentNode = nextNode;
288292
return false;
289293
}
290294
case FunctionType::Kind::Internal:
291295
{
296+
visitNode(_functionCall);
297+
_functionCall.expression().accept(*this);
298+
ASTNode::listAccept(_functionCall.arguments(), *this);
299+
292300
m_currentNode->functionCalls.emplace_back(&_functionCall);
293-
break;
301+
302+
auto nextNode = newLabel();
303+
304+
connect(m_currentNode, nextNode);
305+
m_currentNode = nextNode;
306+
307+
return false;
294308
}
295309
default:
296310
break;

libsolidity/analysis/ControlFlowRevertPruner.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <libsolutil/Algorithms.h>
2222

23+
#include <range/v3/algorithm/remove.hpp>
24+
2325

2426
namespace solidity::frontend
2527
{
@@ -192,7 +194,11 @@ void ControlFlowRevertPruner::modifyFunctionFlows()
192194
// change anymore, we treat all "unknown" states as
193195
// "reverting", since they can only be caused by
194196
// recursion.
197+
for (CFGNode * node: _node->exits)
198+
ranges::remove(node->entries, _node);
199+
195200
_node->exits = {functionFlow.revert};
201+
functionFlow.revert->entries.push_back(_node);
196202
return;
197203
default:
198204
break;

0 commit comments

Comments
 (0)