15 #ifndef LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H 16 #define LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H 22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/ADT/FoldingSet.h" 24 #include "llvm/Support/Allocator.h" 30 class CFGReverseBlockReachabilityAnalysis;
33 class ManagedAnalysis;
35 class PseudoConstantAnalysis;
36 class LocationContextManager;
37 class StackFrameContext;
38 class BlockInvocationContext;
39 class AnalysisDeclContextManager;
40 class LocationContext;
42 namespace idx {
class TranslationUnit; }
74 std::unique_ptr<CFG> cfg, completeCFG;
75 std::unique_ptr<CFGStmtMap> cfgStmtMap;
80 bool builtCFG, builtCompleteCFG;
81 std::unique_ptr<ParentMap> PM;
82 std::unique_ptr<PseudoConstantAnalysis> PCA;
83 std::unique_ptr<CFGReverseBlockReachabilityAnalysis> CFA;
85 llvm::BumpPtrAllocator A;
87 llvm::DenseMap<const BlockDecl*,void*> *ReferencedBlockVars;
89 void *ManagedAnalyses;
112 return cfgBuildOptions;
116 return cfgBuildOptions;
130 void registerForcedBlockExpression(
const Stmt *
stmt);
131 const CFGBlock *getBlockForRegisteredExpression(
const Stmt *stmt);
134 Stmt *getBody()
const;
139 Stmt *getBody(
bool &IsAutosynthesized)
const;
146 bool isBodyAutosynthesized()
const;
154 bool isBodyAutosynthesizedFromModelFile()
const;
163 CFG *getUnoptimizedCFG();
165 void dumpCFG(
bool ShowColors);
177 llvm::iterator_range<referenced_decls_iterator>
178 getReferencedBlockVars(
const BlockDecl *BD);
192 const void *ContextData);
196 template <
typename T>
198 const void *tag = T::getTag();
203 return static_cast<T*
>(data);
208 static bool isInStdNamespace(
const Decl *D);
231 : Kind(k), Ctx(ctx), Parent(parent) {}
244 const Decl *
getDecl()
const {
return getAnalysisDeclContext()->getDecl(); }
246 CFG *
getCFG()
const {
return getAnalysisDeclContext()->getCFG(); }
248 template <
typename T>
250 return getAnalysisDeclContext()->getAnalysis<
T>();
254 return getAnalysisDeclContext()->getParentMap();
264 virtual bool inTopFrame()
const;
266 virtual void Profile(llvm::FoldingSetNodeID &
ID) = 0;
268 void dumpStack(raw_ostream &OS, StringRef Indent =
"")
const;
269 void dumpStack()
const;
272 static void ProfileCommon(llvm::FoldingSetNodeID &ID,
281 const Stmt *CallSite;
294 Block(blk), Index(idx) {}
304 bool inTopFrame()
const override {
return getParent() ==
nullptr; }
308 void Profile(llvm::FoldingSetNodeID &
ID)
override;
312 const CFGBlock *blk,
unsigned idx) {
313 ProfileCommon(ID, StackFrame, ctx, parent, s);
319 return Ctx->
getKind() == StackFrame;
334 void Profile(llvm::FoldingSetNodeID &
ID)
override;
338 ProfileCommon(ID,
Scope, ctx, parent, s);
350 const void *ContextData;
356 const BlockDecl *bd,
const void *contextData)
357 :
LocationContext(Block, ctx, parent), BD(bd), ContextData(contextData) {}
366 void Profile(llvm::FoldingSetNodeID &
ID)
override;
370 const void *contextData) {
371 ProfileCommon(ID, Block, ctx, parent, bd);
372 ID.AddPointer(contextData);
376 return Ctx->
getKind() == Block;
381 llvm::FoldingSet<LocationContext> Contexts;
398 const void *ContextData);
403 template <
typename LOC,
typename DATA>
410 typedef llvm::DenseMap<const Decl *, std::unique_ptr<AnalysisDeclContext>>
419 std::unique_ptr<CodeInjector> Injector;
427 bool SynthesizeBodies;
431 bool addImplicitDtors =
false,
432 bool addInitializers =
false,
433 bool addTemporaryDtors =
false,
434 bool addLifetime =
false,
bool addLoopExit =
false,
435 bool synthesizeBodies =
false,
436 bool addStaticInitBranches =
false,
437 bool addCXXNewAllocator =
true,
447 return cfgBuildOptions;
464 return LocContexts.
getStackFrame(getContext(D),
nullptr,
nullptr,
nullptr,
474 return LocContexts.
getStackFrame(getContext(D), Parent, S, Blk, Idx);
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.
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.
VarDecl - An instance of this class is created to represent 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
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
CFGBlock - Represents a single basic block in a source-level CFG.
static bool classof(const LocationContext *Ctx)
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
CFG - Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
const FunctionProtoType * T
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.
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
bool getUseUnoptimizedCFG() const
~StackFrameContext() override
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
const VarDecl *const * referenced_decls_iterator
LocationContext(ContextKind k, AnalysisDeclContext *ctx, const LocationContext *parent)
AnalysisDeclContext * getAnalysisDeclContext() const
~BlockInvocationContext() override