Coverage Report

Created: 2022-08-24 06:55

/src/solidity/libsolidity/analysis/ControlFlowRevertPruner.h
Line
Count
Source
1
/*
2
  This file is part of solidity.
3
4
  solidity is free software: you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation, either version 3 of the License, or
7
  (at your option) any later version.
8
9
  solidity is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
14
  You should have received a copy of the GNU General Public License
15
  along with solidity.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
// SPDX-License-Identifier: GPL-3.0
18
19
#pragma once
20
21
#include <libsolidity/ast/AST.h>
22
#include <libsolidity/analysis/ControlFlowGraph.h>
23
24
#include <libsolutil/Algorithms.h>
25
26
namespace solidity::frontend
27
{
28
29
/**
30
 * Analyses all function flows and recursively removes all exit edges from CFG
31
 * nodes that make function calls that will always revert.
32
 */
33
class ControlFlowRevertPruner
34
{
35
public:
36
4.55k
  ControlFlowRevertPruner(CFG& _cfg): m_cfg(_cfg) {}
37
38
  void run();
39
private:
40
  /// Possible revert states of a function call
41
  enum class RevertState
42
  {
43
    AllPathsRevert,
44
    HasNonRevertingPath,
45
    Unknown,
46
  };
47
48
  /// Identify revert states of all function flows
49
  void findRevertStates();
50
51
  /// Modify function flows so that edges with reverting function calls are removed
52
  void modifyFunctionFlows();
53
54
  /// Control Flow Graph object.
55
  CFG& m_cfg;
56
57
  /// function/contract pairs mapped to their according revert state
58
  std::map<CFG::FunctionContractTuple, RevertState> m_functions;
59
60
  std::map<
61
    std::tuple<FunctionCall const*, ContractDefinition const*>,
62
    FunctionDefinition const*
63
  > m_resolveCache;
64
65
};
66
}