9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_ANALYZER_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_ANALYZER_H
12#include "clang/AST/ASTContext.h"
13#include "clang/ASTMatchers/ASTMatchFinder.h"
14#include "llvm/ADT/SmallSet.h"
15#include "llvm/ADT/SmallVector.h"
16#include "llvm/ADT/StringSet.h"
34 using CallStack = llvm::MapVector<const FunctionDecl *, SourceLocation>;
52 using Throwables = llvm::SmallDenseMap<const Type *, ThrowInfo, 2>;
73 const ThrowInfo &ThrowInfo);
116 void reevaluateBehaviour();
125 bool ContainsUnknown;
136 IgnoredExceptions = std::move(ExceptionNames);
139 ExceptionInfo
analyze(
const FunctionDecl *Func);
140 ExceptionInfo
analyze(
const Stmt *Stmt);
143 ExceptionInfo throwsException(
const FunctionDecl *Func,
146 ExceptionInfo throwsException(
const Stmt *St,
149 ExceptionInfo analyzeImpl(
const FunctionDecl *Func);
150 ExceptionInfo analyzeImpl(
const Stmt *Stmt);
152 template <
typename T> ExceptionInfo analyzeDispatch(
const T *Node);
154 bool IgnoreBadAlloc =
true;
155 llvm::StringSet<> IgnoredExceptions;
156 llvm::DenseMap<const FunctionDecl *, ExceptionInfo> FunctionCache{32U};
Bundle the gathered information about an entity like a function regarding it's exception behaviour.
State getBehaviour() const
static ExceptionInfo createNonThrowing()
const Throwables & getExceptions() const
References the set of known exceptions that can escape from the corresponding entity.
void clear()
Clear the state to 'NonThrowing' to make the corresponding entity neutral.
llvm::SmallDenseMap< const Type *, ThrowInfo, 2 > Throwables
ExceptionInfo & operator=(const ExceptionInfo &)=default
ExceptionInfo & filterIgnoredExceptions(const llvm::StringSet<> &IgnoredTypes, bool IgnoreBadAlloc)
Filter the set of thrown exception type against a set of ignored types that shall not be considered i...
Throwables filterByCatch(const Type *HandlerTy, const ASTContext &Context)
This method is useful in case 'catch' clauses are analyzed as it is possible to catch multiple except...
static ExceptionInfo createUnknown()
ExceptionInfo(const ExceptionInfo &)=default
void registerExceptions(const Throwables &Exceptions)
Registers a SmallVector of exception types as recognized potential exceptions to be thrown.
ExceptionInfo()
By default the exception situation is unknown and must be clarified step-wise.
ExceptionInfo & merge(const ExceptionInfo &Other)
Updates the local state according to the other state.
void registerException(const Type *ExceptionType, const ThrowInfo &ThrowInfo)
Register a single exception type as recognized potential exception to be thrown.
bool containsUnknownElements() const
Signal if the there is any 'Unknown' element within the scope of the related entity.
ExceptionInfo(ExceptionInfo &&)=default
ExceptionInfo & operator=(ExceptionInfo &&)=default
void ignoreBadAlloc(bool ShallIgnore)
void ignoreExceptions(llvm::StringSet<> ExceptionNames)
@ Throwing
The function can definitely throw given an AST.
@ Unknown
This can happen for extern functions without available definition.
@ NotThrowing
This function can not throw, given an AST.
llvm::MapVector< const FunctionDecl *, SourceLocation > CallStack
We use a MapVector to preserve the order of the functions in the call stack as well as have fast look...
ExceptionInfo analyze(const FunctionDecl *Func)
ExceptionAnalyzer()=default
Holds information about where an exception is thrown.