Coverage Report

Created: 2022-08-24 06:43

/src/solidity/libsolidity/analysis/ControlFlowAnalyzer.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/analysis/ControlFlowGraph.h>
22
#include <liblangutil/ErrorReporter.h>
23
#include <set>
24
25
namespace solidity::frontend
26
{
27
28
class ControlFlowAnalyzer
29
{
30
public:
31
  explicit ControlFlowAnalyzer(CFG const& _cfg, langutil::ErrorReporter& _errorReporter):
32
8.40k
    m_cfg(_cfg), m_errorReporter(_errorReporter) {}
33
34
  bool run();
35
36
private:
37
  void analyze(FunctionDefinition const& _function, ContractDefinition const* _contract, FunctionFlow const& _flow);
38
  /// Checks for uninitialized variable accesses in the control flow between @param _entry and @param _exit.
39
  /// @param _entry entry node
40
  /// @param _exit exit node
41
  /// @param _emptyBody whether the body of the function is empty (true) or not (false)
42
  /// @param _contractName name of the most derived contract, should be empty
43
  ///        if the function is also defined in it
44
  void checkUninitializedAccess(CFGNode const* _entry, CFGNode const* _exit, bool _emptyBody, std::optional<std::string> _contractName = {});
45
  /// Checks for unreachable code, i.e. code ending in @param _exit, @param _revert or @param _transactionReturn
46
  /// that can not be reached from @param _entry.
47
  void checkUnreachable(CFGNode const* _entry, CFGNode const* _exit, CFGNode const* _revert, CFGNode const* _transactionReturn);
48
49
  CFG const& m_cfg;
50
  langutil::ErrorReporter& m_errorReporter;
51
52
  std::set<langutil::SourceLocation> m_unreachableLocationsAlreadyWarnedFor;
53
  std::set<VariableDeclaration const*> m_unassignedReturnVarsAlreadyWarnedFor;
54
};
55
56
}