diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-10-20 21:39:41 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-10-20 21:39:41 +0000 |
commit | d45ff6cced877257fbf5ea0e67f08287fb3c6c3a (patch) | |
tree | 48378c08abf0b4ad55a9bf33f3f72b50860ffd96 | |
parent | a6faf60831fa912c5a808d5b49f7c4d09bff7734 (diff) | |
download | bcm5719-llvm-d45ff6cced877257fbf5ea0e67f08287fb3c6c3a.tar.gz bcm5719-llvm-d45ff6cced877257fbf5ea0e67f08287fb3c6c3a.zip |
Add destructor and cleanup code to LocationContext (fixing some leaks). Along the way, have
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.
llvm-svn: 84684
4 files changed, 37 insertions, 0 deletions
diff --git a/clang/include/clang/Analysis/PathSensitive/AnalysisContext.h b/clang/include/clang/Analysis/PathSensitive/AnalysisContext.h index ffe282d3caa..8e02ccf3820 100644 --- a/clang/include/clang/Analysis/PathSensitive/AnalysisContext.h +++ b/clang/include/clang/Analysis/PathSensitive/AnalysisContext.h @@ -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 diff --git a/clang/include/clang/Analysis/PathSensitive/AnalysisManager.h b/clang/include/clang/Analysis/PathSensitive/AnalysisManager.h index e97f80576a8..1a64f56ee8a 100644 --- a/clang/include/clang/Analysis/PathSensitive/AnalysisManager.h +++ b/clang/include/clang/Analysis/PathSensitive/AnalysisManager.h @@ -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; diff --git a/clang/lib/Analysis/AnalysisContext.cpp b/clang/lib/Analysis/AnalysisContext.cpp index a4cb66be04b..640912ad6b3 100644 --- a/clang/lib/Analysis/AnalysisContext.cpp +++ b/clang/lib/Analysis/AnalysisContext.cpp @@ -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, diff --git a/clang/lib/Frontend/AnalysisConsumer.cpp b/clang/lib/Frontend/AnalysisConsumer.cpp index dbf9364f872..55f27400590 100644 --- a/clang/lib/Frontend/AnalysisConsumer.cpp +++ b/clang/lib/Frontend/AnalysisConsumer.cpp @@ -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); |