[cfe-commits] r79701 - in /cfe/trunk: include/clang/Analysis/ include/clang/Analysis/PathSensitive/ lib/Analysis/

Ted Kremenek kremenek at apple.com
Fri Aug 21 16:58:44 PDT 2009


Author: kremenek
Date: Fri Aug 21 18:58:43 2009
New Revision: 79701

URL: http://llvm.org/viewvc/llvm-project?rev=79701&view=rev
Log:
Remove 'AnalysisContext::setDecl()', as we the Decl associated with an
AnalysisContext should never change. Along the way, propagate some constness
around.

Modified:
    cfe/trunk/include/clang/Analysis/LocalCheckers.h
    cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h
    cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h
    cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h
    cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h
    cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
    cfe/trunk/lib/Analysis/AnalysisContext.cpp
    cfe/trunk/lib/Analysis/AnalysisManager.cpp
    cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp
    cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp
    cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp
    cfe/trunk/lib/Analysis/CheckSecuritySyntaxOnly.cpp
    cfe/trunk/lib/Analysis/GRExprEngine.cpp

Modified: cfe/trunk/include/clang/Analysis/LocalCheckers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/LocalCheckers.h?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/LocalCheckers.h (original)
+++ cfe/trunk/include/clang/Analysis/LocalCheckers.h Fri Aug 21 18:58:43 2009
@@ -40,15 +40,17 @@
 GRTransferFuncs* MakeCFRefCountTF(ASTContext& Ctx, bool GCEnabled,
                                   const LangOptions& lopts); 
   
