AnalysisDeclContext.cpp 19 KB

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