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);
193 const void *ContextData);
197 template <
typename T>
199 const void *tag = T::getTag();
204 return static_cast<T *
>(data);
209 static bool isInStdNamespace(
const Decl *D);
235 : Kind(k), Ctx(ctx), Parent(parent), ID(ID) {}
252 const Decl *
getDecl()
const {
return getAnalysisDeclContext()->getDecl(); }
254 CFG *
getCFG()
const {
return getAnalysisDeclContext()->getCFG(); }
256 template <
typename T>
258 return getAnalysisDeclContext()->getAnalysis<T>();
262 return getAnalysisDeclContext()->getParentMap();
272 virtual bool inTopFrame()
const;
274 virtual void Profile(llvm::FoldingSetNodeID &ID) = 0;
277 raw_ostream &Out,
const char *NL =
"\n",
282 raw_ostream &Out,
const char *NL =
"\n",
unsigned int Space = 0,
290 static void ProfileCommon(llvm::FoldingSetNodeID &ID,
301 const Stmt *CallSite;
314 Block(blk), Index(idx) {}
324 bool inTopFrame()
const override {
return getParent() ==
nullptr; }
328 void Profile(llvm::FoldingSetNodeID &
ID)
override;
332 const CFGBlock *blk,
unsigned idx) {
333 ProfileCommon(ID, StackFrame, ctx, parent, s);
339 return Ctx->
getKind() == StackFrame;
349 const Stmt *s, int64_t
ID)
355 void Profile(llvm::FoldingSetNodeID &
ID)
override;
359 ProfileCommon(ID,
Scope, ctx, parent, s);
373 const void *ContextData;
377 const void *contextData, int64_t
ID)
379 ContextData(contextData) {}
388 void Profile(llvm::FoldingSetNodeID &
ID)
override;
392 const void *contextData) {
393 ProfileCommon(ID, Block, ctx, parent, bd);
394 ID.AddPointer(contextData);
398 return Ctx->
getKind() == Block;
403 llvm::FoldingSet<LocationContext> Contexts;
424 const void *ContextData);
429 template <
typename LOC,
typename DATA>
437 llvm::DenseMap<const Decl *, std::unique_ptr<AnalysisDeclContext>>;
445 std::unique_ptr<CodeInjector> Injector;
453 bool SynthesizeBodies;
457 bool addImplicitDtors =
false,
458 bool addInitializers =
false,
459 bool addTemporaryDtors =
false,
460 bool addLifetime =
false,
461 bool addLoopExit =
false,
462 bool addScopes =
false,
463 bool synthesizeBodies =
false,
464 bool addStaticInitBranches =
false,
465 bool addCXXNewAllocator =
true,
466 bool addRichCXXConstructors =
true,
467 bool markElidedCXXConstructors =
true,
468 bool addVirtualBaseBranches =
true,
478 return cfgBuildOptions;
495 return LocContexts.
getStackFrame(getContext(D),
nullptr,
nullptr,
nullptr,
505 return LocContexts.
getStackFrame(getContext(D), Parent, S, Blk, Idx);
524 #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
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.
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)
Represents 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