-void CheckObjCDealloc(ObjCImplementationDecl* D, const LangOptions& L,
+void CheckObjCDealloc(const ObjCImplementationDecl* D, const LangOptions& L,
                       BugReporter& BR);
   
-void CheckObjCInstMethSignature(ObjCImplementationDecl* ID, BugReporter& BR);
-void CheckObjCUnusedIvar(ObjCImplementationDecl* D, BugReporter& BR);
+void CheckObjCInstMethSignature(const ObjCImplementationDecl *ID,
+                                BugReporter& BR);
+
+void CheckObjCUnusedIvar(const ObjCImplementationDecl *D, BugReporter& BR);
   
 void RegisterAppleChecks(GRExprEngine& Eng, const Decl &D);
   
-void CheckSecuritySyntaxOnly(Decl *D, BugReporter &BR);
+void CheckSecuritySyntaxOnly(const Decl *D, BugReporter &BR);
 
   
 } // end namespace clang

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisContext.h Fri Aug 21 18:58:43 2009
@@ -17,7 +17,7 @@
 
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/FoldingSet.h"
-#include <map>
+#include "llvm/ADT/DenseMap.h"
 
 namespace clang {
 
@@ -31,8 +31,7 @@
 /// AnalysisContext contains the context data for the function or method under
 /// analysis.
 class AnalysisContext {
-  Decl *D;
-  Stmt *Body;
+  const Decl *D;
 
   // AnalysisContext owns the following data.
   CFG *cfg;
@@ -40,11 +39,10 @@
   ParentMap *PM;
 
 public:
-  AnalysisContext() : D(0), Body(0), cfg(0), liveness(0), PM(0) {}
+  AnalysisContext(const Decl *d) : D(d), cfg(0), liveness(0), PM(0) {}
   ~AnalysisContext();
 
-  void setDecl(Decl* d) { D = d; }
-  Decl *getDecl() { return D; }
+  const Decl *getDecl() { return D; }
   Stmt *getBody();
   CFG *getCFG();
   ParentMap &getParentMap();
@@ -56,12 +54,12 @@
 };
 
 class AnalysisContextManager {
-  std::map<Decl*, AnalysisContext> Contexts;
-
+  typedef llvm::DenseMap<const Decl*, AnalysisContext*> ContextMap;
+  ContextMap Contexts;
 public:
-  typedef std::map<Decl*, AnalysisContext>::iterator iterator;
-
-  AnalysisContext *getContext(Decl *D);
+  ~AnalysisContextManager();
+  
+  AnalysisContext *getContext(const Decl *D);
 };
 
 class LocationContext : public llvm::FoldingSetNode {

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/AnalysisManager.h Fri Aug 21 18:58:43 2009
@@ -83,7 +83,7 @@
     DisplayedFunction = false;
   }
     
-  Decl *getCodeDecl() const { 
+  const Decl *getCodeDecl() const { 
     assert (AScope == ScopeDecl);
     return EntryContext->getDecl();
   }

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h Fri Aug 21 18:58:43 2009
@@ -226,9 +226,10 @@
   /// cfg - The CFG associated with this analysis graph.
   CFG& cfg;
   
+  // FIXME: Remove.
   /// CodeDecl - The declaration containing the code being analyzed.  This
   ///  can be a FunctionDecl or and ObjCMethodDecl.
-  Decl& CodeDecl;
+  const Decl& CodeDecl;
   
   /// Ctx - The ASTContext used to "interpret" CodeDecl.
   ASTContext& Ctx;
@@ -261,7 +262,7 @@
     return V;
   }
 
-  ExplodedGraph(CFG& c, Decl& cd, ASTContext& ctx)
+  ExplodedGraph(CFG& c, const Decl &cd, ASTContext& ctx)
     : cfg(c), CodeDecl(cd), Ctx(ctx), NumNodes(0) {}
 
   virtual ~ExplodedGraph() {}
@@ -310,7 +311,7 @@
   CFG& getCFG() { return cfg; }
   ASTContext& getContext() { return Ctx; }
 
-  Decl& getCodeDecl() { return CodeDecl; }
+  // FIXME: Remove.
   const Decl& getCodeDecl() const { return CodeDecl; }
 
   const FunctionDecl* getFunctionDecl() const {

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h Fri Aug 21 18:58:43 2009
@@ -98,7 +98,8 @@
 public:
   /// Construct a GRCoreEngine object to analyze the provided CFG using
   ///  a DFS exploration of the exploded graph.
-  GRCoreEngine(CFG& cfg, Decl& cd, ASTContext& ctx, GRSubEngine& subengine)
+  GRCoreEngine(CFG& cfg, const Decl &cd, ASTContext& ctx,
+               GRSubEngine& subengine)
     : SubEngine(subengine), G(new ExplodedGraph(cfg, cd, ctx)), 
       WList(GRWorkList::MakeBFS()),
       BCounterFactory(G->getAllocator()) {}
@@ -106,7 +107,7 @@
   /// Construct a GRCoreEngine object to analyze the provided CFG and to
   ///  use the provided worklist object to execute the worklist algorithm.
   ///  The GRCoreEngine object assumes ownership of 'wlist'.
-  GRCoreEngine(CFG& cfg, Decl& cd, ASTContext& ctx, GRWorkList* wlist,
+  GRCoreEngine(CFG& cfg, const Decl &cd, ASTContext& ctx, GRWorkList* wlist,
                GRSubEngine& subengine)
     : SubEngine(subengine), G(new ExplodedGraph(cfg, cd, ctx)), WList(wlist),
       BCounterFactory(G->getAllocator()) {}

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Fri Aug 21 18:58:43 2009
@@ -202,7 +202,7 @@
   ErrorNodes ExplicitOOBMemAccesses;
   
 public:
-  GRExprEngine(CFG& cfg, Decl& CD, ASTContext& Ctx, LiveVariables& L,
+  GRExprEngine(CFG& cfg, const Decl &CD, ASTContext& Ctx, LiveVariables& L,
                AnalysisManager &mgr,
                bool purgeDead, bool eagerlyAssume = true,
                StoreManagerCreator SMC = CreateBasicStoreManager,

Modified: cfe/trunk/lib/Analysis/AnalysisContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisContext.cpp?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisContext.cpp Fri Aug 21 18:58:43 2009
@@ -28,10 +28,15 @@
   delete PM;
 }
 
+AnalysisContextManager::~AnalysisContextManager() {
+  for (ContextMap::iterator I = Contexts.begin(), E = Contexts.end(); I!=E; ++I)
+    delete I->second;
+}
+
 Stmt *AnalysisContext::getBody() {
-  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
     return FD->getBody();
-  else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
+  else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
     return MD->getBody();
 
   llvm::llvm_unreachable("unknown code decl");
@@ -70,14 +75,12 @@
   return liveness;
 }
 
-AnalysisContext *AnalysisContextManager::getContext(Decl *D) {
-  iterator I = Contexts.find(D);
-  if (I != Contexts.end())
-    return &(I->second);
-
-  AnalysisContext &Ctx = Contexts[D];
-  Ctx.setDecl(D);
-  return &Ctx;
+AnalysisContext *AnalysisContextManager::getContext(const Decl *D) {
+  AnalysisContext *&AC = Contexts[D];
+  if (!AC)
+    AC = new AnalysisContext(D);
+  
+  return AC;
 }
 
 void LocationContext::Profile(llvm::FoldingSetNodeID &ID, ContextKind k,

Modified: cfe/trunk/lib/Analysis/AnalysisManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisManager.cpp?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisManager.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisManager.cpp Fri Aug 21 18:58:43 2009
@@ -27,7 +27,7 @@
   // FIXME: Is getCodeDecl() always a named decl?
   if (isa<FunctionDecl>(getCodeDecl()) ||
       isa<ObjCMethodDecl>(getCodeDecl())) {
-    NamedDecl *ND = cast<NamedDecl>(getCodeDecl());
+    const NamedDecl *ND = cast<NamedDecl>(getCodeDecl());
     SourceManager &SM = getContext().getSourceManager();
     llvm::cerr << "ANALYZE: "
                << SM.getPresumedLoc(ND->getLocation()).getFilename()

Modified: cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp Fri Aug 21 18:58:43 2009
@@ -87,13 +87,13 @@
   return false;
 }
 
-void clang::CheckObjCDealloc(ObjCImplementationDecl* D,
+void clang::CheckObjCDealloc(const ObjCImplementationDecl* D,
                              const LangOptions& LOpts, BugReporter& BR) {
 
   assert (LOpts.getGCMode() != LangOptions::GCOnly);
   
   ASTContext& Ctx = BR.getContext();
-  ObjCInterfaceDecl* ID = D->getClassInterface();
+  const ObjCInterfaceDecl* ID = D->getClassInterface();
     
   // Does the class contain any ivars that are pointers (or id<...>)?
   // If not, skip the check entirely.

Modified: cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp Fri Aug 21 18:58:43 2009
@@ -36,10 +36,10 @@
   return C.typesAreCompatible(Derived, Ancestor);
 }
 
-static void CompareReturnTypes(ObjCMethodDecl* MethDerived,
-                               ObjCMethodDecl* MethAncestor,
-                               BugReporter& BR, ASTContext& Ctx,
-                               ObjCImplementationDecl* ID) {
+static void CompareReturnTypes(const ObjCMethodDecl *MethDerived,
+                               const ObjCMethodDecl *MethAncestor,
+                               BugReporter &BR, ASTContext &Ctx,
+                               const ObjCImplementationDecl *ID) {
     
   QualType ResDerived  = MethDerived->getResultType();
   QualType ResAncestor = MethAncestor->getResultType(); 
@@ -69,11 +69,11 @@
   }
 }
 
-void clang::CheckObjCInstMethSignature(ObjCImplementationDecl* ID,
+void clang::CheckObjCInstMethSignature(const ObjCImplementationDecl* ID,
                                        BugReporter& BR) {
   
-  ObjCInterfaceDecl* D = ID->getClassInterface();
-  ObjCInterfaceDecl* C = D->getSuperClass();
+  const ObjCInterfaceDecl* D = ID->getClassInterface();
+  const ObjCInterfaceDecl* C = D->getSuperClass();
 
   if (!C)
     return;

Modified: cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp Fri Aug 21 18:58:43 2009
@@ -62,7 +62,8 @@
     I->second = Used;
 }
 
-void clang::CheckObjCUnusedIvar(ObjCImplementationDecl* D, BugReporter& BR) {
+void clang::CheckObjCUnusedIvar(const ObjCImplementationDecl *D,
+                                BugReporter &BR) {
 
   const ObjCInterfaceDecl* ID = D->getClassInterface();
   IvarUsageMap M;

Modified: cfe/trunk/lib/Analysis/CheckSecuritySyntaxOnly.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckSecuritySyntaxOnly.cpp?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CheckSecuritySyntaxOnly.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckSecuritySyntaxOnly.cpp Fri Aug 21 18:58:43 2009
@@ -229,7 +229,7 @@
 // Entry point for check.
 //===----------------------------------------------------------------------===//
 
-void clang::CheckSecuritySyntaxOnly(Decl *D, BugReporter &BR) {  
+void clang::CheckSecuritySyntaxOnly(const Decl *D, BugReporter &BR) {  
   WalkAST walker(BR);
   walker.Visit(D->getBody());  
 }

Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=79701&r1=79700&r2=79701&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Fri Aug 21 18:58:43 2009
@@ -148,8 +148,8 @@
 }
 
 
-GRExprEngine::GRExprEngine(CFG& cfg, Decl& CD, ASTContext& Ctx,
-                           LiveVariables& L, AnalysisManager &mgr,
+GRExprEngine::GRExprEngine(CFG &cfg, const Decl &CD, ASTContext &Ctx,
+                           LiveVariables &L, AnalysisManager &mgr,
                            bool purgeDead, bool eagerlyAssume,
                            StoreManagerCreator SMC,
                            ConstraintManagerCreator CMC)





More information about the cfe-commits mailing list