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/StringSet.h"
102 void reevaluateBehaviour();
111 bool ContainsUnknown;
122 IgnoredExceptions = std::move(ExceptionNames);
125 ExceptionInfo
analyze(
const FunctionDecl *Func);
126 ExceptionInfo
analyze(
const Stmt *Stmt);
130 throwsException(
const FunctionDecl *Func,
132 llvm::SmallSet<const FunctionDecl *, 32> &CallStack);
135 llvm::SmallSet<const FunctionDecl *, 32> &CallStack);
137 ExceptionInfo analyzeImpl(
const FunctionDecl *Func);
138 ExceptionInfo analyzeImpl(
const Stmt *Stmt);
140 template <
typename T> ExceptionInfo analyzeDispatch(
const T *Node);
142 bool IgnoreBadAlloc =
true;
143 llvm::StringSet<> IgnoredExceptions;
144 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
bool 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 createNonThrowing()
void clear()
Clear the state to 'NonThrowing' to make the corresponding entity neutral.
const Throwables & getExceptionTypes() const
References the set of known exception types that can escape from the corresponding entity.
void registerException(const Type *ExceptionType)
Register a single exception type as recognized potential exception to be thrown.
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...
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.
llvm::SmallSet< const Type *, 2 > Throwables
ExceptionInfo & merge(const ExceptionInfo &Other)
Updates the local state according to the other state.
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
This class analysis if a FunctionDecl can in principle throw an exception, either directly or indirec...
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.
ExceptionInfo analyze(const FunctionDecl *Func)
ExceptionAnalyzer()=default