Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 1 | //== AnalysisDeclContext.cpp - Analysis context for Path Sens analysis -*- C++ -*-// |
Zhongxing Xu | 14407bf | 2009-07-30 01:17:21 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 10 | // This file defines AnalysisDeclContext, a class that manages the analysis context |
Zhongxing Xu | 14407bf | 2009-07-30 01:17:21 +0000 | [diff] [blame] | 11 | // data for path sensitive analysis. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 15 | #include "clang/Analysis/AnalysisContext.h" |
| 16 | #include "BodyFarm.h" |
Benjamin Kramer | 4ab984e | 2012-07-04 20:19:54 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Zhongxing Xu | 14407bf | 2009-07-30 01:17:21 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
| 19 | #include "clang/AST/DeclObjC.h" |
Mike Stump | 1bacb81 | 2010-01-13 02:59:54 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" |
Zhongxing Xu | 14407bf | 2009-07-30 01:17:21 +0000 | [diff] [blame] | 21 | #include "clang/AST/ParentMap.h" |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 22 | #include "clang/AST/StmtVisitor.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 23 | #include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h" |
Ted Kremenek | 575398e | 2010-03-10 00:18:11 +0000 | [diff] [blame] | 24 | #include "clang/Analysis/Analyses/LiveVariables.h" |
Tom Care | e332c3b | 2010-08-23 19:51:57 +0000 | [diff] [blame] | 25 | #include "clang/Analysis/Analyses/PseudoConstantAnalysis.h" |
Ted Kremenek | 575398e | 2010-03-10 00:18:11 +0000 | [diff] [blame] | 26 | #include "clang/Analysis/CFG.h" |
Ted Kremenek | cc7f1f8 | 2011-02-23 01:51:53 +0000 | [diff] [blame] | 27 | #include "clang/Analysis/CFGStmtMap.h" |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 28 | #include "clang/Analysis/Support/BumpVector.h" |
Benjamin Kramer | 616f802 | 2012-03-10 15:08:09 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/SmallPtrSet.h" |
Mike Stump | 5b78af9 | 2009-07-31 01:10:29 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 31 | #include "llvm/Support/SaveAndRestore.h" |
Ted Kremenek | 14f779c | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 32 | |
Zhongxing Xu | 14407bf | 2009-07-30 01:17:21 +0000 | [diff] [blame] | 33 | using namespace clang; |
| 34 | |
Ted Kremenek | dccc2b2 | 2011-10-07 22:21:02 +0000 | [diff] [blame] | 35 | typedef llvm::DenseMap<const void *, ManagedAnalysis *> ManagedAnalysisMap; |
| 36 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 37 | AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr, |
Ted Kremenek | 14f779c | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 38 | const Decl *d, |
| 39 | const CFG::BuildOptions &buildOptions) |
Ted Kremenek | 142adc4 | 2011-10-23 02:31:52 +0000 | [diff] [blame] | 40 | : Manager(Mgr), |
| 41 | D(d), |
Ted Kremenek | 189ecec | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 42 | cfgBuildOptions(buildOptions), |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 43 | forcedBlkExprs(0), |
Ted Kremenek | 189ecec | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 44 | builtCFG(false), |
| 45 | builtCompleteCFG(false), |
Ted Kremenek | dccc2b2 | 2011-10-07 22:21:02 +0000 | [diff] [blame] | 46 | ReferencedBlockVars(0), |
| 47 | ManagedAnalyses(0) |
Ted Kremenek | 189ecec | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 48 | { |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 49 | cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs; |
Ted Kremenek | 189ecec | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 52 | AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr, |
Ted Kremenek | 14f779c | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 53 | const Decl *d) |
Ted Kremenek | 142adc4 | 2011-10-23 02:31:52 +0000 | [diff] [blame] | 54 | : Manager(Mgr), |
| 55 | D(d), |
Ted Kremenek | 189ecec | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 56 | forcedBlkExprs(0), |
| 57 | builtCFG(false), |
| 58 | builtCompleteCFG(false), |
Ted Kremenek | dccc2b2 | 2011-10-07 22:21:02 +0000 | [diff] [blame] | 59 | ReferencedBlockVars(0), |
| 60 | ManagedAnalyses(0) |
Ted Kremenek | 189ecec | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 61 | { |
| 62 | cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs; |
| 63 | } |
| 64 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 65 | AnalysisDeclContextManager::AnalysisDeclContextManager(bool useUnoptimizedCFG, |
Jordan Rose | 6d671cc | 2012-09-05 22:55:23 +0000 | [diff] [blame] | 66 | bool addImplicitDtors, |
| 67 | bool addInitializers, |
Ted Kremenek | 14f779c | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 68 | bool addTemporaryDtors, |
Ted Kremenek | 233c1b0 | 2013-03-29 00:09:22 +0000 | [diff] [blame^] | 69 | bool synthesizeBodies, |
| 70 | bool addStaticInitBranch) |
Ted Kremenek | 14f779c | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 71 | : SynthesizeBodies(synthesizeBodies) |
| 72 | { |
Ted Kremenek | 189ecec | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 73 | cfgBuildOptions.PruneTriviallyFalseEdges = !useUnoptimizedCFG; |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 74 | cfgBuildOptions.AddImplicitDtors = addImplicitDtors; |
| 75 | cfgBuildOptions.AddInitializers = addInitializers; |
Jordan Rose | 6d671cc | 2012-09-05 22:55:23 +0000 | [diff] [blame] | 76 | cfgBuildOptions.AddTemporaryDtors = addTemporaryDtors; |
Ted Kremenek | 233c1b0 | 2013-03-29 00:09:22 +0000 | [diff] [blame^] | 77 | cfgBuildOptions.AddStaticInitBranches = addStaticInitBranch; |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 80 | void AnalysisDeclContextManager::clear() { |
Ted Kremenek | d45ff6c | 2009-10-20 21:39:41 +0000 | [diff] [blame] | 81 | for (ContextMap::iterator I = Contexts.begin(), E = Contexts.end(); I!=E; ++I) |
| 82 | delete I->second; |
| 83 | Contexts.clear(); |
| 84 | } |
| 85 | |
Ted Kremenek | 14f779c | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 86 | static BodyFarm &getBodyFarm(ASTContext &C) { |
| 87 | static BodyFarm *BF = new BodyFarm(C); |
| 88 | return *BF; |
| 89 | } |
| 90 | |
Anna Zaks | 00c69a5 | 2013-02-02 00:30:04 +0000 | [diff] [blame] | 91 | Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const { |
NAKAMURA Takumi | cc4aaef | 2013-02-04 05:06:21 +0000 | [diff] [blame] | 92 | IsAutosynthesized = false; |
Ted Kremenek | 14f779c | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 93 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 94 | Stmt *Body = FD->getBody(); |
Anna Zaks | 00c69a5 | 2013-02-02 00:30:04 +0000 | [diff] [blame] | 95 | if (!Body && Manager && Manager->synthesizeBodies()) { |
| 96 | IsAutosynthesized = true; |
Ted Kremenek | 14f779c | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 97 | return getBodyFarm(getASTContext()).getBody(FD); |
Anna Zaks | 00c69a5 | 2013-02-02 00:30:04 +0000 | [diff] [blame] | 98 | } |
Ted Kremenek | 14f779c | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 99 | return Body; |
| 100 | } |
Ted Kremenek | cdf5f4a | 2009-08-21 23:58:43 +0000 | [diff] [blame] | 101 | else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) |
Zhongxing Xu | 14407bf | 2009-07-30 01:17:21 +0000 | [diff] [blame] | 102 | return MD->getBody(); |
Ted Kremenek | 45805b9 | 2009-12-04 20:34:55 +0000 | [diff] [blame] | 103 | else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) |
| 104 | return BD->getBody(); |
Mike Stump | 1bacb81 | 2010-01-13 02:59:54 +0000 | [diff] [blame] | 105 | else if (const FunctionTemplateDecl *FunTmpl |
| 106 | = dyn_cast_or_null<FunctionTemplateDecl>(D)) |
| 107 | return FunTmpl->getTemplatedDecl()->getBody(); |
Zhongxing Xu | 14407bf | 2009-07-30 01:17:21 +0000 | [diff] [blame] | 108 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 109 | llvm_unreachable("unknown code decl"); |
Zhongxing Xu | 14407bf | 2009-07-30 01:17:21 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Anna Zaks | 00c69a5 | 2013-02-02 00:30:04 +0000 | [diff] [blame] | 112 | Stmt *AnalysisDeclContext::getBody() const { |
| 113 | bool Tmp; |
| 114 | return getBody(Tmp); |
| 115 | } |
| 116 | |
| 117 | bool AnalysisDeclContext::isBodyAutosynthesized() const { |
| 118 | bool Tmp; |
| 119 | getBody(Tmp); |
| 120 | return Tmp; |
| 121 | } |
| 122 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 123 | const ImplicitParamDecl *AnalysisDeclContext::getSelfDecl() const { |
Ted Kremenek | 608677a | 2009-08-21 23:25:54 +0000 | [diff] [blame] | 124 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) |
| 125 | return MD->getSelfDecl(); |
Ted Kremenek | b39fcfa | 2011-11-14 19:36:08 +0000 | [diff] [blame] | 126 | if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { |
| 127 | // See if 'self' was captured by the block. |
| 128 | for (BlockDecl::capture_const_iterator it = BD->capture_begin(), |
| 129 | et = BD->capture_end(); it != et; ++it) { |
| 130 | const VarDecl *VD = it->getVariable(); |
| 131 | if (VD->getName() == "self") |
| 132 | return dyn_cast<ImplicitParamDecl>(VD); |
| 133 | } |
| 134 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 135 | |
Ted Kremenek | 608677a | 2009-08-21 23:25:54 +0000 | [diff] [blame] | 136 | return NULL; |
| 137 | } |
| 138 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 139 | void AnalysisDeclContext::registerForcedBlockExpression(const Stmt *stmt) { |
Ted Kremenek | a099c59 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 140 | if (!forcedBlkExprs) |
| 141 | forcedBlkExprs = new CFG::BuildOptions::ForcedBlkExprs(); |
| 142 | // Default construct an entry for 'stmt'. |
Jordy Rose | 1734737 | 2011-06-10 08:49:37 +0000 | [diff] [blame] | 143 | if (const Expr *e = dyn_cast<Expr>(stmt)) |
| 144 | stmt = e->IgnoreParens(); |
Ted Kremenek | a099c59 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 145 | (void) (*forcedBlkExprs)[stmt]; |
| 146 | } |
| 147 | |
| 148 | const CFGBlock * |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 149 | AnalysisDeclContext::getBlockForRegisteredExpression(const Stmt *stmt) { |
Ted Kremenek | a099c59 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 150 | assert(forcedBlkExprs); |
Jordy Rose | 1734737 | 2011-06-10 08:49:37 +0000 | [diff] [blame] | 151 | if (const Expr *e = dyn_cast<Expr>(stmt)) |
| 152 | stmt = e->IgnoreParens(); |
Ted Kremenek | a099c59 | 2011-03-10 03:50:34 +0000 | [diff] [blame] | 153 | CFG::BuildOptions::ForcedBlkExprs::const_iterator itr = |
| 154 | forcedBlkExprs->find(stmt); |
| 155 | assert(itr != forcedBlkExprs->end()); |
| 156 | return itr->second; |
| 157 | } |
| 158 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 159 | CFG *AnalysisDeclContext::getCFG() { |
Ted Kremenek | 189ecec | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 160 | if (!cfgBuildOptions.PruneTriviallyFalseEdges) |
Ted Kremenek | 4a2b237 | 2010-08-03 00:09:51 +0000 | [diff] [blame] | 161 | return getUnoptimizedCFG(); |
| 162 | |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 163 | if (!builtCFG) { |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 164 | cfg.reset(CFG::buildCFG(D, getBody(), |
| 165 | &D->getASTContext(), cfgBuildOptions)); |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 166 | // Even when the cfg is not successfully built, we don't |
| 167 | // want to try building it again. |
| 168 | builtCFG = true; |
| 169 | } |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 170 | return cfg.get(); |
Zhongxing Xu | 14407bf | 2009-07-30 01:17:21 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 173 | CFG *AnalysisDeclContext::getUnoptimizedCFG() { |
Ted Kremenek | dc03bd0 | 2010-08-02 23:46:59 +0000 | [diff] [blame] | 174 | if (!builtCompleteCFG) { |
Ted Kremenek | 189ecec | 2011-07-21 05:22:47 +0000 | [diff] [blame] | 175 | SaveAndRestore<bool> NotPrune(cfgBuildOptions.PruneTriviallyFalseEdges, |
| 176 | false); |
| 177 | completeCFG.reset(CFG::buildCFG(D, getBody(), &D->getASTContext(), |
| 178 | cfgBuildOptions)); |
Ted Kremenek | dc03bd0 | 2010-08-02 23:46:59 +0000 | [diff] [blame] | 179 | // Even when the cfg is not successfully built, we don't |
| 180 | // want to try building it again. |
| 181 | builtCompleteCFG = true; |
| 182 | } |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 183 | return completeCFG.get(); |
Ted Kremenek | dc03bd0 | 2010-08-02 23:46:59 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 186 | CFGStmtMap *AnalysisDeclContext::getCFGStmtMap() { |
Ted Kremenek | cc7f1f8 | 2011-02-23 01:51:53 +0000 | [diff] [blame] | 187 | if (cfgStmtMap) |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 188 | return cfgStmtMap.get(); |
Ted Kremenek | cc7f1f8 | 2011-02-23 01:51:53 +0000 | [diff] [blame] | 189 | |
| 190 | if (CFG *c = getCFG()) { |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 191 | cfgStmtMap.reset(CFGStmtMap::Build(c, &getParentMap())); |
| 192 | return cfgStmtMap.get(); |
Ted Kremenek | cc7f1f8 | 2011-02-23 01:51:53 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | return 0; |
| 196 | } |
Ted Kremenek | 80861ca | 2011-02-23 01:51:59 +0000 | [diff] [blame] | 197 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 198 | CFGReverseBlockReachabilityAnalysis *AnalysisDeclContext::getCFGReachablityAnalysis() { |
Ted Kremenek | 80861ca | 2011-02-23 01:51:59 +0000 | [diff] [blame] | 199 | if (CFA) |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 200 | return CFA.get(); |
Ted Kremenek | cc7f1f8 | 2011-02-23 01:51:53 +0000 | [diff] [blame] | 201 | |
Ted Kremenek | 80861ca | 2011-02-23 01:51:59 +0000 | [diff] [blame] | 202 | if (CFG *c = getCFG()) { |
Ted Kremenek | ddc06d0 | 2011-03-19 01:00:33 +0000 | [diff] [blame] | 203 | CFA.reset(new CFGReverseBlockReachabilityAnalysis(*c)); |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 204 | return CFA.get(); |
Ted Kremenek | 80861ca | 2011-02-23 01:51:59 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | return 0; |
| 208 | } |
Ted Kremenek | cc7f1f8 | 2011-02-23 01:51:53 +0000 | [diff] [blame] | 209 | |
Ted Kremenek | 72be32a | 2011-12-22 23:33:52 +0000 | [diff] [blame] | 210 | void AnalysisDeclContext::dumpCFG(bool ShowColors) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 211 | getCFG()->dump(getASTContext().getLangOpts(), ShowColors); |
Anders Carlsson | 36ecb1f | 2011-01-16 22:05:23 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 214 | ParentMap &AnalysisDeclContext::getParentMap() { |
Jordan Rose | 25bc20f | 2012-07-26 20:04:30 +0000 | [diff] [blame] | 215 | if (!PM) { |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 216 | PM.reset(new ParentMap(getBody())); |
Jordan Rose | 25bc20f | 2012-07-26 20:04:30 +0000 | [diff] [blame] | 217 | if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(getDecl())) { |
| 218 | for (CXXConstructorDecl::init_const_iterator I = C->init_begin(), |
| 219 | E = C->init_end(); |
| 220 | I != E; ++I) { |
| 221 | PM->addStmt((*I)->getInit()); |
| 222 | } |
| 223 | } |
| 224 | } |
Zhongxing Xu | 14407bf | 2009-07-30 01:17:21 +0000 | [diff] [blame] | 225 | return *PM; |
| 226 | } |
| 227 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 228 | PseudoConstantAnalysis *AnalysisDeclContext::getPseudoConstantAnalysis() { |
Tom Care | b9933f3 | 2010-08-18 21:17:24 +0000 | [diff] [blame] | 229 | if (!PCA) |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 230 | PCA.reset(new PseudoConstantAnalysis(getBody())); |
| 231 | return PCA.get(); |
Tom Care | b9933f3 | 2010-08-18 21:17:24 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Jordy Rose | 4f8198e | 2012-04-28 01:58:08 +0000 | [diff] [blame] | 234 | AnalysisDeclContext *AnalysisDeclContextManager::getContext(const Decl *D) { |
Ted Kremenek | 14f779c | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 235 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
Ted Kremenek | 3d0ec38 | 2012-09-24 21:17:14 +0000 | [diff] [blame] | 236 | // Calling 'hasBody' replaces 'FD' in place with the FunctionDecl |
| 237 | // that has the body. |
Ted Kremenek | 14f779c | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 238 | FD->hasBody(FD); |
| 239 | D = FD; |
| 240 | } |
| 241 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 242 | AnalysisDeclContext *&AC = Contexts[D]; |
Ted Kremenek | cdf5f4a | 2009-08-21 23:58:43 +0000 | [diff] [blame] | 243 | if (!AC) |
Jordy Rose | 4f8198e | 2012-04-28 01:58:08 +0000 | [diff] [blame] | 244 | AC = new AnalysisDeclContext(this, D, cfgBuildOptions); |
Ted Kremenek | cdf5f4a | 2009-08-21 23:58:43 +0000 | [diff] [blame] | 245 | return AC; |
Zhongxing Xu | 14407bf | 2009-07-30 01:17:21 +0000 | [diff] [blame] | 246 | } |
Zhongxing Xu | 9ad0b46 | 2009-08-03 07:23:22 +0000 | [diff] [blame] | 247 | |
Ted Kremenek | 142adc4 | 2011-10-23 02:31:52 +0000 | [diff] [blame] | 248 | const StackFrameContext * |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 249 | AnalysisDeclContext::getStackFrame(LocationContext const *Parent, const Stmt *S, |
Ted Kremenek | 142adc4 | 2011-10-23 02:31:52 +0000 | [diff] [blame] | 250 | const CFGBlock *Blk, unsigned Idx) { |
| 251 | return getLocationContextManager().getStackFrame(this, Parent, S, Blk, Idx); |
| 252 | } |
| 253 | |
Ted Kremenek | c3da376 | 2012-06-01 20:04:04 +0000 | [diff] [blame] | 254 | const BlockInvocationContext * |
| 255 | AnalysisDeclContext::getBlockInvocationContext(const LocationContext *parent, |
| 256 | const clang::BlockDecl *BD, |
| 257 | const void *ContextData) { |
| 258 | return getLocationContextManager().getBlockInvocationContext(this, parent, |
| 259 | BD, ContextData); |
| 260 | } |
| 261 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 262 | LocationContextManager & AnalysisDeclContext::getLocationContextManager() { |
Ted Kremenek | 142adc4 | 2011-10-23 02:31:52 +0000 | [diff] [blame] | 263 | assert(Manager && |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 264 | "Cannot create LocationContexts without an AnalysisDeclContextManager!"); |
Ted Kremenek | 142adc4 | 2011-10-23 02:31:52 +0000 | [diff] [blame] | 265 | return Manager->getLocationContextManager(); |
| 266 | } |
| 267 | |
Ted Kremenek | 2538824 | 2009-12-04 00:50:10 +0000 | [diff] [blame] | 268 | //===----------------------------------------------------------------------===// |
| 269 | // FoldingSet profiling. |
| 270 | //===----------------------------------------------------------------------===// |
| 271 | |
Ted Kremenek | 2538824 | 2009-12-04 00:50:10 +0000 | [diff] [blame] | 272 | void LocationContext::ProfileCommon(llvm::FoldingSetNodeID &ID, |
| 273 | ContextKind ck, |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 274 | AnalysisDeclContext *ctx, |
Ted Kremenek | 2538824 | 2009-12-04 00:50:10 +0000 | [diff] [blame] | 275 | const LocationContext *parent, |
Ted Kremenek | 5ef32db | 2011-08-12 23:37:29 +0000 | [diff] [blame] | 276 | const void *data) { |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 277 | ID.AddInteger(ck); |
| 278 | ID.AddPointer(ctx); |
| 279 | ID.AddPointer(parent); |
Ted Kremenek | 2538824 | 2009-12-04 00:50:10 +0000 | [diff] [blame] | 280 | ID.AddPointer(data); |
Zhongxing Xu | 9ad0b46 | 2009-08-03 07:23:22 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Ted Kremenek | 2538824 | 2009-12-04 00:50:10 +0000 | [diff] [blame] | 283 | void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID) { |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 284 | Profile(ID, getAnalysisDeclContext(), getParent(), CallSite, Block, Index); |
Zhongxing Xu | 9ad0b46 | 2009-08-03 07:23:22 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Ted Kremenek | 2538824 | 2009-12-04 00:50:10 +0000 | [diff] [blame] | 287 | void ScopeContext::Profile(llvm::FoldingSetNodeID &ID) { |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 288 | Profile(ID, getAnalysisDeclContext(), getParent(), Enter); |
Ted Kremenek | 2538824 | 2009-12-04 00:50:10 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) { |
Ted Kremenek | c3da376 | 2012-06-01 20:04:04 +0000 | [diff] [blame] | 292 | Profile(ID, getAnalysisDeclContext(), getParent(), BD, ContextData); |
Ted Kremenek | 2538824 | 2009-12-04 00:50:10 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 296 | // LocationContext creation. |
Ted Kremenek | 2538824 | 2009-12-04 00:50:10 +0000 | [diff] [blame] | 297 | //===----------------------------------------------------------------------===// |
| 298 | |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 299 | template <typename LOC, typename DATA> |
| 300 | const LOC* |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 301 | LocationContextManager::getLocationContext(AnalysisDeclContext *ctx, |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 302 | const LocationContext *parent, |
| 303 | const DATA *d) { |
| 304 | llvm::FoldingSetNodeID ID; |
| 305 | LOC::Profile(ID, ctx, parent, d); |
| 306 | void *InsertPos; |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 307 | |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 308 | LOC *L = cast_or_null<LOC>(Contexts.FindNodeOrInsertPos(ID, InsertPos)); |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 309 | |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 310 | if (!L) { |
| 311 | L = new LOC(ctx, parent, d); |
| 312 | Contexts.InsertNode(L, InsertPos); |
| 313 | } |
| 314 | return L; |
Ted Kremenek | d45ff6c | 2009-10-20 21:39:41 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 317 | const StackFrameContext* |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 318 | LocationContextManager::getStackFrame(AnalysisDeclContext *ctx, |
Ted Kremenek | 00aeae9 | 2009-08-21 23:39:58 +0000 | [diff] [blame] | 319 | const LocationContext *parent, |
Ted Kremenek | 8219b82 | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 320 | const Stmt *s, |
Zhongxing Xu | a1a9ba1 | 2010-11-24 13:08:51 +0000 | [diff] [blame] | 321 | const CFGBlock *blk, unsigned idx) { |
Zhongxing Xu | 51f1ca8 | 2009-12-24 03:34:38 +0000 | [diff] [blame] | 322 | llvm::FoldingSetNodeID ID; |
Ted Kremenek | 8219b82 | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 323 | StackFrameContext::Profile(ID, ctx, parent, s, blk, idx); |
Zhongxing Xu | 51f1ca8 | 2009-12-24 03:34:38 +0000 | [diff] [blame] | 324 | void *InsertPos; |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 325 | StackFrameContext *L = |
Zhongxing Xu | 51f1ca8 | 2009-12-24 03:34:38 +0000 | [diff] [blame] | 326 | cast_or_null<StackFrameContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos)); |
| 327 | if (!L) { |
Ted Kremenek | 8219b82 | 2010-12-16 07:46:53 +0000 | [diff] [blame] | 328 | L = new StackFrameContext(ctx, parent, s, blk, idx); |
Zhongxing Xu | 51f1ca8 | 2009-12-24 03:34:38 +0000 | [diff] [blame] | 329 | Contexts.InsertNode(L, InsertPos); |
| 330 | } |
| 331 | return L; |
Zhongxing Xu | 9ad0b46 | 2009-08-03 07:23:22 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 334 | const ScopeContext * |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 335 | LocationContextManager::getScope(AnalysisDeclContext *ctx, |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 336 | const LocationContext *parent, |
| 337 | const Stmt *s) { |
| 338 | return getLocationContext<ScopeContext, Stmt>(ctx, parent, s); |
| 339 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 340 | |
Ted Kremenek | c3da376 | 2012-06-01 20:04:04 +0000 | [diff] [blame] | 341 | const BlockInvocationContext * |
| 342 | LocationContextManager::getBlockInvocationContext(AnalysisDeclContext *ctx, |
| 343 | const LocationContext *parent, |
| 344 | const BlockDecl *BD, |
| 345 | const void *ContextData) { |
| 346 | llvm::FoldingSetNodeID ID; |
| 347 | BlockInvocationContext::Profile(ID, ctx, parent, BD, ContextData); |
| 348 | void *InsertPos; |
| 349 | BlockInvocationContext *L = |
| 350 | cast_or_null<BlockInvocationContext>(Contexts.FindNodeOrInsertPos(ID, |
| 351 | InsertPos)); |
| 352 | if (!L) { |
| 353 | L = new BlockInvocationContext(ctx, parent, BD, ContextData); |
| 354 | Contexts.InsertNode(L, InsertPos); |
| 355 | } |
| 356 | return L; |
| 357 | } |
| 358 | |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 359 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 04af9f2 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 360 | // LocationContext methods. |
| 361 | //===----------------------------------------------------------------------===// |
| 362 | |
| 363 | const StackFrameContext *LocationContext::getCurrentStackFrame() const { |
| 364 | const LocationContext *LC = this; |
| 365 | while (LC) { |
| 366 | if (const StackFrameContext *SFC = dyn_cast<StackFrameContext>(LC)) |
| 367 | return SFC; |
| 368 | LC = LC->getParent(); |
| 369 | } |
| 370 | return NULL; |
| 371 | } |
| 372 | |
Anna Zaks | 44dc91b | 2012-11-03 02:54:16 +0000 | [diff] [blame] | 373 | bool LocationContext::inTopFrame() const { |
| 374 | return getCurrentStackFrame()->inTopFrame(); |
| 375 | } |
| 376 | |
Zhongxing Xu | 86bab2c | 2010-02-17 08:45:06 +0000 | [diff] [blame] | 377 | bool LocationContext::isParentOf(const LocationContext *LC) const { |
| 378 | do { |
| 379 | const LocationContext *Parent = LC->getParent(); |
| 380 | if (Parent == this) |
| 381 | return true; |
| 382 | else |
| 383 | LC = Parent; |
| 384 | } while (LC); |
| 385 | |
| 386 | return false; |
| 387 | } |
| 388 | |
Ted Kremenek | 04af9f2 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 389 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 390 | // Lazily generated map to query the external variables referenced by a Block. |
| 391 | //===----------------------------------------------------------------------===// |
| 392 | |
| 393 | namespace { |
| 394 | class FindBlockDeclRefExprsVals : public StmtVisitor<FindBlockDeclRefExprsVals>{ |
| 395 | BumpVector<const VarDecl*> &BEVals; |
| 396 | BumpVectorContext &BC; |
Benjamin Kramer | 616f802 | 2012-03-10 15:08:09 +0000 | [diff] [blame] | 397 | llvm::SmallPtrSet<const VarDecl*, 4> Visited; |
| 398 | llvm::SmallPtrSet<const DeclContext*, 4> IgnoredContexts; |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 399 | public: |
| 400 | FindBlockDeclRefExprsVals(BumpVector<const VarDecl*> &bevals, |
| 401 | BumpVectorContext &bc) |
| 402 | : BEVals(bevals), BC(bc) {} |
Ted Kremenek | 575398e | 2010-03-10 00:18:11 +0000 | [diff] [blame] | 403 | |
| 404 | bool IsTrackedDecl(const VarDecl *VD) { |
| 405 | const DeclContext *DC = VD->getDeclContext(); |
| 406 | return IgnoredContexts.count(DC) == 0; |
| 407 | } |
| 408 | |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 409 | void VisitStmt(Stmt *S) { |
John McCall | 8322c3a | 2011-02-13 04:07:26 +0000 | [diff] [blame] | 410 | for (Stmt::child_range I = S->children(); I; ++I) |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 411 | if (Stmt *child = *I) |
| 412 | Visit(child); |
| 413 | } |
Ted Kremenek | 5abd69d | 2010-02-06 00:30:00 +0000 | [diff] [blame] | 414 | |
Ted Kremenek | 299cfb7 | 2011-12-22 01:30:46 +0000 | [diff] [blame] | 415 | void VisitDeclRefExpr(DeclRefExpr *DR) { |
Ted Kremenek | 5abd69d | 2010-02-06 00:30:00 +0000 | [diff] [blame] | 416 | // Non-local variables are also directly modified. |
Benjamin Kramer | 616f802 | 2012-03-10 15:08:09 +0000 | [diff] [blame] | 417 | if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) { |
Ted Kremenek | 5abd69d | 2010-02-06 00:30:00 +0000 | [diff] [blame] | 418 | if (!VD->hasLocalStorage()) { |
Benjamin Kramer | 616f802 | 2012-03-10 15:08:09 +0000 | [diff] [blame] | 419 | if (Visited.insert(VD)) |
Ted Kremenek | 5abd69d | 2010-02-06 00:30:00 +0000 | [diff] [blame] | 420 | BEVals.push_back(VD, BC); |
Ted Kremenek | 5abd69d | 2010-02-06 00:30:00 +0000 | [diff] [blame] | 421 | } |
Benjamin Kramer | 616f802 | 2012-03-10 15:08:09 +0000 | [diff] [blame] | 422 | } |
Ted Kremenek | 5abd69d | 2010-02-06 00:30:00 +0000 | [diff] [blame] | 423 | } |
Ted Kremenek | 575398e | 2010-03-10 00:18:11 +0000 | [diff] [blame] | 424 | |
Ted Kremenek | 575398e | 2010-03-10 00:18:11 +0000 | [diff] [blame] | 425 | void VisitBlockExpr(BlockExpr *BR) { |
| 426 | // Blocks containing blocks can transitively capture more variables. |
| 427 | IgnoredContexts.insert(BR->getBlockDecl()); |
| 428 | Visit(BR->getBlockDecl()->getBody()); |
| 429 | } |
Ted Kremenek | 299cfb7 | 2011-12-22 01:30:46 +0000 | [diff] [blame] | 430 | |
| 431 | void VisitPseudoObjectExpr(PseudoObjectExpr *PE) { |
| 432 | for (PseudoObjectExpr::semantics_iterator it = PE->semantics_begin(), |
| 433 | et = PE->semantics_end(); it != et; ++it) { |
| 434 | Expr *Semantic = *it; |
| 435 | if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Semantic)) |
| 436 | Semantic = OVE->getSourceExpr(); |
| 437 | Visit(Semantic); |
| 438 | } |
| 439 | } |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 440 | }; |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 441 | } // end anonymous namespace |
| 442 | |
| 443 | typedef BumpVector<const VarDecl*> DeclVec; |
| 444 | |
| 445 | static DeclVec* LazyInitializeReferencedDecls(const BlockDecl *BD, |
| 446 | void *&Vec, |
| 447 | llvm::BumpPtrAllocator &A) { |
| 448 | if (Vec) |
| 449 | return (DeclVec*) Vec; |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 450 | |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 451 | BumpVectorContext BC(A); |
| 452 | DeclVec *BV = (DeclVec*) A.Allocate<DeclVec>(); |
| 453 | new (BV) DeclVec(BC, 10); |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 454 | |
Ted Kremenek | 3e871d8 | 2012-12-06 07:17:26 +0000 | [diff] [blame] | 455 | // Go through the capture list. |
| 456 | for (BlockDecl::capture_const_iterator CI = BD->capture_begin(), |
| 457 | CE = BD->capture_end(); CI != CE; ++CI) { |
| 458 | BV->push_back(CI->getVariable(), BC); |
| 459 | } |
| 460 | |
| 461 | // Find the referenced global/static variables. |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 462 | FindBlockDeclRefExprsVals F(*BV, BC); |
| 463 | F.Visit(BD->getBody()); |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 464 | |
| 465 | Vec = BV; |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 466 | return BV; |
| 467 | } |
| 468 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 469 | std::pair<AnalysisDeclContext::referenced_decls_iterator, |
| 470 | AnalysisDeclContext::referenced_decls_iterator> |
| 471 | AnalysisDeclContext::getReferencedBlockVars(const BlockDecl *BD) { |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 472 | if (!ReferencedBlockVars) |
| 473 | ReferencedBlockVars = new llvm::DenseMap<const BlockDecl*,void*>(); |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 474 | |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 475 | DeclVec *V = LazyInitializeReferencedDecls(BD, (*ReferencedBlockVars)[BD], A); |
| 476 | return std::make_pair(V->begin(), V->end()); |
| 477 | } |
| 478 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 479 | ManagedAnalysis *&AnalysisDeclContext::getAnalysisImpl(const void *tag) { |
Ted Kremenek | dccc2b2 | 2011-10-07 22:21:02 +0000 | [diff] [blame] | 480 | if (!ManagedAnalyses) |
| 481 | ManagedAnalyses = new ManagedAnalysisMap(); |
| 482 | ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses; |
| 483 | return (*M)[tag]; |
| 484 | } |
| 485 | |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 486 | //===----------------------------------------------------------------------===// |
| 487 | // Cleanup. |
| 488 | //===----------------------------------------------------------------------===// |
| 489 | |
Ted Kremenek | dccc2b2 | 2011-10-07 22:21:02 +0000 | [diff] [blame] | 490 | ManagedAnalysis::~ManagedAnalysis() {} |
| 491 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 492 | AnalysisDeclContext::~AnalysisDeclContext() { |
Ted Kremenek | f9d8290 | 2011-03-10 01:14:05 +0000 | [diff] [blame] | 493 | delete forcedBlkExprs; |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 494 | delete ReferencedBlockVars; |
Ted Kremenek | dccc2b2 | 2011-10-07 22:21:02 +0000 | [diff] [blame] | 495 | // Release the managed analyses. |
| 496 | if (ManagedAnalyses) { |
| 497 | ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses; |
| 498 | for (ManagedAnalysisMap::iterator I = M->begin(), E = M->end(); I!=E; ++I) |
| 499 | delete I->second; |
| 500 | delete M; |
| 501 | } |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Ted Kremenek | 81ce1c8 | 2011-10-24 01:32:45 +0000 | [diff] [blame] | 504 | AnalysisDeclContextManager::~AnalysisDeclContextManager() { |
Ted Kremenek | 0f5e6f88 | 2009-11-26 02:31:33 +0000 | [diff] [blame] | 505 | for (ContextMap::iterator I = Contexts.begin(), E = Contexts.end(); I!=E; ++I) |
| 506 | delete I->second; |
| 507 | } |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 508 | |
| 509 | LocationContext::~LocationContext() {} |
| 510 | |
| 511 | LocationContextManager::~LocationContextManager() { |
| 512 | clear(); |
| 513 | } |
| 514 | |
| 515 | void LocationContextManager::clear() { |
| 516 | for (llvm::FoldingSet<LocationContext>::iterator I = Contexts.begin(), |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 517 | E = Contexts.end(); I != E; ) { |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 518 | LocationContext *LC = &*I; |
| 519 | ++I; |
| 520 | delete LC; |
| 521 | } |
Ted Kremenek | 0b40532 | 2010-03-23 00:13:23 +0000 | [diff] [blame] | 522 | |
Ted Kremenek | 43d4a89 | 2009-12-04 01:28:56 +0000 | [diff] [blame] | 523 | Contexts.clear(); |
| 524 | } |
| 525 | |