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"
77 std::unique_ptr<CFG> cfg, completeCFG;
78 std::optional<CFGStmtMap> cfgStmtMap;
83 bool builtCFG =
false;
84 bool builtCompleteCFG =
false;
85 std::unique_ptr<ParentMap> PM;
86 std::unique_ptr<CFGReverseBlockReachabilityAnalysis> CFA;
88 llvm::BumpPtrAllocator A;
90 llvm::DenseMap<const BlockDecl *, void *> *ReferencedBlockVars =
nullptr;
92 void *ManagedAnalyses =
nullptr;
111 return cfgBuildOptions;
119 return !cfgBuildOptions.PruneTriviallyFalseEdges;
171 llvm::iterator_range<referenced_decls_iterator>
181 unsigned BlockCount,
unsigned Index);
186 const void *tag = T::getTag();
187 std::unique_ptr<ManagedAnalysis> &data = getAnalysisImpl(tag);
189 data = T::create(*
this);
190 return static_cast<T *
>(data.get());
199 std::unique_ptr<ManagedAnalysis> &getAnalysisImpl(
const void *tag);
220 const Expr *CallSite;
228 const unsigned BlockCount;
231 const unsigned Index;
236 unsigned BlockCount,
unsigned Index, int64_t ID)
237 : Ctx(ADC), Parent(Parent), ID(ID), Data(Data), CallSite(E), Block(Block),
238 BlockCount(BlockCount), Index(Index) {
244 LLVM_ATTRIBUTE_RETURNS_NONNULL
250 int64_t
getID()
const {
return ID; }
258 template <
typename T> T *
getAnalysis()
const {
return Ctx->getAnalysis<T>(); }
290 raw_ostream &Out,
const char *NL =
"\n",
unsigned int Space = 0,
298 LLVM_DUMP_METHOD
void dumpStack(raw_ostream &Out)
const;
300 LLVM_DUMP_METHOD
void dump()
const;
302 void Profile(llvm::FoldingSetNodeID &ID);
306 const CFGBlock *Block,
unsigned BlockCount,
312 ID.AddPointer(Block);
313 ID.AddInteger(BlockCount);
314 ID.AddInteger(Index);
319 llvm::FoldingSet<StackFrame> Frames;
343 unsigned BlockCount,
unsigned StmtIdx);
351 llvm::DenseMap<const Decl *, std::unique_ptr<AnalysisDeclContext>>;
359 std::unique_ptr<CodeInjector> Injector;
367 bool SynthesizeBodies;
371 ASTContext &ASTCtx,
bool useUnoptimizedCFG =
false,
372 bool addImplicitDtors =
false,
bool addInitializers =
false,
373 bool addTemporaryDtors =
false,
bool addLifetime =
false,
374 bool addLoopExit =
false,
bool addScopes =
false,
376 bool addCXXNewAllocator =
true,
bool addRichCXXConstructors =
true,
377 bool markElidedCXXConstructors =
true,
bool addVirtualBaseBranches =
true,
378 std::unique_ptr<CodeInjector> injector =
nullptr);
383 return !cfgBuildOptions.PruneTriviallyFalseEdges;
395 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.
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
CFGElement getCallSiteCFGElement() const
const Decl * getDecl() const
const ImplicitParamDecl * getSelfDecl() const
const StackFrame * getParent() const
It might return null.
const CFGBlock * getCallSiteBlock() const
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.
int const char * function