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 PseudoConstantAnalysis;
44 class StackFrameContext;
78 std::unique_ptr<CFG> cfg, completeCFG;
79 std::unique_ptr<CFGStmtMap> cfgStmtMap;
84 bool builtCFG =
false;
85 bool builtCompleteCFG =
false;
86 std::unique_ptr<ParentMap> PM;
87 std::unique_ptr<PseudoConstantAnalysis> PCA;
88 std::unique_ptr<CFGReverseBlockReachabilityAnalysis> CFA;
90 llvm::BumpPtrAllocator A;
92 llvm::DenseMap<const BlockDecl *,void *> *ReferencedBlockVars =
nullptr;
94 void *ManagedAnalyses =
nullptr;
117 return cfgBuildOptions;
121 return cfgBuildOptions;
135 void registerForcedBlockExpression(
const Stmt *
stmt);
136 const CFGBlock *getBlockForRegisteredExpression(
const Stmt *stmt);
139 Stmt *getBody()
const;
144 Stmt *getBody(
bool &IsAutosynthesized)
const;
151 bool isBodyAutosynthesized()
const;
159 bool isBodyAutosynthesizedFromModelFile()
const;
168 CFG *getUnoptimizedCFG();
170 void dumpCFG(
bool ShowColors);
182 llvm::iterator_range<referenced_decls_iterator>
183 getReferencedBlockVars(
const BlockDecl *BD);
197 const void *ContextData);
201 template <
typename T>
203 const void *tag = T::getTag();
208 return static_cast<T *
>(data);
213 static bool isInStdNamespace(
const Decl *D);
237 : Kind(k), Ctx(ctx), Parent(parent) {}
250 const Decl *
getDecl()
const {
return getAnalysisDeclContext()->getDecl(); }
252 CFG *
getCFG()
const {
return getAnalysisDeclContext()->getCFG(); }
254 template <
typename T>
256 return getAnalysisDeclContext()->getAnalysis<T>();
260 return getAnalysisDeclContext()->getParentMap();
270 virtual bool inTopFrame()
const;
272 virtual void Profile(llvm::FoldingSetNodeID &
ID) = 0;
275 raw_ostream &OS, StringRef Indent = {},
const char *NL =
"\n",
276 const char *Sep =
"",
277 std::function<void(const LocationContext *)> printMoreInfoPerContext =
279 void dumpStack()
const;
282 static void ProfileCommon(llvm::FoldingSetNodeID &ID,
293 const Stmt *CallSite;
305 Block(blk), Index(idx) {}
315 bool inTopFrame()
const override {
return getParent() ==
nullptr; }
319 void Profile(llvm::FoldingSetNodeID &
ID)
override;
323 const CFGBlock *blk,
unsigned idx) {
324 ProfileCommon(ID, StackFrame, ctx, parent, s);
330 return Ctx->
getKind() == StackFrame;
346 void Profile(llvm::FoldingSetNodeID &
ID)
override;
350 ProfileCommon(ID,
Scope, ctx, parent, s);
364 const void *ContextData;
368 const BlockDecl *bd,
const void *contextData)
369 :
LocationContext(Block, ctx, parent), BD(bd), ContextData(contextData) {}
378 void Profile(llvm::FoldingSetNodeID &
ID)
override;
382 const void *contextData) {
383 ProfileCommon(ID, Block, ctx, parent, bd);
384 ID.AddPointer(contextData);
388 return Ctx->
getKind() == Block;
393 llvm::FoldingSet<LocationContext> Contexts;
411 const void *ContextData);
416 template <
typename LOC,
typename DATA>
424 llvm::DenseMap<const Decl *, std::unique_ptr<AnalysisDeclContext>>;
432 std::unique_ptr<CodeInjector> Injector;
440 bool SynthesizeBodies;
444 bool addImplicitDtors =
false,
445 bool addInitializers =
false,
446 bool addTemporaryDtors =
false,
447 bool addLifetime =
false,
448 bool addLoopExit =
false,
449 bool addScopes =
false,
450 bool synthesizeBodies =
false,
451 bool addStaticInitBranches =
false,
452 bool addCXXNewAllocator =
true,
453 bool addRichCXXConstructors =
true,
454 bool markElidedCXXConstructors =
true,
464 return cfgBuildOptions;
481 return LocContexts.
getStackFrame(getContext(D),
nullptr,
nullptr,
nullptr,
491 return LocContexts.
getStackFrame(getContext(D), Parent, S, Blk, Idx);
510 #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
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
LocationContext(ContextKind k, AnalysisDeclContext *ctx, const LocationContext *parent)
AnalysisDeclContext * getAnalysisDeclContext() const