14 #ifndef LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H 15 #define LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H 22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/ADT/FoldingSet.h" 24 #include "llvm/ADT/StringRef.h" 25 #include "llvm/ADT/iterator_range.h" 26 #include "llvm/Support/Allocator.h" 32 class AnalysisDeclContextManager;
35 class BlockInvocationContext;
36 class CFGReverseBlockReachabilityAnalysis;
38 class ImplicitParamDecl;
39 class LocationContext;
40 class LocationContextManager;
42 class StackFrameContext;
76 std::unique_ptr<CFG> cfg, completeCFG;
77 std::unique_ptr<CFGStmtMap> cfgStmtMap;
82 bool builtCFG =
false;
83 bool builtCompleteCFG =
false;
84 std::unique_ptr<ParentMap> PM;
85 std::unique_ptr<CFGReverseBlockReachabilityAnalysis> CFA;
87 llvm::BumpPtrAllocator A;
89 llvm::DenseMap<const BlockDecl *,void *> *ReferencedBlockVars =
nullptr;
91 void *ManagedAnalyses =
nullptr;
114 return cfgBuildOptions;
118 return cfgBuildOptions;
132 void registerForcedBlockExpression(
const Stmt *
stmt);
133 const CFGBlock *getBlockForRegisteredExpression(
const Stmt *stmt);
136 Stmt *getBody()
const;
141 Stmt *getBody(
bool &IsAutosynthesized)
const;
148 bool isBodyAutosynthesized()
const;
156 bool isBodyAutosynthesizedFromModelFile()
const;
165 CFG *getUnoptimizedCFG();
167 void dumpCFG(
bool ShowColors);
178 llvm::iterator_range<referenced_decls_iterator>
179 getReferencedBlockVars(
const BlockDecl *BD);
187 unsigned BlockCount,
unsigned Idx);
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);
234 : Kind(k), Ctx(ctx), Parent(parent), ID(ID) {}
251 const Decl *
getDecl()
const {
return getAnalysisDeclContext()->getDecl(); }
253 CFG *
getCFG()
const {
return getAnalysisDeclContext()->getCFG(); }
255 template <
typename T>
257 return getAnalysisDeclContext()->getAnalysis<T>();
261 return getAnalysisDeclContext()->getParentMap();
271 virtual bool inTopFrame()
const;
273 virtual void Profile(llvm::FoldingSetNodeID &ID) = 0;
276 raw_ostream &Out,
const char *NL =
"\n",
281 raw_ostream &Out,
const char *NL =
"\n",
unsigned int Space = 0,
289 static void ProfileCommon(llvm::FoldingSetNodeID &ID,
300 const Stmt *CallSite;
308 const unsigned BlockCount;
311 const unsigned Index;
314 const Stmt *s,
const CFGBlock *blk,
unsigned blockCount,
315 unsigned idx, int64_t
ID)
316 :
LocationContext(StackFrame, ctx, parent, ID), CallSite(s), Block(blk),
317 BlockCount(blockCount), Index(idx) {}
327 bool inTopFrame()
const override {
return getParent() ==
nullptr; }
331 void Profile(llvm::FoldingSetNodeID &
ID)
override;
335 const CFGBlock *blk,
unsigned blockCount,
unsigned idx) {
336 ProfileCommon(ID, StackFrame, ctx, parent, s);
338 ID.AddInteger(blockCount);
343 return Ctx->
getKind() == StackFrame;
353 const Stmt *s, int64_t
ID)
359 void Profile(llvm::FoldingSetNodeID &
ID)
override;
363 ProfileCommon(ID,
Scope, ctx, parent, s);
377 const void *ContextData;
381 const void *contextData, int64_t
ID)
383 ContextData(contextData) {}
392 void Profile(llvm::FoldingSetNodeID &
ID)
override;
396 const void *contextData) {
397 ProfileCommon(ID, Block, ctx, parent, bd);
398 ID.AddPointer(contextData);
402 return Ctx->
getKind() == Block;
407 llvm::FoldingSet<LocationContext> Contexts;
418 unsigned blockCount,
unsigned idx);
428 const void *ContextData);
433 template <
typename LOC,
typename DATA>
441 llvm::DenseMap<const Decl *, std::unique_ptr<AnalysisDeclContext>>;
449 std::unique_ptr<CodeInjector> Injector;
457 bool SynthesizeBodies;
461 bool addImplicitDtors =
false,
462 bool addInitializers =
false,
463 bool addTemporaryDtors =
false,
464 bool addLifetime =
false,
465 bool addLoopExit =
false,
466 bool addScopes =
false,
467 bool synthesizeBodies =
false,
468 bool addStaticInitBranches =
false,
469 bool addCXXNewAllocator =
true,
470 bool addRichCXXConstructors =
true,
471 bool markElidedCXXConstructors =
true,
472 bool addVirtualBaseBranches =
true,
482 return cfgBuildOptions;
492 unsigned BlockCount,
unsigned Idx) {
493 return LocContexts.
getStackFrame(Ctx, Parent, S, Blk, BlockCount, Idx);
498 return LocContexts.
getStackFrame(getContext(D),
nullptr,
nullptr,
nullptr,
506 unsigned BlockCount,
unsigned Idx) {
507 return LocContexts.
getStackFrame(getContext(D), Parent, S, Blk, BlockCount,
527 #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.
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.
const StackFrameContext * getStackFrame(AnalysisDeclContext *Ctx, const LocationContext *Parent, const Stmt *S, const CFGBlock *Blk, unsigned BlockCount, unsigned Idx)
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
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
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.
StackFrameContext const * getStackFrame(const Decl *D, const LocationContext *Parent, const Stmt *S, const CFGBlock *Blk, unsigned BlockCount, unsigned Idx)
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 Stmt * getCallSite() const
Represents a single basic block in a source-level CFG.
static bool classof(const LocationContext *Ctx)
Represents a block literal declaration, which is like an unnamed FunctionDecl.
const StackFrameContext * getStackFrame(AnalysisDeclContext *ctx, const LocationContext *parent, const Stmt *s, const CFGBlock *blk, unsigned blockCount, unsigned idx)
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
const CFG::BuildOptions & getCFGBuildOptions() const
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 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
static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx, const LocationContext *parent, const Stmt *s, const CFGBlock *blk, unsigned blockCount, unsigned idx)
unsigned getIndex() const
const ParentMap & getParentMap() const
AnalysisDeclContext * getAnalysisDeclContext() const