From 7e1a6ca9e89c3ea08f8b008e9140d9fdc048d1df Mon Sep 17 00:00:00 2001 From: Charusso Date: Wed, 4 Mar 2020 07:06:35 +0100 Subject: [PATCH] [analyzer] AnalysisDeclContext: Refactor and documentation Summary: `ScopeContext` wanted to be a thing, but sadly it is dead code. If you wish to continue the work in D19979, here was a tiny code which could be reused, but that tiny and that dead, I felt that it is unneded. Note: Other changes are truly uninteresting. Reviewed By: NoQ Differential Revision: https://reviews.llvm.org/D73519 --- clang/include/clang/Analysis/AnalysisDeclContext.h | 374 +++++++++------------ clang/lib/Analysis/AnalysisDeclContext.cpp | 106 ++---- clang/lib/StaticAnalyzer/Core/MemRegion.cpp | 3 +- 3 files changed, 201 insertions(+), 282 deletions(-) diff --git a/clang/include/clang/Analysis/AnalysisDeclContext.h b/clang/include/clang/Analysis/AnalysisDeclContext.h index 9faa78c..ed554fe 100644 --- a/clang/include/clang/Analysis/AnalysisDeclContext.h +++ b/clang/include/clang/Analysis/AnalysisDeclContext.h @@ -1,4 +1,4 @@ -// AnalysisDeclContext.h - Analysis context for Path Sens analysis -*- C++ -*-// +//===- AnalysisDeclContext.h - Context for path sensitivity -----*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,11 @@ // //===----------------------------------------------------------------------===// // -// This file defines AnalysisDeclContext, a class that manages the analysis -// context data for path sensitive analysis. +/// \file +/// This file defines AnalysisDeclContext, a class that manages the analysis +/// context data for context sensitive and path sensitive analysis. +/// It also defines the helper classes to model entering, leaving or inlining +/// function calls. // //===----------------------------------------------------------------------===// @@ -64,14 +67,14 @@ public: // which creates the analysis object given an AnalysisDeclContext. }; -/// AnalysisDeclContext contains the context data for the function or method -/// under analysis. +/// AnalysisDeclContext contains the context data for the function, method +/// or block under analysis. class AnalysisDeclContext { - /// Backpoint to the AnalysisManager object that created this - /// AnalysisDeclContext. This may be null. - AnalysisDeclContextManager *Manager; + // Backpoint to the AnalysisManager object that created this + // AnalysisDeclContext. This may be null. + AnalysisDeclContextManager *ADCMgr; - const Decl * const D; + const Decl *const D; std::unique_ptr cfg, completeCFG; std::unique_ptr cfgStmtMap; @@ -86,45 +89,36 @@ class AnalysisDeclContext { llvm::BumpPtrAllocator A; - llvm::DenseMap *ReferencedBlockVars = nullptr; + llvm::DenseMap *ReferencedBlockVars = nullptr; void *ManagedAnalyses = nullptr; public: - AnalysisDeclContext(AnalysisDeclContextManager *Mgr, - const Decl *D); + AnalysisDeclContext(AnalysisDeclContextManager *Mgr, const Decl *D); - AnalysisDeclContext(AnalysisDeclContextManager *Mgr, - const Decl *D, - const CFG::BuildOptions &BuildOptions); + AnalysisDeclContext(AnalysisDeclContextManager *Mgr, const Decl *D, + const CFG::BuildOptions &BuildOptions); ~AnalysisDeclContext(); ASTContext &getASTContext() const { return D->getASTContext(); } + const Decl *getDecl() const { return D; } - /// Return the AnalysisDeclContextManager (if any) that created - /// this AnalysisDeclContext. - AnalysisDeclContextManager *getManager() const { - return Manager; - } + AnalysisDeclContextManager *getManager() const { return ADCMgr; } - /// Return the build options used to construct the CFG. - CFG::BuildOptions &getCFGBuildOptions() { - return cfgBuildOptions; - } + CFG::BuildOptions &getCFGBuildOptions() { return cfgBuildOptions; } const CFG::BuildOptions &getCFGBuildOptions() const { return cfgBuildOptions; } - /// getAddEHEdges - Return true iff we are adding exceptional edges from - /// callExprs. If this is false, then try/catch statements and blocks - /// reachable from them can appear to be dead in the CFG, analysis passes must - /// cope with that. + /// \returns Whether we are adding exception handling edges from CallExprs. + /// If this is false, then try/catch statements and blocks reachable from them + /// can appear to be dead in the CFG, analysis passes must cope with that. bool getAddEHEdges() const { return cfgBuildOptions.AddEHEdges; } bool getUseUnoptimizedCFG() const { - return !cfgBuildOptions.PruneTriviallyFalseEdges; + return !cfgBuildOptions.PruneTriviallyFalseEdges; } bool getAddImplicitDtors() const { return cfgBuildOptions.AddImplicitDtors; } bool getAddInitializers() const { return cfgBuildOptions.AddInitializers; } @@ -132,25 +126,25 @@ public: void registerForcedBlockExpression(const Stmt *stmt); const CFGBlock *getBlockForRegisteredExpression(const Stmt *stmt); - /// Get the body of the Declaration. + /// \returns The body of the stored Decl \c D. Stmt *getBody() const; - /// Get the body of the Declaration. + /// \copydoc AnalysisDeclContext::getBody() /// \param[out] IsAutosynthesized Specifies if the body is auto-generated /// by the BodyFarm. Stmt *getBody(bool &IsAutosynthesized) const; - /// Checks if the body of the Decl is generated by the BodyFarm. + /// \returns Whether the body of the Decl \c D is generated by the BodyFarm. /// - /// Note, the lookup is not free. We are going to call getBody behind + /// \note The lookup is not free. We are going to call getBody behind /// the scenes. /// \sa getBody bool isBodyAutosynthesized() const; - /// Checks if the body of the Decl is generated by the BodyFarm from a - /// model file. + /// \returns Whether the body of the Decl \c D is generated by the BodyFarm + /// from a model file. /// - /// Note, the lookup is not free. We are going to call getBody behind + /// \note The lookup is not free. We are going to call getBody behind /// the scenes. /// \sa getBody bool isBodyAutosynthesizedFromModelFile() const; @@ -161,40 +155,41 @@ public: CFGReverseBlockReachabilityAnalysis *getCFGReachablityAnalysis(); - /// Return a version of the CFG without any edges pruned. + /// \returns A version of the CFG without any edges pruned. CFG *getUnoptimizedCFG(); void dumpCFG(bool ShowColors); - /// Returns true if we have built a CFG for this analysis context. - /// Note that this doesn't correspond to whether or not a valid CFG exists, it + /// \returns Whether we have built a CFG for this analysis context. + /// + /// \note This doesn't correspond to whether or not a valid CFG exists, it /// corresponds to whether we *attempted* to build one. bool isCFGBuilt() const { return builtCFG; } ParentMap &getParentMap(); - using referenced_decls_iterator = const VarDecl * const *; + using referenced_decls_iterator = const VarDecl *const *; llvm::iterator_range getReferencedBlockVars(const BlockDecl *BD); - /// Return the ImplicitParamDecl* associated with 'self' if this - /// AnalysisDeclContext wraps an ObjCMethodDecl. Returns NULL otherwise. + /// \returns The ImplicitParamDecl associated with \c self if this + /// AnalysisDeclContext wraps an ObjCMethodDecl or nullptr otherwise. const ImplicitParamDecl *getSelfDecl() const; - const StackFrameContext *getStackFrame(LocationContext const *Parent, + /// \copydoc LocationContextManager::getStackFrame() + const StackFrameContext *getStackFrame(LocationContext const *ParentLC, const Stmt *S, const CFGBlock *Blk, - unsigned BlockCount, unsigned Idx); + unsigned BlockCount, unsigned Index); + /// \copydoc LocationContextManager::getBlockInvocationContext() const BlockInvocationContext * - getBlockInvocationContext(const LocationContext *parent, - const BlockDecl *BD, - const void *ContextData); - - /// Return the specified analysis object, lazily running the analysis if - /// necessary. Return NULL if the analysis could not run. - template - T *getAnalysis() { + getBlockInvocationContext(const LocationContext *ParentLC, + const BlockDecl *BD, const void *Data); + + /// \returns The specified analysis object, lazily running the analysis if + /// necessary or nullptr if the analysis could not run. + template T *getAnalysis() { const void *tag = T::getTag(); ManagedAnalysis *&data = getAnalysisImpl(tag); if (!data) { @@ -203,19 +198,22 @@ public: return static_cast(data); } - /// Returns true if the root namespace of the given declaration is the 'std' - /// C++ namespace. + /// \returns Whether the root namespace of \p D is the \c std C++ namespace. static bool isInStdNamespace(const Decl *D); private: - ManagedAnalysis *&getAnalysisImpl(const void* tag); + ManagedAnalysis *&getAnalysisImpl(const void *tag); LocationContextManager &getLocationContextManager(); }; +/// It wraps the AnalysisDeclContext to represent both the call stack with +/// the help of StackFrameContext and inside the function calls the +/// BlockInvocationContext. It is needed for context sensitive analysis to +/// model entering, leaving or inlining function calls. class LocationContext : public llvm::FoldingSetNode { public: - enum ContextKind { StackFrame, Scope, Block }; + enum ContextKind { StackFrame, Block }; private: ContextKind Kind; @@ -229,8 +227,7 @@ private: protected: LocationContext(ContextKind k, AnalysisDeclContext *ctx, - const LocationContext *parent, - int64_t ID) + const LocationContext *parent, int64_t ID) : Kind(k), Ctx(ctx), Parent(parent), ID(ID) {} public: @@ -238,9 +235,7 @@ public: ContextKind getKind() const { return Kind; } - int64_t getID() const { - return ID; - } + int64_t getID() const { return ID; } AnalysisDeclContext *getAnalysisDeclContext() const { return Ctx; } @@ -248,58 +243,61 @@ public: bool isParentOf(const LocationContext *LC) const; - const Decl *getDecl() const { return getAnalysisDeclContext()->getDecl(); } + const Decl *getDecl() const { return Ctx->getDecl(); } - CFG *getCFG() const { return getAnalysisDeclContext()->getCFG(); } + CFG *getCFG() const { return Ctx->getCFG(); } - template - T *getAnalysis() const { - return getAnalysisDeclContext()->getAnalysis(); - } + template T *getAnalysis() const { return Ctx->getAnalysis(); } - const ParentMap &getParentMap() const { - return getAnalysisDeclContext()->getParentMap(); - } + const ParentMap &getParentMap() const { return Ctx->getParentMap(); } - const ImplicitParamDecl *getSelfDecl() const { - return Ctx->getSelfDecl(); - } + /// \copydoc AnalysisDeclContext::getSelfDecl() + const ImplicitParamDecl *getSelfDecl() const { return Ctx->getSelfDecl(); } const StackFrameContext *getStackFrame() const; - /// Return true if the current LocationContext has no caller context. + /// \returns Whether the current LocationContext has no caller context. virtual bool inTopFrame() const; virtual void Profile(llvm::FoldingSetNodeID &ID) = 0; - void dumpStack( - raw_ostream &Out, const char *NL = "\n", - std::function printMoreInfoPerContext = - [](const LocationContext *) {}) const; + /// Prints out the call stack. + /// + /// \param Out The out stream. + LLVM_DUMP_METHOD void dumpStack(raw_ostream &Out) const; + /// Prints out the call stack in \c json format. + /// + /// \param Out The out stream. + /// \param NL The newline. + /// \param Space The space count for indentation. + /// \param IsDot Whether the output format is \c dot. + /// \param printMoreInfoPerContext + /// A callback to print more information for each context, for example: + /// \code + /// [&](const LocationContext *LC) { LC->dump(); } + /// \endcode void printJson( raw_ostream &Out, const char *NL = "\n", unsigned int Space = 0, bool IsDot = false, std::function printMoreInfoPerContext = [](const LocationContext *) {}) const; - void dump() const; + LLVM_DUMP_METHOD void dump() const; -public: - static void ProfileCommon(llvm::FoldingSetNodeID &ID, - ContextKind ck, + static void ProfileCommon(llvm::FoldingSetNodeID &ID, ContextKind ck, AnalysisDeclContext *ctx, - const LocationContext *parent, - const void *data); + const LocationContext *parent, const void *data); }; +/// It represents a stack frame of the call stack (based on CallEvent). class StackFrameContext : public LocationContext { friend class LocationContextManager; - // The callsite where this stack frame is established. + // The call site where this stack frame is established. const Stmt *CallSite; - // The parent block of the callsite. + // The parent block of the call site. const CFGBlock *Block; // The number of times the 'Block' has been visited. @@ -307,14 +305,14 @@ class StackFrameContext : public LocationContext { // called multiple times in a loop. const unsigned BlockCount; - // The index of the callsite in the CFGBlock. + // The index of the call site in the CFGBlock. const unsigned Index; - StackFrameContext(AnalysisDeclContext *ctx, const LocationContext *parent, - const Stmt *s, const CFGBlock *blk, unsigned blockCount, - unsigned idx, int64_t ID) - : LocationContext(StackFrame, ctx, parent, ID), CallSite(s), Block(blk), - BlockCount(blockCount), Index(idx) {} + StackFrameContext(AnalysisDeclContext *ADC, const LocationContext *ParentLC, + const Stmt *S, const CFGBlock *Block, unsigned BlockCount, + unsigned Index, int64_t ID) + : LocationContext(StackFrame, ADC, ParentLC, ID), CallSite(S), + Block(Block), BlockCount(BlockCount), Index(Index) {} public: ~StackFrameContext() override = default; @@ -323,117 +321,98 @@ public: const CFGBlock *getCallSiteBlock() const { return Block; } - /// Return true if the current LocationContext has no caller context. - bool inTopFrame() const override { return getParent() == nullptr; } + bool inTopFrame() const override { return getParent() == nullptr; } unsigned getIndex() const { return Index; } void Profile(llvm::FoldingSetNodeID &ID) override; - static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx, - const LocationContext *parent, const Stmt *s, - const CFGBlock *blk, unsigned blockCount, unsigned idx) { - ProfileCommon(ID, StackFrame, ctx, parent, s); - ID.AddPointer(blk); - ID.AddInteger(blockCount); - ID.AddInteger(idx); + static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ADC, + const LocationContext *ParentLC, const Stmt *S, + const CFGBlock *Block, unsigned BlockCount, + unsigned Index) { + ProfileCommon(ID, StackFrame, ADC, ParentLC, S); + ID.AddPointer(Block); + ID.AddInteger(BlockCount); + ID.AddInteger(Index); } - static bool classof(const LocationContext *Ctx) { - return Ctx->getKind() == StackFrame; - } -}; - -class ScopeContext : public LocationContext { - friend class LocationContextManager; - - const Stmt *Enter; - - ScopeContext(AnalysisDeclContext *ctx, const LocationContext *parent, - const Stmt *s, int64_t ID) - : LocationContext(Scope, ctx, parent, ID), Enter(s) {} - -public: - ~ScopeContext() override = default; - - void Profile(llvm::FoldingSetNodeID &ID) override; - - static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx, - const LocationContext *parent, const Stmt *s) { - ProfileCommon(ID, Scope, ctx, parent, s); - } - - static bool classof(const LocationContext *Ctx) { - return Ctx->getKind() == Scope; + static bool classof(const LocationContext *LC) { + return LC->getKind() == StackFrame; } }; +/// It represents a block invocation (based on BlockCall). class BlockInvocationContext : public LocationContext { friend class LocationContextManager; const BlockDecl *BD; // FIXME: Come up with a more type-safe way to model context-sensitivity. - const void *ContextData; + const void *Data; - BlockInvocationContext(AnalysisDeclContext *ctx, - const LocationContext *parent, const BlockDecl *bd, - const void *contextData, int64_t ID) - : LocationContext(Block, ctx, parent, ID), BD(bd), - ContextData(contextData) {} + BlockInvocationContext(AnalysisDeclContext *ADC, + const LocationContext *ParentLC, const BlockDecl *BD, + const void *Data, int64_t ID) + : LocationContext(Block, ADC, ParentLC, ID), BD(BD), Data(Data) {} public: ~BlockInvocationContext() override = default; const BlockDecl *getBlockDecl() const { return BD; } - const void *getContextData() const { return ContextData; } + const void *getData() const { return Data; } void Profile(llvm::FoldingSetNodeID &ID) override; - static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx, - const LocationContext *parent, const BlockDecl *bd, - const void *contextData) { - ProfileCommon(ID, Block, ctx, parent, bd); - ID.AddPointer(contextData); + static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ADC, + const LocationContext *ParentLC, const BlockDecl *BD, + const void *Data) { + ProfileCommon(ID, Block, ADC, ParentLC, BD); + ID.AddPointer(Data); } - static bool classof(const LocationContext *Ctx) { - return Ctx->getKind() == Block; + static bool classof(const LocationContext *LC) { + return LC->getKind() == Block; } }; class LocationContextManager { llvm::FoldingSet Contexts; - /// ID used for generating a new location context. + // ID used for generating a new location context. int64_t NewID = 0; public: ~LocationContextManager(); - const StackFrameContext *getStackFrame(AnalysisDeclContext *ctx, - const LocationContext *parent, - const Stmt *s, const CFGBlock *blk, - unsigned blockCount, unsigned idx); - - const ScopeContext *getScope(AnalysisDeclContext *ctx, - const LocationContext *parent, - const Stmt *s); - + /// Obtain a context of the call stack using its parent context. + /// + /// \param ADC The AnalysisDeclContext. + /// \param ParentLC The parent context of this newly created context. + /// \param S The call. + /// \param Block The basic block. + /// \param BlockCount The current count of entering into \p Blk. + /// \param Index The index of \p Blk. + /// \returns The context for \p D with parent context \p ParentLC. + const StackFrameContext *getStackFrame(AnalysisDeclContext *ADC, + const LocationContext *ParentLC, + const Stmt *S, const CFGBlock *Block, + unsigned BlockCount, unsigned Index); + + /// Obtain a context of the block invocation using its parent context. + /// + /// \param ADC The AnalysisDeclContext. + /// \param ParentLC The parent context of this newly created context. + /// \param BD The BlockDecl. + /// \param Data The raw data to store as part of the context. const BlockInvocationContext * - getBlockInvocationContext(AnalysisDeclContext *ctx, - const LocationContext *parent, - const BlockDecl *BD, - const void *ContextData); + getBlockInvocationContext(AnalysisDeclContext *ADC, + const LocationContext *ParentLC, + const BlockDecl *BD, const void *Data); /// Discard all previously created LocationContext objects. void clear(); -private: - template - const LOC *getLocationContext(AnalysisDeclContext *ctx, - const LocationContext *parent, - const DATA *d); }; class AnalysisDeclContextManager { @@ -441,36 +420,31 @@ class AnalysisDeclContextManager { llvm::DenseMap>; ContextMap Contexts; - LocationContextManager LocContexts; + LocationContextManager LocCtxMgr; CFG::BuildOptions cfgBuildOptions; - /// Pointer to an interface that can provide function bodies for - /// declarations from external source. + // Pointer to an interface that can provide function bodies for + // declarations from external source. std::unique_ptr Injector; - /// A factory for creating and caching implementations for common - /// methods during the analysis. + // A factory for creating and caching implementations for common + // methods during the analysis. BodyFarm FunctionBodyFarm; - /// Flag to indicate whether or not bodies should be synthesized - /// for well-known functions. + // Flag to indicate whether or not bodies should be synthesized + // for well-known functions. bool SynthesizeBodies; public: - AnalysisDeclContextManager(ASTContext &ASTCtx, bool useUnoptimizedCFG = false, - bool addImplicitDtors = false, - bool addInitializers = false, - bool addTemporaryDtors = false, - bool addLifetime = false, - bool addLoopExit = false, - bool addScopes = false, - bool synthesizeBodies = false, - bool addStaticInitBranches = false, - bool addCXXNewAllocator = true, - bool addRichCXXConstructors = true, - bool markElidedCXXConstructors = true, - bool addVirtualBaseBranches = true, - CodeInjector *injector = nullptr); + AnalysisDeclContextManager( + ASTContext &ASTCtx, bool useUnoptimizedCFG = false, + bool addImplicitDtors = false, bool addInitializers = false, + bool addTemporaryDtors = false, bool addLifetime = false, + bool addLoopExit = false, bool addScopes = false, + bool synthesizeBodies = false, bool addStaticInitBranches = false, + bool addCXXNewAllocator = true, bool addRichCXXConstructors = true, + bool markElidedCXXConstructors = true, bool addVirtualBaseBranches = true, + CodeInjector *injector = nullptr); AnalysisDeclContext *getContext(const Decl *D); @@ -478,37 +452,27 @@ public: return !cfgBuildOptions.PruneTriviallyFalseEdges; } - CFG::BuildOptions &getCFGBuildOptions() { - return cfgBuildOptions; - } + CFG::BuildOptions &getCFGBuildOptions() { return cfgBuildOptions; } - /// Return true if faux bodies should be synthesized for well-known - /// functions. + /// \returns Whether faux bodies should be synthesized for known functions. bool synthesizeBodies() const { return SynthesizeBodies; } - const StackFrameContext *getStackFrame(AnalysisDeclContext *Ctx, - const LocationContext *Parent, - const Stmt *S, const CFGBlock *Blk, - unsigned BlockCount, unsigned Idx) { - return LocContexts.getStackFrame(Ctx, Parent, S, Blk, BlockCount, Idx); - } - - // Get the top level stack frame. + /// Obtain the beginning context of the analysis. + /// + /// \returns The top level stack frame for \p D. const StackFrameContext *getStackFrame(const Decl *D) { - return LocContexts.getStackFrame(getContext(D), nullptr, nullptr, nullptr, - 0, 0); + return LocCtxMgr.getStackFrame(getContext(D), nullptr, nullptr, nullptr, 0, + 0); } - // Get a stack frame with parent. - StackFrameContext const *getStackFrame(const Decl *D, + /// \copydoc LocationContextManager::getStackFrame() + const StackFrameContext *getStackFrame(AnalysisDeclContext *ADC, const LocationContext *Parent, - const Stmt *S, const CFGBlock *Blk, - unsigned BlockCount, unsigned Idx) { - return LocContexts.getStackFrame(getContext(D), Parent, S, Blk, BlockCount, - Idx); + const Stmt *S, const CFGBlock *Block, + unsigned BlockCount, unsigned Index) { + return LocCtxMgr.getStackFrame(ADC, Parent, S, Block, BlockCount, Index); } - /// Get a reference to {@code BodyFarm} instance. BodyFarm &getBodyFarm(); /// Discard all previously created AnalysisDeclContexts. @@ -517,9 +481,7 @@ public: private: friend class AnalysisDeclContext; - LocationContextManager &getLocationContextManager() { - return LocContexts; - } + LocationContextManager &getLocationContextManager() { return LocCtxMgr; } }; } // namespace clang diff --git a/clang/lib/Analysis/AnalysisDeclContext.cpp b/clang/lib/Analysis/AnalysisDeclContext.cpp index 9f58b50..96d5807 100644 --- a/clang/lib/Analysis/AnalysisDeclContext.cpp +++ b/clang/lib/Analysis/AnalysisDeclContext.cpp @@ -52,16 +52,16 @@ using namespace clang; using ManagedAnalysisMap = llvm::DenseMap; -AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr, - const Decl *d, - const CFG::BuildOptions &buildOptions) - : Manager(Mgr), D(d), cfgBuildOptions(buildOptions) { +AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *ADCMgr, + const Decl *D, + const CFG::BuildOptions &Options) + : ADCMgr(ADCMgr), D(D), cfgBuildOptions(Options) { cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs; } -AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr, - const Decl *d) - : Manager(Mgr), D(d) { +AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *ADCMgr, + const Decl *D) + : ADCMgr(ADCMgr), D(D) { cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs; } @@ -96,8 +96,8 @@ Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const { Stmt *Body = FD->getBody(); if (auto *CoroBody = dyn_cast_or_null(Body)) Body = CoroBody->getBody(); - if (Manager && Manager->synthesizeBodies()) { - Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(FD); + if (ADCMgr && ADCMgr->synthesizeBodies()) { + Stmt *SynthesizedBody = ADCMgr->getBodyFarm().getBody(FD); if (SynthesizedBody) { Body = SynthesizedBody; IsAutosynthesized = true; @@ -107,8 +107,8 @@ Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const { } else if (const auto *MD = dyn_cast(D)) { Stmt *Body = MD->getBody(); - if (Manager && Manager->synthesizeBodies()) { - Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(MD); + if (ADCMgr && ADCMgr->synthesizeBodies()) { + Stmt *SynthesizedBody = ADCMgr->getBodyFarm().getBody(MD); if (SynthesizedBody) { Body = SynthesizedBody; IsAutosynthesized = true; @@ -309,19 +309,17 @@ AnalysisDeclContext *AnalysisDeclContextManager::getContext(const Decl *D) { BodyFarm &AnalysisDeclContextManager::getBodyFarm() { return FunctionBodyFarm; } const StackFrameContext * -AnalysisDeclContext::getStackFrame(LocationContext const *Parent, const Stmt *S, - const CFGBlock *Blk, unsigned BlockCount, - unsigned Idx) { - return getLocationContextManager().getStackFrame(this, Parent, S, Blk, - BlockCount, Idx); +AnalysisDeclContext::getStackFrame(const LocationContext *ParentLC, + const Stmt *S, const CFGBlock *Blk, + unsigned BlockCount, unsigned Index) { + return getLocationContextManager().getStackFrame(this, ParentLC, S, Blk, + BlockCount, Index); } -const BlockInvocationContext * -AnalysisDeclContext::getBlockInvocationContext(const LocationContext *parent, - const BlockDecl *BD, - const void *ContextData) { - return getLocationContextManager().getBlockInvocationContext(this, parent, - BD, ContextData); +const BlockInvocationContext *AnalysisDeclContext::getBlockInvocationContext( + const LocationContext *ParentLC, const BlockDecl *BD, const void *Data) { + return getLocationContextManager().getBlockInvocationContext(this, ParentLC, + BD, Data); } bool AnalysisDeclContext::isInStdNamespace(const Decl *D) { @@ -340,9 +338,10 @@ bool AnalysisDeclContext::isInStdNamespace(const Decl *D) { } LocationContextManager &AnalysisDeclContext::getLocationContextManager() { - assert(Manager && - "Cannot create LocationContexts without an AnalysisDeclContextManager!"); - return Manager->getLocationContextManager(); + assert( + ADCMgr && + "Cannot create LocationContexts without an AnalysisDeclContextManager!"); + return ADCMgr->getLocationContextManager(); } //===----------------------------------------------------------------------===// @@ -365,36 +364,14 @@ void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID) { BlockCount, Index); } -void ScopeContext::Profile(llvm::FoldingSetNodeID &ID) { - Profile(ID, getAnalysisDeclContext(), getParent(), Enter); -} - void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) { - Profile(ID, getAnalysisDeclContext(), getParent(), BD, ContextData); + Profile(ID, getAnalysisDeclContext(), getParent(), BD, Data); } //===----------------------------------------------------------------------===// // LocationContext creation. //===----------------------------------------------------------------------===// -template -const LOC* -LocationContextManager::getLocationContext(AnalysisDeclContext *ctx, - const LocationContext *parent, - const DATA *d) { - llvm::FoldingSetNodeID ID; - LOC::Profile(ID, ctx, parent, d); - void *InsertPos; - - LOC *L = cast_or_null(Contexts.FindNodeOrInsertPos(ID, InsertPos)); - - if (!L) { - L = new LOC(ctx, parent, d, ++NewID); - Contexts.InsertNode(L, InsertPos); - } - return L; -} - const StackFrameContext *LocationContextManager::getStackFrame( AnalysisDeclContext *ctx, const LocationContext *parent, const Stmt *s, const CFGBlock *blk, unsigned blockCount, unsigned idx) { @@ -410,26 +387,17 @@ const StackFrameContext *LocationContextManager::getStackFrame( return L; } -const ScopeContext * -LocationContextManager::getScope(AnalysisDeclContext *ctx, - const LocationContext *parent, - const Stmt *s) { - return getLocationContext(ctx, parent, s); -} - -const BlockInvocationContext * -LocationContextManager::getBlockInvocationContext(AnalysisDeclContext *ctx, - const LocationContext *parent, - const BlockDecl *BD, - const void *ContextData) { +const BlockInvocationContext *LocationContextManager::getBlockInvocationContext( + AnalysisDeclContext *ADC, const LocationContext *ParentLC, + const BlockDecl *BD, const void *Data) { llvm::FoldingSetNodeID ID; - BlockInvocationContext::Profile(ID, ctx, parent, BD, ContextData); + BlockInvocationContext::Profile(ID, ADC, ParentLC, BD, Data); void *InsertPos; auto *L = cast_or_null(Contexts.FindNodeOrInsertPos(ID, InsertPos)); if (!L) { - L = new BlockInvocationContext(ctx, parent, BD, ContextData, ++NewID); + L = new BlockInvocationContext(ADC, ParentLC, BD, Data, ++NewID); Contexts.InsertNode(L, InsertPos); } return L; @@ -473,9 +441,7 @@ static void printLocation(raw_ostream &Out, const SourceManager &SM, Loc.print(Out, SM); } -void LocationContext::dumpStack(raw_ostream &Out, const char *NL, - std::function - printMoreInfoPerContext) const { +void LocationContext::dumpStack(raw_ostream &Out) const { ASTContext &Ctx = getAnalysisDeclContext()->getASTContext(); PrintingPolicy PP(Ctx.getLangOpts()); PP.TerseOutput = 1; @@ -498,9 +464,6 @@ void LocationContext::dumpStack(raw_ostream &Out, const char *NL, printLocation(Out, SM, S->getBeginLoc()); } break; - case Scope: - Out << "Entering scope"; - break; case Block: Out << "Invoking block"; if (const Decl *D = cast(LCtx)->getDecl()) { @@ -509,9 +472,7 @@ void LocationContext::dumpStack(raw_ostream &Out, const char *NL, } break; } - Out << NL; - - printMoreInfoPerContext(LCtx); + Out << '\n'; } } @@ -548,9 +509,6 @@ void LocationContext::printJson(raw_ostream &Out, const char *NL, Out << ", \"items\": "; break; - case Scope: - Out << "Entering scope\" "; - break; case Block: Out << "Invoking block\" "; if (const Decl *D = cast(LCtx)->getDecl()) { diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp index 2319ae1..77944de 100644 --- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp +++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp @@ -842,8 +842,7 @@ getStackOrCaptureRegionForDeclContext(const LocationContext *LC, return SFC; } if (const auto *BC = dyn_cast(LC)) { - const auto *BR = - static_cast(BC->getContextData()); + const auto *BR = static_cast(BC->getData()); // FIXME: This can be made more efficient. for (BlockDataRegion::referenced_vars_iterator I = BR->referenced_vars_begin(), -- 2.7.4