17#ifndef LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H
18#define LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H
26#include "llvm/ADT/DenseMap.h"
27#include "llvm/ADT/FoldingSet.h"
28#include "llvm/ADT/StringRef.h"
29#include "llvm/ADT/iterator_range.h"
30#include "llvm/Support/Allocator.h"
78 std::unique_ptr<CFG> cfg, completeCFG;
79 std::optional<CFGStmtMap> cfgStmtMap;
84 bool builtCFG =
false;
85 bool builtCompleteCFG =
false;
86 std::unique_ptr<ParentMap> PM;
87 std::unique_ptr<CFGReverseBlockReachabilityAnalysis> CFA;
89 llvm::BumpPtrAllocator A;
91 llvm::DenseMap<const BlockDecl *, void *> *ReferencedBlockVars =
nullptr;
93 void *ManagedAnalyses =
nullptr;
112 return cfgBuildOptions;
120 return !cfgBuildOptions.PruneTriviallyFalseEdges;
172 llvm::iterator_range<referenced_decls_iterator>
182 unsigned BlockCount,
unsigned Index);
187 const void *tag = T::getTag();
188 std::unique_ptr<ManagedAnalysis> &data = getAnalysisImpl(tag);
190 data = T::create(*
this);
191 return static_cast<T *
>(data.get());
200 std::unique_ptr<ManagedAnalysis> &getAnalysisImpl(
const void *tag);
221 const Expr *CallSite;
229 const unsigned BlockCount;
232 const unsigned Index;
237 unsigned BlockCount,
unsigned Index, int64_t ID)
238 : Ctx(ADC), Parent(Parent), ID(ID), Data(Data), CallSite(E), Block(Block),
239 BlockCount(BlockCount), Index(Index) {
245 LLVM_ATTRIBUTE_RETURNS_NONNULL
269 assert(Current &&
"Cannot call ++ on the end iterator");
270 Current = Current->getParent();
279 return Current ==
Other.Current;
282 return !(*
this ==
Other);
289 llvm::iterator_range<parent_iterator>
parents()
const {
298 int64_t
getID()
const {
return ID; }
306 template <
typename T>
T *
getAnalysis()
const {
return Ctx->getAnalysis<
T>(); }
338 raw_ostream &Out,
const char *NL =
"\n",
unsigned int Space = 0,
346 LLVM_DUMP_METHOD
void dumpStack(raw_ostream &Out)
const;
348 LLVM_DUMP_METHOD
void dump()
const;
350 void Profile(llvm::FoldingSetNodeID &ID);
354 const CFGBlock *Block,
unsigned BlockCount,
360 ID.AddPointer(Block);
361 ID.AddInteger(BlockCount);
362 ID.AddInteger(Index);
367 llvm::FoldingSet<StackFrame> Frames;
391 unsigned BlockCount,
unsigned StmtIdx);
399 llvm::DenseMap<const Decl *, std::unique_ptr<AnalysisDeclContext>>;
407 std::unique_ptr<CodeInjector> Injector;
415 bool SynthesizeBodies;
419 ASTContext &ASTCtx,
bool useUnoptimizedCFG =
false,
420 bool addImplicitDtors =
false,
bool addInitializers =
false,
421 bool addTemporaryDtors =
false,
bool addLifetime =
false,
422 bool addLoopExit =
false,
bool addScopes =
false,
424 bool addCXXNewAllocator =
true,
bool addRichCXXConstructors =
true,
425 bool markElidedCXXConstructors =
true,
bool addVirtualBaseBranches =
true,
426 std::unique_ptr<CodeInjector> injector =
nullptr);
431 return !cfgBuildOptions.PruneTriviallyFalseEdges;
443 return SFMgr.getStackFrame(
getContext(D),
nullptr,
nullptr,
nullptr,
Defines the clang::CodeInjector interface which is responsible for injecting AST of function definiti...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
AnalysisDeclContextManager(ASTContext &ASTCtx, bool useUnoptimizedCFG=false, bool addImplicitDtors=false, bool addInitializers=false, bool addTemporaryDtors=false, bool addLifetime=false, bool addLoopExit=false, bool addScopes=false, bool synthesizeBodies=false, bool addStaticInitBranches=false, bool addCXXNewAllocator=true, bool addRichCXXConstructors=true, bool markElidedCXXConstructors=true, bool addVirtualBaseBranches=true, std::unique_ptr< CodeInjector > injector=nullptr)
friend class AnalysisDeclContext
bool synthesizeBodies() const
const StackFrame * getTopStackFrame(const Decl *D)
Obtain the beginning context of the analysis.
CFG::BuildOptions & getCFGBuildOptions()
void clear()
Discard all previously created AnalysisDeclContexts.
AnalysisDeclContext * getContext(const Decl *D)
bool getUseUnoptimizedCFG() const
AnalysisDeclContext contains the context data for the function, method or block under analysis.
static std::string getFunctionName(const Decl *D)
void registerForcedBlockExpression(const Stmt *stmt)
const CFGBlock * getBlockForRegisteredExpression(const Stmt *stmt)
bool getUseUnoptimizedCFG() const
ParentMap & getParentMap()
const VarDecl *const * referenced_decls_iterator
const Decl * getDecl() const
bool getAddImplicitDtors() const
const CFGStmtMap * getCFGStmtMap()
bool getAddEHEdges() const
static bool isInStdNamespace(const Decl *D)
bool getAddInitializers() const
CFGReverseBlockReachabilityAnalysis * getCFGReachablityAnalysis()
const CFG::BuildOptions & getCFGBuildOptions() const
const ImplicitParamDecl * getSelfDecl() const
ASTContext & getASTContext() const
AnalysisDeclContextManager * getManager() const
llvm::iterator_range< referenced_decls_iterator > getReferencedBlockVars(const BlockDecl *BD)
bool isBodyAutosynthesized() const
CFG * getUnoptimizedCFG()
const StackFrame * getStackFrame(const StackFrame *ParentSF, const void *Data, const Expr *E, const CFGBlock *Blk, unsigned BlockCount, unsigned Index)
Obtain a context of the call stack using its parent context.
AnalysisDeclContext(AnalysisDeclContextManager *Mgr, const Decl *D)
void dumpCFG(bool ShowColors)
CFG::BuildOptions & getCFGBuildOptions()
bool isBodyAutosynthesizedFromModelFile() const
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Represents a single basic block in a source-level CFG.
Represents a top-level expression in a basic block.
llvm::DenseMap< const Stmt *, const CFGBlock * > ForcedBlkExprs
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Decl - This represents one declaration (or definition), e.g.
This represents one expression.
ManagedAnalysis()=default
virtual ~ManagedAnalysis()
void clear()
Discard all previously created StackFrame objects.
const StackFrame * getStackFrame(AnalysisDeclContext *ADC, const StackFrame *ParentSF, const void *Data, const Expr *E, const CFGBlock *Block, unsigned BlockCount, unsigned StmtIdx)
Obtain a context of the call stack using its parent context.
Forward iterator over a chain of StackFrame parents.
std::ptrdiff_t difference_type
std::forward_iterator_tag iterator_category
const StackFrame & reference
const StackFrame * pointer
bool operator!=(const parent_iterator &Other) const
parent_iterator & operator++()
reference operator*() const
const StackFrame value_type
bool operator==(const parent_iterator &Other) const
parent_iterator(const StackFrame *SF)
pointer operator->() const
parent_iterator operator++(int)
parent_iterator()=default
It represents a stack frame of the call stack.
const ParentMap & getParentMap() const
LLVM_DUMP_METHOD void dump() const
StackFrame(AnalysisDeclContext *ADC, const StackFrame *Parent, const void *Data, const Expr *E, const CFGBlock *Block, unsigned BlockCount, unsigned Index, int64_t ID)
LLVM_DUMP_METHOD void dumpStack(raw_ostream &Out) const
Prints out the call stack.
const void * getData() const
bool isParentOf(const StackFrame *SF) const
void Profile(llvm::FoldingSetNodeID &ID)
friend class StackFrameManager
unsigned getIndex() const
LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const
void printJson(raw_ostream &Out, const char *NL="\n", unsigned int Space=0, bool IsDot=false, std::function< void(const StackFrame *)> printMoreInfoPerStackFrame=[](const StackFrame *) {}) const
Prints out the call stack in json format.
const Expr * getCallSite() const
llvm::iterator_range< parent_iterator > parents() const
Iterates over the strict ancestors of this frame, i.e.
CFGElement getCallSiteCFGElement() const
const Decl * getDecl() const
const ImplicitParamDecl * getSelfDecl() const
const StackFrame * getParent() const
It might return null.
const CFGBlock * getCallSiteBlock() const
llvm::iterator_range< parent_iterator > parentsIncludingSelf() const
Iterates over this frame followed by all of its ancestors.
static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ADC, const StackFrame *SF, const void *Data, const Expr *E, const CFGBlock *Block, unsigned BlockCount, unsigned Index)
Stmt - This represents one statement.
Represents a variable declaration or definition.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
@ Other
Other implicit parameter.
int const char * function