]> granicus.if.org Git - clang/commitdiff
Add destructor and cleanup code to LocationContext (fixing some leaks). Along the...
authorTed Kremenek <kremenek@apple.com>
Tue, 20 Oct 2009 21:39:41 +0000 (21:39 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 20 Oct 2009 21:39:41 +0000 (21:39 +0000)
AnalysisManager periodically cleanup its AnalysisContextManager and LocationContextManager objects,
as they don't need to forever retain all the CFGs ever created when analyzing a file.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84684 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/AnalysisContext.h
include/clang/Analysis/PathSensitive/AnalysisManager.h
lib/Analysis/AnalysisContext.cpp
lib/Frontend/AnalysisConsumer.cpp

index ffe282d3caa39f6342fb7cd741e5af10048dc96c..8e02ccf38209fb683505e14ae21e20d7cd9d435b 100644 (file)
@@ -60,6 +60,9 @@ public:
   ~AnalysisContextManager();
 
   AnalysisContext *getContext(const Decl *D);
+  
+  // Discard all previously created AnalysisContexts.
+  void clear();
 };
 
 class LocationContext : public llvm::FoldingSetNode {
@@ -155,12 +158,17 @@ class LocationContextManager {
   llvm::FoldingSet<LocationContext> Contexts;
 
 public:
+  ~LocationContextManager();
+  
   StackFrameContext *getStackFrame(AnalysisContext *ctx,
                                    const LocationContext *parent,
                                    const Stmt *s);
 
   ScopeContext *getScope(AnalysisContext *ctx, const LocationContext *parent,
                          const Stmt *s);
+  
+  /// Discard all previously created LocationContext objects.
+  void clear();
 };
 
 } // end clang namespace
index e97f80576a8bdc2e967894cf72b51ecd6da5f079..1a64f56ee8a41405597b69b90e9b8fc5d20cae17 100644 (file)
@@ -65,6 +65,11 @@ public:
       AScope(ScopeDecl), DisplayedFunction(!displayProgress),
       VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
       EagerlyAssume(eager), TrimGraph(trim) {}
+  
+  void ClearContexts() {
+    LocCtxMgr.clear();
+    AnaCtxMgr.clear();
+  }
 
   StoreManagerCreator getStoreManagerCreator() {
     return CreateStoreMgr;
index a4cb66be04b30c766df348311d47ba75a6bdb0f8..640912ad6b39de79aed52e41d00924e802576fd2 100644 (file)
@@ -33,6 +33,12 @@ AnalysisContextManager::~AnalysisContextManager() {
     delete I->second;
 }
 
+void AnalysisContextManager::clear() {
+  for (ContextMap::iterator I = Contexts.begin(), E = Contexts.end(); I!=E; ++I)
+    delete I->second;
+  Contexts.clear();
+}
+
 Stmt *AnalysisContext::getBody() {
   if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
     return FD->getBody();
@@ -103,6 +109,21 @@ void ScopeContext::Profile(llvm::FoldingSetNodeID &ID, AnalysisContext *ctx,
   ID.AddPointer(s);
 }
 
+LocationContextManager::~LocationContextManager() {
+  clear();
+}
+
+void LocationContextManager::clear() {
+  for (llvm::FoldingSet<LocationContext>::iterator I = Contexts.begin(),
+       E = Contexts.end(); I != E; ) {    
+    LocationContext *LC = &*I;
+    ++I;
+    delete LC;
+  }
+  
+  Contexts.clear();
+}
+
 StackFrameContext*
 LocationContextManager::getStackFrame(AnalysisContext *ctx,
                                       const LocationContext *parent,
index dbf9364f8722092c5b912b2369aeb25b22ff9892..55f274005909bee90a618bacb1b0542b87468d94 100644 (file)
@@ -273,6 +273,9 @@ void AnalysisConsumer::HandleCode(Decl *D, Stmt* Body, Actions& actions) {
       !Ctx->getSourceManager().isFromMainFile(D->getLocation()))
     return;
 
+  // Clear the AnalysisManager of old AnalysisContexts.
+  Mgr->ClearContexts();
+  
   // Dispatch on the actions.
   for (Actions::iterator I = actions.begin(), E = actions.end(); I != E; ++I)
     (*I)(*Mgr, D);