ControlFlowAnalyser: Also consider called functions in a flow

This commit is contained in:
Mathias Baumann
2021-06-01 15:54:37 +02:00
parent 3dfa68a574
commit 56ebea8b2f
33 changed files with 723 additions and 52 deletions
+14 -6
View File
@@ -19,30 +19,38 @@
#pragma once
#include <libsolidity/analysis/ControlFlowGraph.h>
#include <liblangutil/ErrorReporter.h>
#include <set>
namespace solidity::frontend
{
class ControlFlowAnalyzer: private ASTConstVisitor
class ControlFlowAnalyzer
{
public:
explicit ControlFlowAnalyzer(CFG const& _cfg, langutil::ErrorReporter& _errorReporter):
m_cfg(_cfg), m_errorReporter(_errorReporter) {}
bool analyze(ASTNode const& _astRoot);
bool visit(FunctionDefinition const& _function) override;
bool run();
private:
void analyze(FunctionDefinition const& _function, ContractDefinition const* _contract, FunctionFlow const& _flow);
/// Checks for uninitialized variable accesses in the control flow between @param _entry and @param _exit.
void checkUninitializedAccess(CFGNode const* _entry, CFGNode const* _exit, bool _emptyBody) const;
/// @param _entry entry node
/// @param _exit exit node
/// @param _emptyBody whether the body of the function is empty (true) or not (false)
/// @param _contractName name of the most derived contract, should be empty
/// if the function is also defined in it
void checkUninitializedAccess(CFGNode const* _entry, CFGNode const* _exit, bool _emptyBody, std::optional<std::string> _contractName = {});
/// Checks for unreachable code, i.e. code ending in @param _exit, @param _revert or @param _transactionReturn
/// that can not be reached from @param _entry.
void checkUnreachable(CFGNode const* _entry, CFGNode const* _exit, CFGNode const* _revert, CFGNode const* _transactionReturn) const;
void checkUnreachable(CFGNode const* _entry, CFGNode const* _exit, CFGNode const* _revert, CFGNode const* _transactionReturn);
CFG const& m_cfg;
langutil::ErrorReporter& m_errorReporter;
std::set<langutil::SourceLocation> m_unreachableLocationsAlreadyWarnedFor;
std::set<VariableDeclaration const*> m_unassignedReturnVarsAlreadyWarnedFor;
};
}