blob: 461468de92b1734ea6ee74a07943a82a18a12152 [file] [log] [blame]
Zhongxing Xu97ab3942009-07-30 01:17:21 +00001//== AnalysisContext.cpp - Analysis context for Path Sens analysis -*- C++ -*-//
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//
10// This file defines AnalysisContext, a class that manages the analysis context
11// data for path sensitive analysis.
12//
13//===----------------------------------------------------------------------===//
14
Zhongxing Xu97ab3942009-07-30 01:17:21 +000015#include "clang/AST/Decl.h"
16#include "clang/AST/DeclObjC.h"
Mike Stumpfa6ef182010-01-13 02:59:54 +000017#include "clang/AST/DeclTemplate.h"
Zhongxing Xu97ab3942009-07-30 01:17:21 +000018#include "clang/AST/ParentMap.h"
Ted Kremenekb1a7b652009-11-26 02:31:33 +000019#include "clang/AST/StmtVisitor.h"
Ted Kremenek2cfe28b2010-03-10 00:18:11 +000020#include "clang/Analysis/Analyses/LiveVariables.h"
Tom Caredb34ab72010-08-23 19:51:57 +000021#include "clang/Analysis/Analyses/PseudoConstantAnalysis.h"
Ted Kremenek42461ee2011-02-23 01:51:59 +000022#include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
Ted Kremenek2cfe28b2010-03-10 00:18:11 +000023#include "clang/Analysis/AnalysisContext.h"
24#include "clang/Analysis/CFG.h"
Ted Kremenek283a3582011-02-23 01:51:53 +000025#include "clang/Analysis/CFGStmtMap.h"
Ted Kremenekb1a7b652009-11-26 02:31:33 +000026#include "clang/Analysis/Support/BumpVector.h"
Ted Kremenek2cfe28b2010-03-10 00:18:11 +000027#include "llvm/ADT/SmallSet.h"
Mike Stump87a05f12009-07-31 01:10:29 +000028#include "llvm/Support/ErrorHandling.h"
Zhongxing Xu97ab3942009-07-30 01:17:21 +000029
30using namespace clang;
31
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +000032AnalysisContext::AnalysisContext(const Decl *d,
33 idx::TranslationUnit *tu,
34 bool useUnoptimizedCFG,
35 bool addehedges,
36 bool addImplicitDtors,
37 bool addInitializers)
38 : D(d), TU(tu),
39 forcedBlkExprs(0),
40 builtCFG(false), builtCompleteCFG(false),
41 useUnoptimizedCFG(useUnoptimizedCFG),
42 ReferencedBlockVars(0)
43{
44 cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
45 cfgBuildOptions.AddEHEdges = addehedges;
46 cfgBuildOptions.AddImplicitDtors = addImplicitDtors;
47 cfgBuildOptions.AddInitializers = addInitializers;
48}
49
Ted Kremenek58f5ec72009-10-20 21:39:41 +000050void AnalysisContextManager::clear() {
51 for (ContextMap::iterator I = Contexts.begin(), E = Contexts.end(); I!=E; ++I)
52 delete I->second;
53 Contexts.clear();
54}
55
Zhongxing Xu97ab3942009-07-30 01:17:21 +000056Stmt *AnalysisContext::getBody() {
Ted Kremenek23760022009-08-21 23:58:43 +000057 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
Zhongxing Xu97ab3942009-07-30 01:17:21 +000058 return FD->getBody();
Ted Kremenek23760022009-08-21 23:58:43 +000059 else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
Zhongxing Xu97ab3942009-07-30 01:17:21 +000060 return MD->getBody();
Ted Kremenek30a45342009-12-04 20:34:55 +000061 else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D))
62 return BD->getBody();
Mike Stumpfa6ef182010-01-13 02:59:54 +000063 else if (const FunctionTemplateDecl *FunTmpl
64 = dyn_cast_or_null<FunctionTemplateDecl>(D))
65 return FunTmpl->getTemplatedDecl()->getBody();
Zhongxing Xu97ab3942009-07-30 01:17:21 +000066
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +000067 llvm_unreachable("unknown code decl");
Zhongxing Xu97ab3942009-07-30 01:17:21 +000068}
69
Ted Kremenek82cd37c2009-08-21 23:25:54 +000070const ImplicitParamDecl *AnalysisContext::getSelfDecl() const {
71 if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
72 return MD->getSelfDecl();
Mike Stump1eb44332009-09-09 15:08:12 +000073
Ted Kremenek82cd37c2009-08-21 23:25:54 +000074 return NULL;
75}
76
Ted Kremenek0d28d362011-03-10 03:50:34 +000077void AnalysisContext::registerForcedBlockExpression(const Stmt *stmt) {
78 if (!forcedBlkExprs)
79 forcedBlkExprs = new CFG::BuildOptions::ForcedBlkExprs();
80 // Default construct an entry for 'stmt'.
81 if (const ParenExpr *pe = dyn_cast<ParenExpr>(stmt))
82 stmt = pe->IgnoreParens();
83 (void) (*forcedBlkExprs)[stmt];
84}
85
86const CFGBlock *
87AnalysisContext::getBlockForRegisteredExpression(const Stmt *stmt) {
88 assert(forcedBlkExprs);
89 if (const ParenExpr *pe = dyn_cast<ParenExpr>(stmt))
90 stmt = pe->IgnoreParens();
91 CFG::BuildOptions::ForcedBlkExprs::const_iterator itr =
92 forcedBlkExprs->find(stmt);
93 assert(itr != forcedBlkExprs->end());
94 return itr->second;
95}
96
Zhongxing Xu97ab3942009-07-30 01:17:21 +000097CFG *AnalysisContext::getCFG() {
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +000098 if (useUnoptimizedCFG)
Ted Kremenek9b823e82010-08-03 00:09:51 +000099 return getUnoptimizedCFG();
100
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000101 if (!builtCFG) {
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000102 cfg.reset(CFG::buildCFG(D, getBody(),
103 &D->getASTContext(), cfgBuildOptions));
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000104 // Even when the cfg is not successfully built, we don't
105 // want to try building it again.
106 builtCFG = true;
107 }
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000108 return cfg.get();
Zhongxing Xu97ab3942009-07-30 01:17:21 +0000109}
110
Ted Kremenekad5a8942010-08-02 23:46:59 +0000111CFG *AnalysisContext::getUnoptimizedCFG() {
112 if (!builtCompleteCFG) {
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000113 CFG::BuildOptions B = cfgBuildOptions;
Ted Kremenek6c52c782010-09-14 23:41:16 +0000114 B.PruneTriviallyFalseEdges = false;
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000115 completeCFG.reset(CFG::buildCFG(D, getBody(), &D->getASTContext(), B));
Ted Kremenekad5a8942010-08-02 23:46:59 +0000116 // Even when the cfg is not successfully built, we don't
117 // want to try building it again.
118 builtCompleteCFG = true;
119 }
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000120 return completeCFG.get();
Ted Kremenekad5a8942010-08-02 23:46:59 +0000121}
122
Ted Kremenek283a3582011-02-23 01:51:53 +0000123CFGStmtMap *AnalysisContext::getCFGStmtMap() {
124 if (cfgStmtMap)
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000125 return cfgStmtMap.get();
Ted Kremenek283a3582011-02-23 01:51:53 +0000126
127 if (CFG *c = getCFG()) {
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000128 cfgStmtMap.reset(CFGStmtMap::Build(c, &getParentMap()));
129 return cfgStmtMap.get();
Ted Kremenek283a3582011-02-23 01:51:53 +0000130 }
131
132 return 0;
133}
Ted Kremenek42461ee2011-02-23 01:51:59 +0000134
135CFGReachabilityAnalysis *AnalysisContext::getCFGReachablityAnalysis() {
136 if (CFA)
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000137 return CFA.get();
Ted Kremenek283a3582011-02-23 01:51:53 +0000138
Ted Kremenek42461ee2011-02-23 01:51:59 +0000139 if (CFG *c = getCFG()) {
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000140 CFA.reset(new CFGReachabilityAnalysis(*c));
141 return CFA.get();
Ted Kremenek42461ee2011-02-23 01:51:59 +0000142 }
143
144 return 0;
145}
Ted Kremenek283a3582011-02-23 01:51:53 +0000146
Anders Carlsson04eeba42011-01-16 22:05:23 +0000147void AnalysisContext::dumpCFG() {
148 getCFG()->dump(getASTContext().getLangOptions());
149}
150
Zhongxing Xu97ab3942009-07-30 01:17:21 +0000151ParentMap &AnalysisContext::getParentMap() {
Mike Stump1eb44332009-09-09 15:08:12 +0000152 if (!PM)
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000153 PM.reset(new ParentMap(getBody()));
Zhongxing Xu97ab3942009-07-30 01:17:21 +0000154 return *PM;
155}
156
Tom Caredb34ab72010-08-23 19:51:57 +0000157PseudoConstantAnalysis *AnalysisContext::getPseudoConstantAnalysis() {
Tom Care245adab2010-08-18 21:17:24 +0000158 if (!PCA)
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000159 PCA.reset(new PseudoConstantAnalysis(getBody()));
160 return PCA.get();
Tom Care245adab2010-08-18 21:17:24 +0000161}
162
Zhongxing Xu97ab3942009-07-30 01:17:21 +0000163LiveVariables *AnalysisContext::getLiveVariables() {
164 if (!liveness) {
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000165 if (CFG *c = getCFG()) {
166 liveness.reset(new LiveVariables(*this));
167 liveness->runOnCFG(*c);
168 liveness->runOnAllBlocks(*c, 0, true);
169 }
Zhongxing Xu97ab3942009-07-30 01:17:21 +0000170 }
Mike Stump1eb44332009-09-09 15:08:12 +0000171
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000172 return liveness.get();
Zhongxing Xu97ab3942009-07-30 01:17:21 +0000173}
174
Tom Careec49bf42010-08-27 22:30:10 +0000175LiveVariables *AnalysisContext::getRelaxedLiveVariables() {
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000176 if (!relaxedLiveness)
177 if (CFG *c = getCFG()) {
178 relaxedLiveness.reset(new LiveVariables(*this, false));
179 relaxedLiveness->runOnCFG(*c);
180 relaxedLiveness->runOnAllBlocks(*c, 0, true);
181 }
Tom Careec49bf42010-08-27 22:30:10 +0000182
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000183 return relaxedLiveness.get();
Tom Careec49bf42010-08-27 22:30:10 +0000184}
185
Zhongxing Xuc6238d22010-07-19 01:31:21 +0000186AnalysisContext *AnalysisContextManager::getContext(const Decl *D,
Zhongxing Xu2ce43c82010-07-22 13:52:13 +0000187 idx::TranslationUnit *TU) {
Ted Kremenek23760022009-08-21 23:58:43 +0000188 AnalysisContext *&AC = Contexts[D];
189 if (!AC)
Marcin Swiderski9121ba22010-09-30 07:41:24 +0000190 AC = new AnalysisContext(D, TU, UseUnoptimizedCFG, false,
191 AddImplicitDtors, AddInitializers);
Mike Stump1eb44332009-09-09 15:08:12 +0000192
Ted Kremenek23760022009-08-21 23:58:43 +0000193 return AC;
Zhongxing Xu97ab3942009-07-30 01:17:21 +0000194}
Zhongxing Xu18c7c062009-08-03 07:23:22 +0000195
Ted Kremenekdc0d9092009-12-04 00:50:10 +0000196//===----------------------------------------------------------------------===//
197// FoldingSet profiling.
198//===----------------------------------------------------------------------===//
199
Ted Kremenekdc0d9092009-12-04 00:50:10 +0000200void LocationContext::ProfileCommon(llvm::FoldingSetNodeID &ID,
201 ContextKind ck,
202 AnalysisContext *ctx,
203 const LocationContext *parent,
204 const void* data) {
Ted Kremenek0ee41242009-12-04 01:28:56 +0000205 ID.AddInteger(ck);
206 ID.AddPointer(ctx);
207 ID.AddPointer(parent);
Ted Kremenekdc0d9092009-12-04 00:50:10 +0000208 ID.AddPointer(data);
Zhongxing Xu18c7c062009-08-03 07:23:22 +0000209}
210
Ted Kremenekdc0d9092009-12-04 00:50:10 +0000211void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID) {
Ted Kremenek892697d2010-12-16 07:46:53 +0000212 Profile(ID, getAnalysisContext(), getParent(), CallSite, Block, Index);
Zhongxing Xu18c7c062009-08-03 07:23:22 +0000213}
214
Ted Kremenekdc0d9092009-12-04 00:50:10 +0000215void ScopeContext::Profile(llvm::FoldingSetNodeID &ID) {
216 Profile(ID, getAnalysisContext(), getParent(), Enter);
217}
218
219void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) {
Ted Kremenek1309f9a2010-01-25 04:41:41 +0000220 Profile(ID, getAnalysisContext(), getParent(), BD);
Ted Kremenekdc0d9092009-12-04 00:50:10 +0000221}
222
223//===----------------------------------------------------------------------===//
Ted Kremenek0ee41242009-12-04 01:28:56 +0000224// LocationContext creation.
Ted Kremenekdc0d9092009-12-04 00:50:10 +0000225//===----------------------------------------------------------------------===//
226
Ted Kremenek0ee41242009-12-04 01:28:56 +0000227template <typename LOC, typename DATA>
228const LOC*
229LocationContextManager::getLocationContext(AnalysisContext *ctx,
230 const LocationContext *parent,
231 const DATA *d) {
232 llvm::FoldingSetNodeID ID;
233 LOC::Profile(ID, ctx, parent, d);
234 void *InsertPos;
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000235
Ted Kremenek0ee41242009-12-04 01:28:56 +0000236 LOC *L = cast_or_null<LOC>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000237
Ted Kremenek0ee41242009-12-04 01:28:56 +0000238 if (!L) {
239 L = new LOC(ctx, parent, d);
240 Contexts.InsertNode(L, InsertPos);
241 }
242 return L;
Ted Kremenek58f5ec72009-10-20 21:39:41 +0000243}
244
Ted Kremenek0ee41242009-12-04 01:28:56 +0000245const StackFrameContext*
Mike Stump1eb44332009-09-09 15:08:12 +0000246LocationContextManager::getStackFrame(AnalysisContext *ctx,
Ted Kremenek54c809b2009-08-21 23:39:58 +0000247 const LocationContext *parent,
Ted Kremenek892697d2010-12-16 07:46:53 +0000248 const Stmt *s,
Zhongxing Xud7064342010-11-24 13:08:51 +0000249 const CFGBlock *blk, unsigned idx) {
Zhongxing Xu62d399e2009-12-24 03:34:38 +0000250 llvm::FoldingSetNodeID ID;
Ted Kremenek892697d2010-12-16 07:46:53 +0000251 StackFrameContext::Profile(ID, ctx, parent, s, blk, idx);
Zhongxing Xu62d399e2009-12-24 03:34:38 +0000252 void *InsertPos;
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000253 StackFrameContext *L =
Zhongxing Xu62d399e2009-12-24 03:34:38 +0000254 cast_or_null<StackFrameContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
255 if (!L) {
Ted Kremenek892697d2010-12-16 07:46:53 +0000256 L = new StackFrameContext(ctx, parent, s, blk, idx);
Zhongxing Xu62d399e2009-12-24 03:34:38 +0000257 Contexts.InsertNode(L, InsertPos);
258 }
259 return L;
Zhongxing Xu18c7c062009-08-03 07:23:22 +0000260}
261
Ted Kremenek0ee41242009-12-04 01:28:56 +0000262const ScopeContext *
263LocationContextManager::getScope(AnalysisContext *ctx,
264 const LocationContext *parent,
265 const Stmt *s) {
266 return getLocationContext<ScopeContext, Stmt>(ctx, parent, s);
267}
Mike Stump1eb44332009-09-09 15:08:12 +0000268
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000269//===----------------------------------------------------------------------===//
Ted Kremenek67d12872009-12-07 22:05:27 +0000270// LocationContext methods.
271//===----------------------------------------------------------------------===//
272
273const StackFrameContext *LocationContext::getCurrentStackFrame() const {
274 const LocationContext *LC = this;
275 while (LC) {
276 if (const StackFrameContext *SFC = dyn_cast<StackFrameContext>(LC))
277 return SFC;
278 LC = LC->getParent();
279 }
280 return NULL;
281}
282
Ted Kremenek2b87ae42009-12-11 06:43:27 +0000283const StackFrameContext *
284LocationContext::getStackFrameForDeclContext(const DeclContext *DC) const {
285 const LocationContext *LC = this;
286 while (LC) {
287 if (const StackFrameContext *SFC = dyn_cast<StackFrameContext>(LC)) {
288 if (cast<DeclContext>(SFC->getDecl()) == DC)
289 return SFC;
290 }
291 LC = LC->getParent();
292 }
293 return NULL;
294}
295
Zhongxing Xu8ddf7ce2010-02-17 08:45:06 +0000296bool LocationContext::isParentOf(const LocationContext *LC) const {
297 do {
298 const LocationContext *Parent = LC->getParent();
299 if (Parent == this)
300 return true;
301 else
302 LC = Parent;
303 } while (LC);
304
305 return false;
306}
307
Ted Kremenek67d12872009-12-07 22:05:27 +0000308//===----------------------------------------------------------------------===//
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000309// Lazily generated map to query the external variables referenced by a Block.
310//===----------------------------------------------------------------------===//
311
312namespace {
313class FindBlockDeclRefExprsVals : public StmtVisitor<FindBlockDeclRefExprsVals>{
314 BumpVector<const VarDecl*> &BEVals;
315 BumpVectorContext &BC;
Ted Kremenek85248732010-02-06 00:30:00 +0000316 llvm::DenseMap<const VarDecl*, unsigned> Visited;
Ted Kremenek2cfe28b2010-03-10 00:18:11 +0000317 llvm::SmallSet<const DeclContext*, 4> IgnoredContexts;
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000318public:
319 FindBlockDeclRefExprsVals(BumpVector<const VarDecl*> &bevals,
320 BumpVectorContext &bc)
321 : BEVals(bevals), BC(bc) {}
Ted Kremenek2cfe28b2010-03-10 00:18:11 +0000322
323 bool IsTrackedDecl(const VarDecl *VD) {
324 const DeclContext *DC = VD->getDeclContext();
325 return IgnoredContexts.count(DC) == 0;
326 }
327
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000328 void VisitStmt(Stmt *S) {
John McCall7502c1d2011-02-13 04:07:26 +0000329 for (Stmt::child_range I = S->children(); I; ++I)
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000330 if (Stmt *child = *I)
331 Visit(child);
332 }
Ted Kremenek85248732010-02-06 00:30:00 +0000333
334 void VisitDeclRefExpr(const DeclRefExpr *DR) {
335 // Non-local variables are also directly modified.
336 if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl()))
337 if (!VD->hasLocalStorage()) {
338 unsigned &flag = Visited[VD];
339 if (!flag) {
340 flag = 1;
341 BEVals.push_back(VD, BC);
342 }
343 }
344 }
Ted Kremenek2cfe28b2010-03-10 00:18:11 +0000345
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000346 void VisitBlockDeclRefExpr(BlockDeclRefExpr *DR) {
Ted Kremenek85248732010-02-06 00:30:00 +0000347 if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) {
348 unsigned &flag = Visited[VD];
349 if (!flag) {
350 flag = 1;
Ted Kremenek2cfe28b2010-03-10 00:18:11 +0000351 if (IsTrackedDecl(VD))
352 BEVals.push_back(VD, BC);
Ted Kremenek85248732010-02-06 00:30:00 +0000353 }
354 }
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000355 }
Ted Kremenek2cfe28b2010-03-10 00:18:11 +0000356
357 void VisitBlockExpr(BlockExpr *BR) {
358 // Blocks containing blocks can transitively capture more variables.
359 IgnoredContexts.insert(BR->getBlockDecl());
360 Visit(BR->getBlockDecl()->getBody());
361 }
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000362};
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000363} // end anonymous namespace
364
365typedef BumpVector<const VarDecl*> DeclVec;
366
367static DeclVec* LazyInitializeReferencedDecls(const BlockDecl *BD,
368 void *&Vec,
369 llvm::BumpPtrAllocator &A) {
370 if (Vec)
371 return (DeclVec*) Vec;
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000372
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000373 BumpVectorContext BC(A);
374 DeclVec *BV = (DeclVec*) A.Allocate<DeclVec>();
375 new (BV) DeclVec(BC, 10);
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000376
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000377 // Find the referenced variables.
378 FindBlockDeclRefExprsVals F(*BV, BC);
379 F.Visit(BD->getBody());
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000380
381 Vec = BV;
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000382 return BV;
383}
384
385std::pair<AnalysisContext::referenced_decls_iterator,
386 AnalysisContext::referenced_decls_iterator>
387AnalysisContext::getReferencedBlockVars(const BlockDecl *BD) {
388 if (!ReferencedBlockVars)
389 ReferencedBlockVars = new llvm::DenseMap<const BlockDecl*,void*>();
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000390
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000391 DeclVec *V = LazyInitializeReferencedDecls(BD, (*ReferencedBlockVars)[BD], A);
392 return std::make_pair(V->begin(), V->end());
393}
394
395//===----------------------------------------------------------------------===//
396// Cleanup.
397//===----------------------------------------------------------------------===//
398
399AnalysisContext::~AnalysisContext() {
Ted Kremenekb8ad5ee2011-03-10 01:14:05 +0000400 delete forcedBlkExprs;
Ted Kremenekb1a7b652009-11-26 02:31:33 +0000401 delete ReferencedBlockVars;
402}
403
404AnalysisContextManager::~AnalysisContextManager() {
405 for (ContextMap::iterator I = Contexts.begin(), E = Contexts.end(); I!=E; ++I)
406 delete I->second;
407}
Ted Kremenek0ee41242009-12-04 01:28:56 +0000408
409LocationContext::~LocationContext() {}
410
411LocationContextManager::~LocationContextManager() {
412 clear();
413}
414
415void LocationContextManager::clear() {
416 for (llvm::FoldingSet<LocationContext>::iterator I = Contexts.begin(),
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000417 E = Contexts.end(); I != E; ) {
Ted Kremenek0ee41242009-12-04 01:28:56 +0000418 LocationContext *LC = &*I;
419 ++I;
420 delete LC;
421 }
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000422
Ted Kremenek0ee41242009-12-04 01:28:56 +0000423 Contexts.clear();
424}
425