15 #ifndef LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H 16 #define LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H 23 #include "llvm/ADT/DenseMap.h" 24 #include "llvm/ADT/FoldingSet.h" 25 #include "llvm/ADT/StringRef.h" 26 #include "llvm/ADT/iterator_range.h" 27 #include "llvm/Support/Allocator.h" 33 class AnalysisDeclContextManager;
36 class BlockInvocationContext;
37 class CFGReverseBlockReachabilityAnalysis;
39 class ImplicitParamDecl;
40 class LocationContext;
41 class LocationContextManager;
43 class StackFrameContext;
77 std::unique_ptr<CFG> cfg, completeCFG;
78 std::unique_ptr<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;
115 return cfgBuildOptions;
119 return cfgBuildOptions;
133 void registerForcedBlockExpression(
const Stmt *
stmt);
134 const CFGBlock *getBlockForRegisteredExpression(
const Stmt *stmt);
137 Stmt *getBody()
const;
142 Stmt *getBody(
bool &IsAutosynthesized)
const;
149 bool isBodyAutosynthesized()
const;
157 bool isBodyAutosynthesizedFromModelFile()
const;
166 CFG *getUnoptimizedCFG();
168 void dumpCFG(
bool ShowColors);
179 llvm::iterator_range<referenced_decls_iterator>
180 getReferencedBlockVars(
const BlockDecl *BD);
194 const void *ContextData);
198 template <
typename T>
200 const void *tag = T::getTag();
205 return static_cast<T *
>(data);
210 static bool isInStdNamespace(
const Decl *D);
236 : Kind(k), Ctx(ctx), Parent(parent), ID(ID) {}
253 const Decl *
getDecl()
const {
return getAnalysisDeclContext()->getDecl(); }
255 CFG *
getCFG()
const {
return getAnalysisDeclContext()->getCFG(); }
257 template <
typename T>
259 return getAnalysisDeclContext()->getAnalysis<T>();
263 return getAnalysisDeclContext()->getParentMap();
273 virtual bool inTopFrame()
const;
275 virtual void Profile(llvm::FoldingSetNodeID &ID) = 0;
278 raw_ostream &OS, StringRef Indent = {},
const char *NL =
"\n",
279 const char *Sep =
"",
280 std::function<void(const LocationContext *)> printMoreInfoPerContext =
282 void dumpStack()
const;
285 static void ProfileCommon(llvm::FoldingSetNodeID &ID,
296 const Stmt *CallSite;
309 Block(blk), Index(idx) {}
319 bool inTopFrame()
const override {
return getParent() ==
nullptr; }
323 void Profile(llvm::FoldingSetNodeID &
ID)
override;
327 const CFGBlock *blk,
unsigned idx) {
328 ProfileCommon(ID, StackFrame, ctx, parent, s);
334 return Ctx->
getKind() == StackFrame;
344 const Stmt *s, int64_t
ID)
350 void Profile(llvm::FoldingSetNodeID &
ID)
override;
354 ProfileCommon(ID,
Scope, ctx, parent, s);
368 const void *ContextData;
372 const void *contextData, int64_t
ID)
374 ContextData(contextData) {}
383 void Profile(llvm::FoldingSetNodeID &
ID)
override;
387 const void *contextData) {
388 ProfileCommon(ID, Block, ctx, parent, bd);
389 ID.AddPointer(contextData);
393 return Ctx->
getKind() == Block;
398 llvm::FoldingSet<LocationContext> Contexts;
419 const void *ContextData);
424 template <
typename LOC,
typename DATA>
432 llvm::DenseMap<const Decl *, std::unique_ptr<AnalysisDeclContext>>;
440 std::unique_ptr<CodeInjector> Injector;
448 bool SynthesizeBodies;
452 bool addImplicitDtors =
false,
453 bool addInitializers =
false,
454 bool addTemporaryDtors =
false,
455 bool addLifetime =
false,
456 bool addLoopExit =
false,
457 bool addScopes =
false,
458 bool synthesizeBodies =
false,
459 bool addStaticInitBranches =
false,
460 bool addCXXNewAllocator =
true,
461 bool addRichCXXConstructors =
true,
462 bool markElidedCXXConstructors =
true,
472 return cfgBuildOptions;
489 return LocContexts.
getStackFrame(getContext(D),
nullptr,
nullptr,
nullptr,
499 return LocContexts.
getStackFrame(getContext(D), Parent, S, Blk, Idx);
518 #endif // LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H
static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx, const LocationContext *parent, const Stmt *s)
The base class of a hierarchy of objects representing analyses tied to AnalysisDeclContext.
static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx, const LocationContext *parent, const Stmt *s, const CFGBlock *blk, unsigned idx)
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
const VarDecl *const * referenced_decls_iterator
Stmt - This represents one statement.
const BlockDecl * getBlockDecl() const
Decl - This represents one declaration (or definition), e.g.
bool getAddEHEdges() const
getAddEHEdges - Return true iff we are adding exceptional edges from callExprs.
Represents a variable declaration or definition.
ASTContext & getASTContext() const
bool synthesizeBodies() const
Return true if faux bodies should be synthesized for well-known functions.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Defines the clang::CodeInjector interface which is responsible for injecting AST of function definiti...
AnalysisDeclContext contains the context data for the function or method under analysis.
static bool classof(const LocationContext *Ctx)
const ImplicitParamDecl * getSelfDecl() const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
T * getAnalysis()
Return the specified analysis object, lazily running the analysis if necessary.
const LocationContext * getParent() const
Scope - A scope is a transient data structure that is used while parsing the program.
llvm::DenseMap< const Stmt *, const CFGBlock * > ForcedBlkExprs
const CFGBlock * getCallSiteBlock() const
const StackFrameContext * getStackFrame(AnalysisDeclContext *Ctx, LocationContext const *Parent, const Stmt *S, const CFGBlock *Blk, unsigned Idx)
const Stmt * getCallSite() const
Represents a single basic block in a source-level CFG.
static bool classof(const LocationContext *Ctx)
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
const CFG::BuildOptions & getCFGBuildOptions() const
StackFrameContext const * getStackFrame(const Decl *D, LocationContext const *Parent, const Stmt *S, const CFGBlock *Blk, unsigned Idx)
bool inTopFrame() const override
Return true if the current LocationContext has no caller context.
ManagedAnalysis()=default
LocationContext(ContextKind k, AnalysisDeclContext *ctx, const LocationContext *parent, int64_t ID)
bool getUseUnoptimizedCFG() const
CFG::BuildOptions & getCFGBuildOptions()
const StackFrameContext * getStackFrame(AnalysisDeclContext *ctx, const LocationContext *parent, const Stmt *s, const CFGBlock *blk, unsigned idx)
ParentMap & getParentMap() const
const ImplicitParamDecl * getSelfDecl() const
Return the ImplicitParamDecl* associated with 'self' if this AnalysisDeclContext wraps an ObjCMethodD...
ASTContext & getASTContext() const LLVM_READONLY
bool PruneTriviallyFalseEdges
static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx, const LocationContext *parent, const BlockDecl *bd, const void *contextData)
const void * getContextData() const
bool isCFGBuilt() const
Returns true if we have built a CFG for this analysis context.
const Decl * getDecl() const
virtual ~ManagedAnalysis()
bool getUseUnoptimizedCFG() const
Dataflow Directional Tag Classes.
CFG::BuildOptions & getCFGBuildOptions()
Return the build options used to construct the CFG.
AnalysisDeclContextManager * getManager() const
Return the AnalysisDeclContextManager (if any) that created this AnalysisDeclContext.
bool getAddInitializers() const
CodeInjector is an interface which is responsible for injecting AST of function definitions that may ...
bool getAddImplicitDtors() const
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
static bool classof(const LocationContext *Ctx)
const StackFrameContext * getStackFrame(const Decl *D)
ContextKind getKind() const
const Decl * getDecl() const
unsigned getIndex() const
AnalysisDeclContext * getAnalysisDeclContext() const