17#ifndef LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H
18#define LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H
25#include "llvm/ADT/DenseMap.h"
26#include "llvm/ADT/FoldingSet.h"
27#include "llvm/ADT/StringRef.h"
28#include "llvm/ADT/iterator_range.h"
29#include "llvm/Support/Allocator.h"
35class AnalysisDeclContextManager;
38class BlockInvocationContext;
39class CFGReverseBlockReachabilityAnalysis;
41class ImplicitParamDecl;
43class LocationContextManager;
45class StackFrameContext;
79 std::unique_ptr<CFG> cfg, completeCFG;
80 std::unique_ptr<CFGStmtMap> cfgStmtMap;
85 bool builtCFG =
false;
86 bool builtCompleteCFG =
false;
87 std::unique_ptr<ParentMap> PM;
88 std::unique_ptr<CFGReverseBlockReachabilityAnalysis> CFA;
90 llvm::BumpPtrAllocator A;
92 llvm::DenseMap<const BlockDecl *, void *> *ReferencedBlockVars =
nullptr;
94 void *ManagedAnalyses =
nullptr;
113 return cfgBuildOptions;
173 llvm::iterator_range<referenced_decls_iterator>
183 unsigned BlockCount,
unsigned Index);
193 const void *tag = T::getTag();
194 std::unique_ptr<ManagedAnalysis> &data = getAnalysisImpl(tag);
196 data = T::create(*
this);
197 return static_cast<T *
>(data.get());
206 std::unique_ptr<ManagedAnalysis> &getAnalysisImpl(
const void *tag);
232 : Kind(k), Ctx(ctx),
Parent(parent), ID(ID) {
241 int64_t
getID()
const {
return ID; }
243 LLVM_ATTRIBUTE_RETURNS_NONNULL
267 virtual void Profile(llvm::FoldingSetNodeID &ID) = 0;
272 LLVM_DUMP_METHOD
void dumpStack(raw_ostream &Out)
const;
286 raw_ostream &Out,
const char *NL =
"\n",
unsigned int Space = 0,
291 LLVM_DUMP_METHOD
void dump()
const;
303 const Stmt *CallSite;
311 const unsigned BlockCount;
314 const unsigned Index;
318 unsigned Index, int64_t
ID)
320 Block(
Block), BlockCount(BlockCount), Index(Index) {}
335 void Profile(llvm::FoldingSetNodeID &
ID)
override;
343 ID.AddInteger(BlockCount);
344 ID.AddInteger(Index);
363 const void *
Data, int64_t
ID)
373 void Profile(llvm::FoldingSetNodeID &
ID)
override;
388 llvm::FoldingSet<LocationContext> Contexts;
408 unsigned BlockCount,
unsigned Index);
427 llvm::DenseMap<const Decl *, std::unique_ptr<AnalysisDeclContext>>;
435 std::unique_ptr<CodeInjector> Injector;
443 bool SynthesizeBodies;
447 ASTContext &ASTCtx,
bool useUnoptimizedCFG =
false,
448 bool addImplicitDtors =
false,
bool addInitializers =
false,
449 bool addTemporaryDtors =
false,
bool addLifetime =
false,
450 bool addLoopExit =
false,
bool addScopes =
false,
452 bool addCXXNewAllocator =
true,
bool addRichCXXConstructors =
true,
453 bool markElidedCXXConstructors =
true,
bool addVirtualBaseBranches =
true,
479 unsigned BlockCount,
unsigned Index) {
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 ...
bool synthesizeBodies() const
CFG::BuildOptions & getCFGBuildOptions()
void clear()
Discard all previously created AnalysisDeclContexts.
AnalysisDeclContext * getContext(const Decl *D)
const StackFrameContext * getStackFrame(const Decl *D)
Obtain the beginning context of the analysis.
bool getUseUnoptimizedCFG() const
const StackFrameContext * getStackFrame(AnalysisDeclContext *ADC, const LocationContext *Parent, const Stmt *S, const CFGBlock *Block, unsigned BlockCount, unsigned Index)
Obtain a context of the call stack using its parent context.
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 BlockInvocationContext * getBlockInvocationContext(const LocationContext *ParentLC, const BlockDecl *BD, const void *Data)
Obtain a context of the block invocation using its parent context.
CFGStmtMap * getCFGStmtMap()
const CFGBlock * getBlockForRegisteredExpression(const Stmt *stmt)
bool getUseUnoptimizedCFG() const
ParentMap & getParentMap()
const VarDecl *const * referenced_decls_iterator
const Decl * getDecl() const
bool getAddImplicitDtors() const
bool getAddEHEdges() const
static bool isInStdNamespace(const Decl *D)
bool getAddInitializers() const
CFGReverseBlockReachabilityAnalysis * getCFGReachablityAnalysis()
const CFG::BuildOptions & getCFGBuildOptions() const
const ImplicitParamDecl * getSelfDecl() const
const StackFrameContext * getStackFrame(LocationContext const *ParentLC, const Stmt *S, const CFGBlock *Blk, unsigned BlockCount, unsigned Index)
Obtain a context of the call stack using its parent context.
ASTContext & getASTContext() const
AnalysisDeclContextManager * getManager() const
llvm::iterator_range< referenced_decls_iterator > getReferencedBlockVars(const BlockDecl *BD)
bool isBodyAutosynthesized() const
CFG * getUnoptimizedCFG()
void dumpCFG(bool ShowColors)
CFG::BuildOptions & getCFGBuildOptions()
bool isBodyAutosynthesizedFromModelFile() const
Represents a block literal declaration, which is like an unnamed FunctionDecl.
It represents a block invocation (based on BlockCall).
void Profile(llvm::FoldingSetNodeID &ID) override
static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ADC, const LocationContext *ParentLC, const BlockDecl *BD, const void *Data)
const BlockDecl * getBlockDecl() const
~BlockInvocationContext() override=default
static bool classof(const LocationContext *LC)
const void * getData() const
Represents a single basic block in a source-level CFG.
Represents a top-level expression in a basic block.
bool PruneTriviallyFalseEdges
llvm::DenseMap< const Stmt *, const CFGBlock * > ForcedBlkExprs
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
CodeInjector is an interface which is responsible for injecting AST of function definitions that may ...
Decl - This represents one declaration (or definition), e.g.
~LocationContextManager()
const StackFrameContext * getStackFrame(AnalysisDeclContext *ADC, const LocationContext *ParentLC, const Stmt *S, const CFGBlock *Block, unsigned BlockCount, unsigned Index)
Obtain a context of the call stack using its parent context.
void clear()
Discard all previously created LocationContext objects.
const BlockInvocationContext * getBlockInvocationContext(AnalysisDeclContext *ADC, const LocationContext *ParentLC, const BlockDecl *BD, const void *Data)
Obtain a context of the block invocation using its parent context.
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
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.
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
const StackFrameContext * getStackFrame() const
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
The base class of a hierarchy of objects representing analyses tied to AnalysisDeclContext.
ManagedAnalysis()=default
virtual ~ManagedAnalysis()
It represents a stack frame of the call stack (based on CallEvent).
void Profile(llvm::FoldingSetNodeID &ID) override
unsigned getIndex() const
~StackFrameContext() override=default
CFGElement getCallSiteCFGElement() const
static bool classof(const LocationContext *LC)
const Stmt * getCallSite() const
static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ADC, const LocationContext *ParentLC, const Stmt *S, const CFGBlock *Block, unsigned BlockCount, unsigned Index)
const CFGBlock * getCallSiteBlock() const
bool inTopFrame() const override
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