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 const CFGBlock *Blk,
unsigned BlockCount,
188 const void *tag = T::getTag();
189 std::unique_ptr<ManagedAnalysis> &data = getAnalysisImpl(tag);
191 data = T::create(*
this);
192 return static_cast<T *
>(data.get());
201 std::unique_ptr<ManagedAnalysis> &getAnalysisImpl(
const void *tag);
223 : Kind(k), Ctx(ctx), Parent(parent), ID(ID) {
232 int64_t
getID()
const {
return ID; }
234 LLVM_ATTRIBUTE_RETURNS_NONNULL
246 template <
typename T> T *
getAnalysis()
const {
return Ctx->getAnalysis<T>(); }
258 virtual void Profile(llvm::FoldingSetNodeID &ID) = 0;
263 LLVM_DUMP_METHOD
void dumpStack(raw_ostream &Out)
const;
277 raw_ostream &Out,
const char *NL =
"\n",
unsigned int Space = 0,
282 LLVM_DUMP_METHOD
void dump()
const;
284 static void ProfileCommon(llvm::FoldingSetNodeID &ID, ContextKind ck,
297 const Expr *CallSite;
305 const unsigned BlockCount;
308 const unsigned Index;
312 unsigned BlockCount,
unsigned Index, int64_t ID)
314 CallSite(E), Block(Block), BlockCount(BlockCount), Index(Index) {}
331 void Profile(llvm::FoldingSetNodeID &ID)
override;
335 const Expr *E,
const CFGBlock *Block,
unsigned BlockCount,
339 ID.AddPointer(Block);
340 ID.AddInteger(BlockCount);
341 ID.AddInteger(Index);
350 llvm::FoldingSet<LocationContext> Contexts;
383 llvm::DenseMap<const Decl *, std::unique_ptr<AnalysisDeclContext>>;
391 std::unique_ptr<CodeInjector> Injector;
399 bool SynthesizeBodies;
403 ASTContext &ASTCtx,
bool useUnoptimizedCFG =
false,
404 bool addImplicitDtors =
false,
bool addInitializers =
false,
405 bool addTemporaryDtors =
false,
bool addLifetime =
false,
406 bool addLoopExit =
false,
bool addScopes =
false,
408 bool addCXXNewAllocator =
true,
bool addRichCXXConstructors =
true,
409 bool markElidedCXXConstructors =
true,
bool addVirtualBaseBranches =
true,
410 std::unique_ptr<CodeInjector> injector =
nullptr);
415 return !cfgBuildOptions.PruneTriviallyFalseEdges;
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 ...
const StackFrame * getStackFrame(const Decl *D)
Obtain the beginning context of the analysis.
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
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()
AnalysisDeclContext(AnalysisDeclContextManager *Mgr, const Decl *D)
void dumpCFG(bool ShowColors)
const StackFrame * getStackFrame(LocationContext const *ParentLC, const void *Data, const Expr *E, const CFGBlock *Blk, unsigned BlockCount, unsigned Index)
Obtain a context of the call stack using its parent context.
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.
~LocationContextManager()
const StackFrame * getStackFrame(AnalysisDeclContext *ADC, const LocationContext *ParentLC, const void *Data, const Expr *E, const CFGBlock *Block, unsigned BlockCount, unsigned StmtIdx)
Obtain a context of the call stack using its parent context.
void clear()
Discard all previously created LocationContext objects.
bool isParentOf(const LocationContext *LC) const
const Decl * getDecl() const
LocationContext(ContextKind k, AnalysisDeclContext *ctx, const LocationContext *parent, int64_t ID)
const ParentMap & getParentMap() const
LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const
static void ProfileCommon(llvm::FoldingSetNodeID &ID, ContextKind ck, AnalysisDeclContext *ctx, const LocationContext *parent, const void *data)
const LocationContext * getParent() const
It might return null.
const StackFrame * getStackFrame() const
LLVM_DUMP_METHOD void dumpStack(raw_ostream &Out) const
Prints out the call stack.
LLVM_DUMP_METHOD void dump() const
virtual void Profile(llvm::FoldingSetNodeID &ID)=0
virtual bool inTopFrame() const
virtual ~LocationContext()
const ImplicitParamDecl * getSelfDecl() const
void printJson(raw_ostream &Out, const char *NL="\n", unsigned int Space=0, bool IsDot=false, std::function< void(const LocationContext *)> printMoreInfoPerContext=[](const LocationContext *) {}) const
Prints out the call stack in json format.
ContextKind getKind() const
ManagedAnalysis()=default
virtual ~ManagedAnalysis()
It represents a stack frame of the call stack (based on CallEvent).
static bool classof(const LocationContext *LC)
const void * getData() const
bool inTopFrame() const override
static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ADC, const LocationContext *ParentLC, const void *Data, const Expr *E, const CFGBlock *Block, unsigned BlockCount, unsigned Index)
void Profile(llvm::FoldingSetNodeID &ID) override
friend class LocationContextManager
unsigned getIndex() const
const Expr * getCallSite() const
CFGElement getCallSiteCFGElement() const
~StackFrame() override=default
const CFGBlock * getCallSiteBlock() const
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