Clang Project

clang_source_code/lib/Analysis/AnalysisDeclContext.cpp
1//===- AnalysisDeclContext.cpp - Analysis context for Path Sens analysis --===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines AnalysisDeclContext, a class that manages the analysis
10// context data for path sensitive analysis.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Analysis/AnalysisDeclContext.h"
15#include "clang/AST/ASTContext.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclBase.h"
18#include "clang/AST/DeclCXX.h"
19#include "clang/AST/DeclObjC.h"
20#include "clang/AST/DeclTemplate.h"
21#include "clang/AST/Expr.h"
22#include "clang/AST/LambdaCapture.h"
23#include "clang/AST/ParentMap.h"
24#include "clang/AST/PrettyPrinter.h"
25#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtVisitor.h"
28#include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
29#include "clang/Analysis/BodyFarm.h"
30#include "clang/Analysis/CFG.h"
31#include "clang/Analysis/CFGStmtMap.h"
32#include "clang/Analysis/Support/BumpVector.h"
33#include "clang/Basic/LLVM.h"
34#include "clang/Basic/SourceLocation.h"
35#include "clang/Basic/SourceManager.h"
36#include "llvm/ADT/DenseMap.h"
37#include "llvm/ADT/FoldingSet.h"
38#include "llvm/ADT/STLExtras.h"
39#include "llvm/ADT/SmallPtrSet.h"
40#include "llvm/ADT/iterator_range.h"
41#include "llvm/Support/Allocator.h"
42#include "llvm/Support/Casting.h"
43#include "llvm/Support/Compiler.h"
44#include "llvm/Support/ErrorHandling.h"
45#include "llvm/Support/SaveAndRestore.h"
46#include "llvm/Support/raw_ostream.h"
47#include <cassert>
48#include <memory>
49
50using namespace clang;
51
52using ManagedAnalysisMap = llvm::DenseMap<const void *, ManagedAnalysis *>;
53
54AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
55                                         const Decl *d,
56                                         const CFG::BuildOptions &buildOptions)
57    : Manager(Mgr), D(d), cfgBuildOptions(buildOptions) {
58  cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
59}
60
61AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
62                                         const Decl *d)
63    : Manager(Mgr), D(d) {
64  cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
65}
66
67AnalysisDeclContextManager::AnalysisDeclContextManager(
68    ASTContext &ASTCtxbool useUnoptimizedCFGbool addImplicitDtors,
69    bool addInitializersbool addTemporaryDtorsbool addLifetime,
70    bool addLoopExitbool addScopesbool synthesizeBodies,
71    bool addStaticInitBranchbool addCXXNewAllocator,
72    bool addRichCXXConstructorsbool markElidedCXXConstructors,
73    CodeInjector *injector)
74    : Injector(injector), FunctionBodyFarm(ASTCtxinjector),
75      SynthesizeBodies(synthesizeBodies) {
76  cfgBuildOptions.PruneTriviallyFalseEdges = !useUnoptimizedCFG;
77  cfgBuildOptions.AddImplicitDtors = addImplicitDtors;
78  cfgBuildOptions.AddInitializers = addInitializers;
79  cfgBuildOptions.AddTemporaryDtors = addTemporaryDtors;
80  cfgBuildOptions.AddLifetime = addLifetime;
81  cfgBuildOptions.AddLoopExit = addLoopExit;
82  cfgBuildOptions.AddScopes = addScopes;
83  cfgBuildOptions.AddStaticInitBranches = addStaticInitBranch;
84  cfgBuildOptions.AddCXXNewAllocator = addCXXNewAllocator;
85  cfgBuildOptions.AddRichCXXConstructors = addRichCXXConstructors;
86  cfgBuildOptions.MarkElidedCXXConstructors = markElidedCXXConstructors;
87}
88
89void AnalysisDeclContextManager::clear() { Contexts.clear(); }
90
91Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesizedconst {
92  IsAutosynthesized = false;
93  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
94    Stmt *Body = FD->getBody();
95    if (auto *CoroBody = dyn_cast_or_null<CoroutineBodyStmt>(Body))
96      Body = CoroBody->getBody();
97    if (Manager && Manager->synthesizeBodies()) {
98      Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(FD);
99      if (SynthesizedBody) {
100        Body = SynthesizedBody;
101        IsAutosynthesized = true;
102      }
103    }
104    return Body;
105  }
106  else if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
107    Stmt *Body = MD->getBody();
108    if (Manager && Manager->synthesizeBodies()) {
109      Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(MD);
110      if (SynthesizedBody) {
111        Body = SynthesizedBody;
112        IsAutosynthesized = true;
113      }
114    }
115    return Body;
116  } else if (const auto *BD = dyn_cast<BlockDecl>(D))
117    return BD->getBody();
118  else if (const auto *FunTmpl = dyn_cast_or_null<FunctionTemplateDecl>(D))
119    return FunTmpl->getTemplatedDecl()->getBody();
120
121  llvm_unreachable("unknown code decl");
122}
123
124Stmt *AnalysisDeclContext::getBody() const {
125  bool Tmp;
126  return getBody(Tmp);
127}
128
129bool AnalysisDeclContext::isBodyAutosynthesized() const {
130  bool Tmp;
131  getBody(Tmp);
132  return Tmp;
133}
134
135bool AnalysisDeclContext::isBodyAutosynthesizedFromModelFile() const {
136  bool Tmp;
137  Stmt *Body = getBody(Tmp);
138  return Tmp && Body->getBeginLoc().isValid();
139}
140
141/// Returns true if \param VD is an Objective-C implicit 'self' parameter.
142static bool isSelfDecl(const VarDecl *VD) {
143  return isa<ImplicitParamDecl>(VD) && VD->getName() == "self";
144}
145
146const ImplicitParamDecl *AnalysisDeclContext::getSelfDecl() const {
147  if (const auto *MD = dyn_cast<ObjCMethodDecl>(D))
148    return MD->getSelfDecl();
149  if (const auto *BD = dyn_cast<BlockDecl>(D)) {
150    // See if 'self' was captured by the block.
151    for (const auto &I : BD->captures()) {
152      const VarDecl *VD = I.getVariable();
153      if (isSelfDecl(VD))
154        return dyn_cast<ImplicitParamDecl>(VD);
155    }
156  }
157
158  auto *CXXMethod = dyn_cast<CXXMethodDecl>(D);
159  if (!CXXMethod)
160    return nullptr;
161
162  const CXXRecordDecl *parent = CXXMethod->getParent();
163  if (!parent->isLambda())
164    return nullptr;
165
166  for (const auto &LC : parent->captures()) {
167    if (!LC.capturesVariable())
168      continue;
169
170    VarDecl *VD = LC.getCapturedVar();
171    if (isSelfDecl(VD))
172      return dyn_cast<ImplicitParamDecl>(VD);
173  }
174
175  return nullptr;
176}
177
178void AnalysisDeclContext::registerForcedBlockExpression(const Stmt *stmt) {
179  if (!forcedBlkExprs)
180    forcedBlkExprs = new CFG::BuildOptions::ForcedBlkExprs();
181  // Default construct an entry for 'stmt'.
182  if (const auto *e = dyn_cast<Expr>(stmt))
183    stmt = e->IgnoreParens();
184  (void) (*forcedBlkExprs)[stmt];
185}
186
187const CFGBlock *
188AnalysisDeclContext::getBlockForRegisteredExpression(const Stmt *stmt) {
189  assert(forcedBlkExprs);
190  if (const auto *e = dyn_cast<Expr>(stmt))
191    stmt = e->IgnoreParens();
192  CFG::BuildOptions::ForcedBlkExprs::const_iterator itr =
193    forcedBlkExprs->find(stmt);
194  end()", "/home/seafit/code_projects/clang_source/clang/lib/Analysis/AnalysisDeclContext.cpp", 194, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(itr != forcedBlkExprs->end());
195  return itr->second;
196}
197
198/// Add each synthetic statement in the CFG to the parent map, using the
199/// source statement's parent.
200static void addParentsForSyntheticStmts(const CFG *TheCFGParentMap &PM) {
201  if (!TheCFG)
202    return;
203
204  for (CFG::synthetic_stmt_iterator I = TheCFG->synthetic_stmt_begin(),
205                                    E = TheCFG->synthetic_stmt_end();
206       I != E; ++I) {
207    PM.setParent(I->first, PM.getParent(I->second));
208  }
209}
210
211CFG *AnalysisDeclContext::getCFG() {
212  if (!cfgBuildOptions.PruneTriviallyFalseEdges)
213    return getUnoptimizedCFG();
214
215  if (!builtCFG) {
216    cfg = CFG::buildCFG(D, getBody(), &D->getASTContext(), cfgBuildOptions);
217    // Even when the cfg is not successfully built, we don't
218    // want to try building it again.
219    builtCFG = true;
220
221    if (PM)
222      addParentsForSyntheticStmts(cfg.get(), *PM);
223
224    // The Observer should only observe one build of the CFG.
225    getCFGBuildOptions().Observer = nullptr;
226  }
227  return cfg.get();
228}
229
230CFG *AnalysisDeclContext::getUnoptimizedCFG() {
231  if (!builtCompleteCFG) {
232    SaveAndRestore<boolNotPrune(cfgBuildOptions.PruneTriviallyFalseEdges,
233                                  false);
234    completeCFG =
235        CFG::buildCFG(D, getBody(), &D->getASTContext(), cfgBuildOptions);
236    // Even when the cfg is not successfully built, we don't
237    // want to try building it again.
238    builtCompleteCFG = true;
239
240    if (PM)
241      addParentsForSyntheticStmts(completeCFG.get(), *PM);
242
243    // The Observer should only observe one build of the CFG.
244    getCFGBuildOptions().Observer = nullptr;
245  }
246  return completeCFG.get();
247}
248
249CFGStmtMap *AnalysisDeclContext::getCFGStmtMap() {
250  if (cfgStmtMap)
251    return cfgStmtMap.get();
252
253  if (CFG *c = getCFG()) {
254    cfgStmtMap.reset(CFGStmtMap::Build(c, &getParentMap()));
255    return cfgStmtMap.get();
256  }
257
258  return nullptr;
259}
260
261CFGReverseBlockReachabilityAnalysis *AnalysisDeclContext::getCFGReachablityAnalysis() {
262  if (CFA)
263    return CFA.get();
264
265  if (CFG *c = getCFG()) {
266    CFA.reset(new CFGReverseBlockReachabilityAnalysis(*c));
267    return CFA.get();
268  }
269
270  return nullptr;
271}
272
273void AnalysisDeclContext::dumpCFG(bool ShowColors) {
274  getCFG()->dump(getASTContext().getLangOpts(), ShowColors);
275}
276
277ParentMap &AnalysisDeclContext::getParentMap() {
278  if (!PM) {
279    PM.reset(new ParentMap(getBody()));
280    if (const auto *C = dyn_cast<CXXConstructorDecl>(getDecl())) {
281      for (const auto *I : C->inits()) {
282        PM->addStmt(I->getInit());
283      }
284    }
285    if (builtCFG)
286      addParentsForSyntheticStmts(getCFG(), *PM);
287    if (builtCompleteCFG)
288      addParentsForSyntheticStmts(getUnoptimizedCFG(), *PM);
289  }
290  return *PM;
291}
292
293AnalysisDeclContext *AnalysisDeclContextManager::getContext(const Decl *D) {
294  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
295    // Calling 'hasBody' replaces 'FD' in place with the FunctionDecl
296    // that has the body.
297    FD->hasBody(FD);
298    D = FD;
299  }
300
301  std::unique_ptr<AnalysisDeclContext> &AC = Contexts[D];
302  if (!AC)
303    AC = llvm::make_unique<AnalysisDeclContext>(this, D, cfgBuildOptions);
304  return AC.get();
305}
306
307BodyFarm &AnalysisDeclContextManager::getBodyFarm() { return FunctionBodyFarm; }
308
309const StackFrameContext *
310AnalysisDeclContext::getStackFrame(LocationContext const *Parentconst Stmt *S,
311                               const CFGBlock *Blkunsigned Idx) {
312  return getLocationContextManager().getStackFrame(thisParentSBlkIdx);
313}
314
315const BlockInvocationContext *
316AnalysisDeclContext::getBlockInvocationContext(const LocationContext *parent,
317                                               const BlockDecl *BD,
318                                               const void *ContextData) {
319  return getLocationContextManager().getBlockInvocationContext(thisparent,
320                                                               BDContextData);
321}
322
323bool AnalysisDeclContext::isInStdNamespace(const Decl *D) {
324  const DeclContext *DC = D->getDeclContext()->getEnclosingNamespaceContext();
325  const auto *ND = dyn_cast<NamespaceDecl>(DC);
326  if (!ND)
327    return false;
328
329  while (const DeclContext *Parent = ND->getParent()) {
330    if (!isa<NamespaceDecl>(Parent))
331      break;
332    ND = cast<NamespaceDecl>(Parent);
333  }
334
335  return ND->isStdNamespace();
336}
337
338LocationContextManager &AnalysisDeclContext::getLocationContextManager() {
339   (0) . __assert_fail ("Manager && \"Cannot create LocationContexts without an AnalysisDeclContextManager!\"", "/home/seafit/code_projects/clang_source/clang/lib/Analysis/AnalysisDeclContext.cpp", 340, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Manager &&
340 (0) . __assert_fail ("Manager && \"Cannot create LocationContexts without an AnalysisDeclContextManager!\"", "/home/seafit/code_projects/clang_source/clang/lib/Analysis/AnalysisDeclContext.cpp", 340, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">         "Cannot create LocationContexts without an AnalysisDeclContextManager!");
341  return Manager->getLocationContextManager();
342}
343
344//===----------------------------------------------------------------------===//
345// FoldingSet profiling.
346//===----------------------------------------------------------------------===//
347
348void LocationContext::ProfileCommon(llvm::FoldingSetNodeID &ID,
349                                    ContextKind ck,
350                                    AnalysisDeclContext *ctx,
351                                    const LocationContext *parent,
352                                    const void *data) {
353  ID.AddInteger(ck);
354  ID.AddPointer(ctx);
355  ID.AddPointer(parent);
356  ID.AddPointer(data);
357}
358
359void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID) {
360  Profile(IDgetAnalysisDeclContext(), getParent(), CallSiteBlockIndex);
361}
362
363void ScopeContext::Profile(llvm::FoldingSetNodeID &ID) {
364  Profile(IDgetAnalysisDeclContext(), getParent(), Enter);
365}
366
367void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) {
368  Profile(IDgetAnalysisDeclContext(), getParent(), BDContextData);
369}
370
371//===----------------------------------------------------------------------===//
372// LocationContext creation.
373//===----------------------------------------------------------------------===//
374
375template <typename LOC, typename DATA>
376const LOC*
377LocationContextManager::getLocationContext(AnalysisDeclContext *ctx,
378                                           const LocationContext *parent,
379                                           const DATA *d) {
380  llvm::FoldingSetNodeID ID;
381  LOC::Profile(ID, ctx, parent, d);
382  void *InsertPos;
383
384  LOC *L = cast_or_null<LOC>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
385
386  if (!L) {
387    L = new LOC(ctxparentd, ++NewID);
388    Contexts.InsertNode(L, InsertPos);
389  }
390  return L;
391}
392
393const StackFrameContext*
394LocationContextManager::getStackFrame(AnalysisDeclContext *ctx,
395                                      const LocationContext *parent,
396                                      const Stmt *s,
397                                      const CFGBlock *blkunsigned idx) {
398  llvm::FoldingSetNodeID ID;
399  StackFrameContext::Profile(ID, ctx, parent, s, blk, idx);
400  void *InsertPos;
401  auto *L =
402   cast_or_null<StackFrameContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
403  if (!L) {
404    L = new StackFrameContext(ctx, parent, s, blk, idx, ++NewID);
405    Contexts.InsertNode(L, InsertPos);
406  }
407  return L;
408}
409
410const ScopeContext *
411LocationContextManager::getScope(AnalysisDeclContext *ctx,
412                                 const LocationContext *parent,
413                                 const Stmt *s) {
414  return getLocationContext<ScopeContextStmt>(ctxparents);
415}
416
417const BlockInvocationContext *
418LocationContextManager::getBlockInvocationContext(AnalysisDeclContext *ctx,
419                                                  const LocationContext *parent,
420                                                  const BlockDecl *BD,
421                                                  const void *ContextData) {
422  llvm::FoldingSetNodeID ID;
423  BlockInvocationContext::Profile(ID, ctx, parent, BD, ContextData);
424  void *InsertPos;
425  auto *L =
426    cast_or_null<BlockInvocationContext>(Contexts.FindNodeOrInsertPos(ID,
427                                                                    InsertPos));
428  if (!L) {
429    L = new BlockInvocationContext(ctx, parent, BD, ContextData, ++NewID);
430    Contexts.InsertNode(L, InsertPos);
431  }
432  return L;
433}
434
435//===----------------------------------------------------------------------===//
436// LocationContext methods.
437//===----------------------------------------------------------------------===//
438
439const StackFrameContext *LocationContext::getStackFrame() const {
440  const LocationContext *LC = this;
441  while (LC) {
442    if (const auto *SFC = dyn_cast<StackFrameContext>(LC))
443      return SFC;
444    LC = LC->getParent();
445  }
446  return nullptr;
447}
448
449bool LocationContext::inTopFrame() const {
450  return getStackFrame()->inTopFrame();
451}
452
453bool LocationContext::isParentOf(const LocationContext *LCconst {
454  do {
455    const LocationContext *Parent = LC->getParent();
456    if (Parent == this)
457      return true;
458    else
459      LC = Parent;
460  } while (LC);
461
462  return false;
463}
464
465static void printLocation(raw_ostream &OSconst SourceManager &SM,
466                          SourceLocation SLoc) {
467  if (SLoc.isFileID() && SM.isInMainFile(SLoc))
468    OS << "line " << SM.getExpansionLineNumber(SLoc);
469  else
470    SLoc.print(OSSM);
471}
472
473void LocationContext::dumpStack(
474    raw_ostream &OSStringRef Indentconst char *NLconst char *Sep,
475    std::function<void(const LocationContext *)> printMoreInfoPerContextconst {
476  ASTContext &Ctx = getAnalysisDeclContext()->getASTContext();
477  PrintingPolicy PP(Ctx.getLangOpts());
478  PP.TerseOutput = 1;
479
480  const SourceManager &SM =
481      getAnalysisDeclContext()->getASTContext().getSourceManager();
482
483  unsigned Frame = 0;
484  for (const LocationContext *LCtx = thisLCtxLCtx = LCtx->getParent()) {
485    switch (LCtx->getKind()) {
486    case StackFrame:
487      OS << Indent << '#' << Frame << ' ';
488      ++Frame;
489      if (const auto *D = dyn_cast<NamedDecl>(LCtx->getDecl()))
490        OS << "Calling " << D->getQualifiedNameAsString();
491      else
492        OS << "Calling anonymous code";
493      if (const Stmt *S = cast<StackFrameContext>(LCtx)->getCallSite()) {
494        OS << " at ";
495        printLocation(OSSMS->getBeginLoc());
496      }
497      break;
498    case Scope:
499      OS << "Entering scope";
500      break;
501    case Block:
502      OS << "Invoking block";
503      if (const Decl *D = cast<BlockInvocationContext>(LCtx)->getDecl()) {
504        OS << " defined at ";
505        printLocation(OSSMD->getBeginLoc());
506      }
507      break;
508    }
509    OS << NL;
510
511    printMoreInfoPerContext(LCtx);
512  }
513}
514
515LLVM_DUMP_METHOD void LocationContext::dumpStack() const {
516  dumpStack(llvm::errs());
517}
518
519//===----------------------------------------------------------------------===//
520// Lazily generated map to query the external variables referenced by a Block.
521//===----------------------------------------------------------------------===//
522
523namespace {
524
525class FindBlockDeclRefExprsVals : public StmtVisitor<FindBlockDeclRefExprsVals>{
526  BumpVector<const VarDecl *> &BEVals;
527  BumpVectorContext &BC;
528  llvm::SmallPtrSet<const VarDecl *, 4Visited;
529  llvm::SmallPtrSet<const DeclContext *, 4IgnoredContexts;
530
531public:
532  FindBlockDeclRefExprsVals(BumpVector<const VarDecl*> &bevals,
533                            BumpVectorContext &bc)
534      : BEVals(bevals), BC(bc) {}
535
536  void VisitStmt(Stmt *S) {
537    for (auto *Child : S->children())
538      if (Child)
539        Visit(Child);
540  }
541
542  void VisitDeclRefExpr(DeclRefExpr *DR) {
543    // Non-local variables are also directly modified.
544    if (const auto *VD = dyn_cast<VarDecl>(DR->getDecl())) {
545      if (!VD->hasLocalStorage()) {
546        if (Visited.insert(VD).second)
547          BEVals.push_back(VD, BC);
548      }
549    }
550  }
551
552  void VisitBlockExpr(BlockExpr *BR) {
553    // Blocks containing blocks can transitively capture more variables.
554    IgnoredContexts.insert(BR->getBlockDecl());
555    Visit(BR->getBlockDecl()->getBody());
556  }
557
558  void VisitPseudoObjectExpr(PseudoObjectExpr *PE) {
559    for (PseudoObjectExpr::semantics_iterator it = PE->semantics_begin(),
560         et = PE->semantics_end(); it != et; ++it) {
561      Expr *Semantic = *it;
562      if (auto *OVE = dyn_cast<OpaqueValueExpr>(Semantic))
563        Semantic = OVE->getSourceExpr();
564      Visit(Semantic);
565    }
566  }
567};
568
569// namespace
570
571using DeclVec = BumpVector<const VarDecl *>;
572
573static DeclVecLazyInitializeReferencedDecls(const BlockDecl *BD,
574                                              void *&Vec,
575                                              llvm::BumpPtrAllocator &A) {
576  if (Vec)
577    return (DeclVec*) Vec;
578
579  BumpVectorContext BC(A);
580  DeclVec *BV = (DeclVec*) A.Allocate<DeclVec>();
581  new (BVDeclVec(BC10);
582
583  // Go through the capture list.
584  for (const auto &CI : BD->captures()) {
585    BV->push_back(CI.getVariable(), BC);
586  }
587
588  // Find the referenced global/static variables.
589  FindBlockDeclRefExprsVals F(*BVBC);
590  F.Visit(BD->getBody());
591
592  Vec = BV;
593  return BV;
594}
595
596llvm::iterator_range<AnalysisDeclContext::referenced_decls_iterator>
597AnalysisDeclContext::getReferencedBlockVars(const BlockDecl *BD) {
598  if (!ReferencedBlockVars)
599    ReferencedBlockVars = new llvm::DenseMap<const BlockDecl*,void*>();
600
601  const DeclVec *V =
602      LazyInitializeReferencedDecls(BD, (*ReferencedBlockVars)[BD], A);
603  return llvm::make_range(V->begin(), V->end());
604}
605
606ManagedAnalysis *&AnalysisDeclContext::getAnalysisImpl(const void *tag) {
607  if (!ManagedAnalyses)
608    ManagedAnalyses = new ManagedAnalysisMap();
609  ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses;
610  return (*M)[tag];
611}
612
613//===----------------------------------------------------------------------===//
614// Cleanup.
615//===----------------------------------------------------------------------===//
616
617ManagedAnalysis::~ManagedAnalysis() = default;
618
619AnalysisDeclContext::~AnalysisDeclContext() {
620  delete forcedBlkExprs;
621  delete ReferencedBlockVars;
622  // Release the managed analyses.
623  if (ManagedAnalyses) {
624    ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses;
625    llvm::DeleteContainerSeconds(*M);
626    delete M;
627  }
628}
629
630LocationContext::~LocationContext() = default;
631
632LocationContextManager::~LocationContextManager() {
633  clear();
634}
635
636void LocationContextManager::clear() {
637  for (llvm::FoldingSet<LocationContext>::iterator I = Contexts.begin(),
638       E = Contexts.end(); I != E; ) {
639    LocationContext *LC = &*I;
640    ++I;
641    delete LC;
642  }
643  Contexts.clear();
644}
645
clang::AnalysisDeclContextManager::clear
clang::AnalysisDeclContext::getBody
clang::AnalysisDeclContext::getBody
clang::AnalysisDeclContext::isBodyAutosynthesized
clang::AnalysisDeclContext::isBodyAutosynthesizedFromModelFile
clang::AnalysisDeclContext::getSelfDecl
clang::AnalysisDeclContext::registerForcedBlockExpression
clang::AnalysisDeclContext::getBlockForRegisteredExpression
clang::AnalysisDeclContext::getCFG
clang::AnalysisDeclContext::getUnoptimizedCFG
clang::AnalysisDeclContext::getCFGStmtMap
clang::AnalysisDeclContext::getCFGReachablityAnalysis
clang::AnalysisDeclContext::dumpCFG
clang::AnalysisDeclContext::getParentMap
clang::AnalysisDeclContextManager::getContext
clang::AnalysisDeclContextManager::getBodyFarm
clang::AnalysisDeclContext::getStackFrame
clang::AnalysisDeclContext::getBlockInvocationContext
clang::AnalysisDeclContext::isInStdNamespace
clang::AnalysisDeclContext::getLocationContextManager
clang::LocationContext::ProfileCommon
clang::StackFrameContext::Profile
clang::ScopeContext::Profile
clang::BlockInvocationContext::Profile
clang::LocationContextManager::getLocationContext
clang::LocationContextManager::getStackFrame
clang::LocationContextManager::getScope
clang::LocationContextManager::getBlockInvocationContext
clang::LocationContext::getStackFrame
clang::LocationContext::inTopFrame
clang::LocationContext::isParentOf
clang::LocationContext::dumpStack
clang::LocationContext::dumpStack
clang::AnalysisDeclContext::getReferencedBlockVars
clang::AnalysisDeclContext::getAnalysisImpl
clang::LocationContextManager::clear