diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Analysis/AnalysisContext.cpp | 36 | ||||
-rw-r--r-- | clang/lib/Analysis/LiveVariables.cpp | 2 | ||||
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp | 2 | ||||
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp | 2 | ||||
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/SymbolManager.cpp | 6 | ||||
-rw-r--r-- | clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp | 5 |
6 files changed, 30 insertions, 23 deletions
diff --git a/clang/lib/Analysis/AnalysisContext.cpp b/clang/lib/Analysis/AnalysisContext.cpp index 200183a0275..3dd194b8e80 100644 --- a/clang/lib/Analysis/AnalysisContext.cpp +++ b/clang/lib/Analysis/AnalysisContext.cpp @@ -30,6 +30,8 @@ using namespace clang; +typedef llvm::DenseMap<const void *, ManagedAnalysis *> ManagedAnalysisMap; + AnalysisContext::AnalysisContext(const Decl *d, idx::TranslationUnit *tu, const CFG::BuildOptions &buildOptions) @@ -38,7 +40,8 @@ AnalysisContext::AnalysisContext(const Decl *d, forcedBlkExprs(0), builtCFG(false), builtCompleteCFG(false), - ReferencedBlockVars(0) + ReferencedBlockVars(0), + ManagedAnalyses(0) { cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs; } @@ -49,7 +52,8 @@ AnalysisContext::AnalysisContext(const Decl *d, forcedBlkExprs(0), builtCFG(false), builtCompleteCFG(false), - ReferencedBlockVars(0) + ReferencedBlockVars(0), + ManagedAnalyses(0) { cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs; } @@ -176,18 +180,6 @@ PseudoConstantAnalysis *AnalysisContext::getPseudoConstantAnalysis() { return PCA.get(); } -LiveVariables *AnalysisContext::getLiveVariables() { - if (!liveness) - liveness.reset(LiveVariables::computeLiveness(*this)); - return liveness.get(); -} - -LiveVariables *AnalysisContext::getRelaxedLiveVariables() { - if (!relaxedLiveness) - relaxedLiveness.reset(LiveVariables::computeLiveness(*this, false)); - return relaxedLiveness.get(); -} - AnalysisContext *AnalysisContextManager::getContext(const Decl *D, idx::TranslationUnit *TU) { AnalysisContext *&AC = Contexts[D]; @@ -395,13 +387,29 @@ AnalysisContext::getReferencedBlockVars(const BlockDecl *BD) { return std::make_pair(V->begin(), V->end()); } +ManagedAnalysis *&AnalysisContext::getAnalysisImpl(const void *tag) { + if (!ManagedAnalyses) + ManagedAnalyses = new ManagedAnalysisMap(); + ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses; + return (*M)[tag]; +} + //===----------------------------------------------------------------------===// // Cleanup. //===----------------------------------------------------------------------===// +ManagedAnalysis::~ManagedAnalysis() {} + AnalysisContext::~AnalysisContext() { delete forcedBlkExprs; delete ReferencedBlockVars; + // Release the managed analyses. + if (ManagedAnalyses) { + ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses; + for (ManagedAnalysisMap::iterator I = M->begin(), E = M->end(); I!=E; ++I) + delete I->second; + delete M; + } } AnalysisContextManager::~AnalysisContextManager() { diff --git a/clang/lib/Analysis/LiveVariables.cpp b/clang/lib/Analysis/LiveVariables.cpp index c800c70a38f..62c5455e0f2 100644 --- a/clang/lib/Analysis/LiveVariables.cpp +++ b/clang/lib/Analysis/LiveVariables.cpp @@ -670,3 +670,5 @@ void LiveVariablesImpl::dumpBlockLiveness(const SourceManager &M) { llvm::errs() << "\n"; } +const void *LiveVariables::getTag() { static int x; return &x; } +const void *RelaxedLiveVariables::getTag() { static int x; return &x; } diff --git a/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp index 5d272ea382d..df66aaf19ad 100644 --- a/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp @@ -348,7 +348,7 @@ class DeadStoresChecker : public Checker<check::ASTCodeBody> { public: void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, BugReporter &BR) const { - if (LiveVariables *L = mgr.getLiveVariables(D)) { + if (LiveVariables *L = mgr.getAnalysis<LiveVariables>(D)) { CFG &cfg = *mgr.getCFG(D); AnalysisContext *AC = mgr.getAnalysisContext(D); ParentMap &pmap = mgr.getParentMap(D); diff --git a/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp b/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp index 486b7f7feb1..d9d569423d3 100644 --- a/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp @@ -28,7 +28,7 @@ class LiveVariablesDumper : public Checker<check::ASTCodeBody> { public: void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, BugReporter &BR) const { - if (LiveVariables* L = mgr.getLiveVariables(D)) { + if (LiveVariables* L = mgr.getAnalysis<LiveVariables>(D)) { L->dumpBlockLiveness(mgr.getSourceManager()); } } diff --git a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp index dc3a2fe6603..b843ab1a903 100644 --- a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp @@ -382,8 +382,7 @@ bool SymbolReaper::isLive(SymbolRef sym) { } bool SymbolReaper::isLive(const Stmt *ExprVal) const { - return LCtx->getAnalysisContext()->getRelaxedLiveVariables()-> - isLive(Loc, ExprVal); + return LCtx->getAnalysis<RelaxedLiveVariables>()->isLive(Loc, ExprVal); } bool SymbolReaper::isLive(const VarRegion *VR, bool includeStoreBindings) const{ @@ -391,8 +390,7 @@ bool SymbolReaper::isLive(const VarRegion *VR, bool includeStoreBindings) const{ const StackFrameContext *CurrentContext = LCtx->getCurrentStackFrame(); if (VarContext == CurrentContext) { - if (LCtx->getAnalysisContext()->getRelaxedLiveVariables()-> - isLive(Loc, VR->getDecl())) + if (LCtx->getAnalysis<RelaxedLiveVariables>()->isLive(Loc, VR->getDecl())) return true; if (!includeStoreBindings) diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp index 876136ba685..50cbefd1425 100644 --- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -304,10 +304,9 @@ void AnalysisConsumer::HandleCode(Decl *D) { static void ActionExprEngine(AnalysisConsumer &C, AnalysisManager &mgr, Decl *D, bool ObjCGCEnabled) { - // Construct the analysis engine. We first query for the LiveVariables - // information to see if the CFG is valid. + // Construct the analysis engine. First check if the CFG is valid. // FIXME: Inter-procedural analysis will need to handle invalid CFGs. - if (!mgr.getLiveVariables(D)) + if (!mgr.getCFG(D)) return; ExprEngine Eng(mgr, ObjCGCEnabled); |