1326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek//=== AnalysisContext.h - Analysis context for Path Sens analysis --*- C++ -*-//
2326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek//
3326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek//                     The LLVM Compiler Infrastructure
4326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek//
5326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek// This file is distributed under the University of Illinois Open Source
6326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek// License. See LICENSE.TXT for details.
7326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek//
8326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek//===----------------------------------------------------------------------===//
9326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek//
10ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie// This file defines AnalysisDeclContext, a class that manages the analysis
11ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie// context data for path sensitive analysis.
12326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek//
13326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek//===----------------------------------------------------------------------===//
14326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
15326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek#ifndef LLVM_CLANG_ANALYSIS_ANALYSISCONTEXT_H
16326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek#define LLVM_CLANG_ANALYSIS_ANALYSISCONTEXT_H
17326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
18326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek#include "clang/AST/Decl.h"
19b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek#include "clang/Analysis/CFG.h"
2030a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "llvm/ADT/DenseMap.h"
21326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek#include "llvm/ADT/FoldingSet.h"
22326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek#include "llvm/Support/Allocator.h"
23651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include <memory>
24326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
25326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremeneknamespace clang {
26326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
27326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekclass Stmt;
28af13d5b25b360e698cc1cf1055ad7d14e008e505Ted Kremenekclass CFGReverseBlockReachabilityAnalysis;
29283a358aecb75e30fcd486f2206f6c03c5e7f11dTed Kremenekclass CFGStmtMap;
30326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekclass LiveVariables;
31a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenekclass ManagedAnalysis;
32326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekclass ParentMap;
33db34ab70961ca4b24b600eb47053d7af304659f5Tom Careclass PseudoConstantAnalysis;
34326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekclass LocationContextManager;
35326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekclass StackFrameContext;
367fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenekclass BlockInvocationContext;
371d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenekclass AnalysisDeclContextManager;
38ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikieclass LocationContext;
39b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek
40c6238d2786cfd961b94580b3d3675a1b3ff0721cZhongxing Xunamespace idx { class TranslationUnit; }
41c6238d2786cfd961b94580b3d3675a1b3ff0721cZhongxing Xu
42a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek/// The base class of a hierarchy of objects representing analyses tied
431d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek/// to AnalysisDeclContext.
44a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenekclass ManagedAnalysis {
45a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenekprotected:
46a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  ManagedAnalysis() {}
47a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenekpublic:
48a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  virtual ~ManagedAnalysis();
49ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
50a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  // Subclasses need to implement:
51a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  //
52a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  //  static const void *getTag();
53a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  //
54a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  // Which returns a fixed pointer address to distinguish classes of
55a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  // analysis objects.  They also need to implement:
56a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  //
571d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  //  static [Derived*] create(AnalysisDeclContext &Ctx);
58a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  //
591d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  // which creates the analysis object given an AnalysisDeclContext.
60a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek};
61ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
62ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
63ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// AnalysisDeclContext contains the context data for the function or method
64ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// under analysis.
651d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenekclass AnalysisDeclContext {
66ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// Backpoint to the AnalysisManager object that created this
67ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// AnalysisDeclContext. This may be null.
681d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  AnalysisDeclContextManager *Manager;
69ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
70cca300a91966df70c9c320e477a3c26ba622673dTed Kremenek  const Decl * const D;
71326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
72651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<CFG> cfg, completeCFG;
73651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<CFGStmtMap> cfgStmtMap;
74b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek
75b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek  CFG::BuildOptions cfgBuildOptions;
76b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek  CFG::BuildOptions::ForcedBlkExprs *forcedBlkExprs;
77ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
78ad5a894df1841698c824381b414630799adc26caTed Kremenek  bool builtCFG, builtCompleteCFG;
79651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<ParentMap> PM;
80651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<PseudoConstantAnalysis> PCA;
81651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<CFGReverseBlockReachabilityAnalysis> CFA;
82b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek
83326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  llvm::BumpPtrAllocator A;
84b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek
85b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek  llvm::DenseMap<const BlockDecl*,void*> *ReferencedBlockVars;
86b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek
87a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  void *ManagedAnalyses;
88a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek
89326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekpublic:
901d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
91d200187bd27f9ad68699693a6e57f9ee3ff260faJordy Rose                  const Decl *D);
92bc5cb8a5fe2b88f917d47ceb58b53696a121e57eTed Kremenek
931d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
94b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                  const Decl *D,
95b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                  const CFG::BuildOptions &BuildOptions);
96326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
971d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  ~AnalysisDeclContext();
98326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
99445895a97ae3f1d7bad3480839d31ed3ebcc9c83Ted Kremenek  ASTContext &getASTContext() const { return D->getASTContext(); }
100c6238d2786cfd961b94580b3d3675a1b3ff0721cZhongxing Xu  const Decl *getDecl() const { return D; }
101c6238d2786cfd961b94580b3d3675a1b3ff0721cZhongxing Xu
102ddc0c4814788dda4ef224cd4d22d07154a6ede49Ted Kremenek  /// Return the AnalysisDeclContextManager (if any) that created
103ddc0c4814788dda4ef224cd4d22d07154a6ede49Ted Kremenek  /// this AnalysisDeclContext.
104ddc0c4814788dda4ef224cd4d22d07154a6ede49Ted Kremenek  AnalysisDeclContextManager *getManager() const {
105ddc0c4814788dda4ef224cd4d22d07154a6ede49Ted Kremenek    return Manager;
106ddc0c4814788dda4ef224cd4d22d07154a6ede49Ted Kremenek  }
107ddc0c4814788dda4ef224cd4d22d07154a6ede49Ted Kremenek
10874fb1a493cf5d2dd0fb51a4eadf74e85e10a3457Ted Kremenek  /// Return the build options used to construct the CFG.
10974fb1a493cf5d2dd0fb51a4eadf74e85e10a3457Ted Kremenek  CFG::BuildOptions &getCFGBuildOptions() {
11074fb1a493cf5d2dd0fb51a4eadf74e85e10a3457Ted Kremenek    return cfgBuildOptions;
11174fb1a493cf5d2dd0fb51a4eadf74e85e10a3457Ted Kremenek  }
11274fb1a493cf5d2dd0fb51a4eadf74e85e10a3457Ted Kremenek
11374fb1a493cf5d2dd0fb51a4eadf74e85e10a3457Ted Kremenek  const CFG::BuildOptions &getCFGBuildOptions() const {
11474fb1a493cf5d2dd0fb51a4eadf74e85e10a3457Ted Kremenek    return cfgBuildOptions;
11574fb1a493cf5d2dd0fb51a4eadf74e85e10a3457Ted Kremenek  }
116ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
117f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru  /// getAddEHEdges - Return true iff we are adding exceptional edges from
118326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  /// callExprs.  If this is false, then try/catch statements and blocks
119326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  /// reachable from them can appear to be dead in the CFG, analysis passes must
120326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  /// cope with that.
121ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool getAddEHEdges() const { return cfgBuildOptions.AddEHEdges; }
122b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek  bool getUseUnoptimizedCFG() const {
123bc5cb8a5fe2b88f917d47ceb58b53696a121e57eTed Kremenek      return !cfgBuildOptions.PruneTriviallyFalseEdges;
124b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek  }
125b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek  bool getAddImplicitDtors() const { return cfgBuildOptions.AddImplicitDtors; }
126b8ad5ee345fa1fdd1fa9253f2d01f69becc88a04Ted Kremenek  bool getAddInitializers() const { return cfgBuildOptions.AddInitializers; }
1279b823e8e1ccb8a2cb49923bad22a80ca96f41f92Ted Kremenek
1280d28d360b5559abda755e50b855ba5e59727d9cdTed Kremenek  void registerForcedBlockExpression(const Stmt *stmt);
1290d28d360b5559abda755e50b855ba5e59727d9cdTed Kremenek  const CFGBlock *getBlockForRegisteredExpression(const Stmt *stmt);
130ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
131453cb859a3c8dcafe79ae840dfc35ff8eae1b4b3Anna Zaks  /// \brief Get the body of the Declaration.
132a2d7e6511a8767dc67381c210601b895a8ebae39Anna Zaks  Stmt *getBody() const;
133453cb859a3c8dcafe79ae840dfc35ff8eae1b4b3Anna Zaks
134453cb859a3c8dcafe79ae840dfc35ff8eae1b4b3Anna Zaks  /// \brief Get the body of the Declaration.
135087f40702fd00898fbb66d765d1143fd944c0485Anna Zaks  /// \param[out] IsAutosynthesized Specifies if the body is auto-generated
136087f40702fd00898fbb66d765d1143fd944c0485Anna Zaks  ///             by the BodyFarm.
137453cb859a3c8dcafe79ae840dfc35ff8eae1b4b3Anna Zaks  Stmt *getBody(bool &IsAutosynthesized) const;
138453cb859a3c8dcafe79ae840dfc35ff8eae1b4b3Anna Zaks
139453cb859a3c8dcafe79ae840dfc35ff8eae1b4b3Anna Zaks  /// \brief Checks if the body of the Decl is generated by the BodyFarm.
140453cb859a3c8dcafe79ae840dfc35ff8eae1b4b3Anna Zaks  ///
141453cb859a3c8dcafe79ae840dfc35ff8eae1b4b3Anna Zaks  /// Note, the lookup is not free. We are going to call getBody behind
142087f40702fd00898fbb66d765d1143fd944c0485Anna Zaks  /// the scenes.
143453cb859a3c8dcafe79ae840dfc35ff8eae1b4b3Anna Zaks  /// \sa getBody
144453cb859a3c8dcafe79ae840dfc35ff8eae1b4b3Anna Zaks  bool isBodyAutosynthesized() const;
145453cb859a3c8dcafe79ae840dfc35ff8eae1b4b3Anna Zaks
146326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  CFG *getCFG();
147ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
148283a358aecb75e30fcd486f2206f6c03c5e7f11dTed Kremenek  CFGStmtMap *getCFGStmtMap();
14904eeba43040969c05cfcb563195ef5b199297b62Anders Carlsson
150af13d5b25b360e698cc1cf1055ad7d14e008e505Ted Kremenek  CFGReverseBlockReachabilityAnalysis *getCFGReachablityAnalysis();
151ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
152ad5a894df1841698c824381b414630799adc26caTed Kremenek  /// Return a version of the CFG without any edges pruned.
153ad5a894df1841698c824381b414630799adc26caTed Kremenek  CFG *getUnoptimizedCFG();
154ad5a894df1841698c824381b414630799adc26caTed Kremenek
155682060c5d95f6e4f79536013781ab0870cdd3850Ted Kremenek  void dumpCFG(bool ShowColors);
15604eeba43040969c05cfcb563195ef5b199297b62Anders Carlsson
1575d98994c7749312a43ce6adf45537979a98e7afdChandler Carruth  /// \brief Returns true if we have built a CFG for this analysis context.
1585d98994c7749312a43ce6adf45537979a98e7afdChandler Carruth  /// Note that this doesn't correspond to whether or not a valid CFG exists, it
1595d98994c7749312a43ce6adf45537979a98e7afdChandler Carruth  /// corresponds to whether we *attempted* to build one.
1605d98994c7749312a43ce6adf45537979a98e7afdChandler Carruth  bool isCFGBuilt() const { return builtCFG; }
1615d98994c7749312a43ce6adf45537979a98e7afdChandler Carruth
162326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  ParentMap &getParentMap();
163db34ab70961ca4b24b600eb47053d7af304659f5Tom Care  PseudoConstantAnalysis *getPseudoConstantAnalysis();
164326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
165326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  typedef const VarDecl * const * referenced_decls_iterator;
166326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
167326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  std::pair<referenced_decls_iterator, referenced_decls_iterator>
168326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    getReferencedBlockVars(const BlockDecl *BD);
169d064fdc4b7b64ca55b40b70490c79d6f569df78eTed Kremenek
170326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  /// Return the ImplicitParamDecl* associated with 'self' if this
1711d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  /// AnalysisDeclContext wraps an ObjCMethodDecl.  Returns NULL otherwise.
172326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  const ImplicitParamDecl *getSelfDecl() const;
173ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
174b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  const StackFrameContext *getStackFrame(LocationContext const *Parent,
175b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                                         const Stmt *S,
176b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                                         const CFGBlock *Blk,
177ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                         unsigned Idx);
1787fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek
1797fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek  const BlockInvocationContext *
1807fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek  getBlockInvocationContext(const LocationContext *parent,
1817fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek                            const BlockDecl *BD,
1827fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek                            const void *ContextData);
183ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
184a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  /// Return the specified analysis object, lazily running the analysis if
185a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  /// necessary.  Return NULL if the analysis could not run.
186a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  template <typename T>
187a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  T *getAnalysis() {
188a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek    const void *tag = T::getTag();
189a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek    ManagedAnalysis *&data = getAnalysisImpl(tag);
190a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek    if (!data) {
191a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek      data = T::create(*this);
192a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek    }
193a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek    return static_cast<T*>(data);
194a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  }
195a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenekprivate:
196a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  ManagedAnalysis *&getAnalysisImpl(const void* tag);
197ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
198b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  LocationContextManager &getLocationContextManager();
199326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek};
200326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
201326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekclass LocationContext : public llvm::FoldingSetNode {
202326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekpublic:
203326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  enum ContextKind { StackFrame, Scope, Block };
204326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
205326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekprivate:
206326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  ContextKind Kind;
207a02d893f15d4663bdba3bd92ade10070bf0510e4Zhongxing Xu
208ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  // AnalysisDeclContext can't be const since some methods may modify its
209ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  // member.
2101d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  AnalysisDeclContext *Ctx;
211a02d893f15d4663bdba3bd92ade10070bf0510e4Zhongxing Xu
212326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  const LocationContext *Parent;
213326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
214326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekprotected:
2151d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  LocationContext(ContextKind k, AnalysisDeclContext *ctx,
216326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek                  const LocationContext *parent)
217326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    : Kind(k), Ctx(ctx), Parent(parent) {}
218326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
219326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekpublic:
220326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  virtual ~LocationContext();
221d064fdc4b7b64ca55b40b70490c79d6f569df78eTed Kremenek
222326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  ContextKind getKind() const { return Kind; }
223326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
2241d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  AnalysisDeclContext *getAnalysisDeclContext() const { return Ctx; }
225326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
226326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  const LocationContext *getParent() const { return Parent; }
227326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
2288ddf7cead8a67342a4584a203e0bf736b7efedbeZhongxing Xu  bool isParentOf(const LocationContext *LC) const;
2298ddf7cead8a67342a4584a203e0bf736b7efedbeZhongxing Xu
2301d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  const Decl *getDecl() const { return getAnalysisDeclContext()->getDecl(); }
231326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
2321d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  CFG *getCFG() const { return getAnalysisDeclContext()->getCFG(); }
233326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
234a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  template <typename T>
235a5937bbfd19e61d651a58b0f0ffeef68457902a5Ted Kremenek  T *getAnalysis() const {
2361d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek    return getAnalysisDeclContext()->getAnalysis<T>();
237326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  }
238326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
239d064fdc4b7b64ca55b40b70490c79d6f569df78eTed Kremenek  ParentMap &getParentMap() const {
2401d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek    return getAnalysisDeclContext()->getParentMap();
241326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  }
242326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
243326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  const ImplicitParamDecl *getSelfDecl() const {
244326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    return Ctx->getSelfDecl();
245326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  }
246d064fdc4b7b64ca55b40b70490c79d6f569df78eTed Kremenek
247326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  const StackFrameContext *getCurrentStackFrame() const;
248326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
249fadcd5d5bbe1bfc1c6b8d819cc2242f780a49fecAnna Zaks  /// Return true if the current LocationContext has no caller context.
250fadcd5d5bbe1bfc1c6b8d819cc2242f780a49fecAnna Zaks  virtual bool inTopFrame() const;
251fadcd5d5bbe1bfc1c6b8d819cc2242f780a49fecAnna Zaks
252326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  virtual void Profile(llvm::FoldingSetNodeID &ID) = 0;
253326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
254ac7cc2d37e82181e73fcc265c1d0a619d18b7605Jordan Rose  void dumpStack(raw_ostream &OS, StringRef Indent = "") const;
255651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void dumpStack() const;
25675f8bd01319000b3e1438847505302670514759dJordan Rose
257326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekpublic:
258326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  static void ProfileCommon(llvm::FoldingSetNodeID &ID,
259326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek                            ContextKind ck,
2601d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek                            AnalysisDeclContext *ctx,
261326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek                            const LocationContext *parent,
2629c378f705405d37f49795d5e915989de774fe11fTed Kremenek                            const void *data);
263326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek};
264326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
265326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekclass StackFrameContext : public LocationContext {
26626c9cb55cb96643c0759c08d037c16c309864087Zhongxing Xu  // The callsite where this stack frame is established.
267892697dd2287caf7c29aaaa82909b0e90b8b63feTed Kremenek  const Stmt *CallSite;
268326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
269326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  // The parent block of the callsite.
270326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  const CFGBlock *Block;
271326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
272326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  // The index of the callsite in the CFGBlock.
273326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  unsigned Index;
274326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
275326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  friend class LocationContextManager;
2761d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  StackFrameContext(AnalysisDeclContext *ctx, const LocationContext *parent,
277ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                    const Stmt *s, const CFGBlock *blk,
278d706434b0231c76fd9acf30060646a7aa8f69aefZhongxing Xu                    unsigned idx)
279892697dd2287caf7c29aaaa82909b0e90b8b63feTed Kremenek    : LocationContext(StackFrame, ctx, parent), CallSite(s),
280d706434b0231c76fd9acf30060646a7aa8f69aefZhongxing Xu      Block(blk), Index(idx) {}
281326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
282326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekpublic:
283326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  ~StackFrameContext() {}
284326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
285892697dd2287caf7c29aaaa82909b0e90b8b63feTed Kremenek  const Stmt *getCallSite() const { return CallSite; }
286d706434b0231c76fd9acf30060646a7aa8f69aefZhongxing Xu
287326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  const CFGBlock *getCallSiteBlock() const { return Block; }
288326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
289fadcd5d5bbe1bfc1c6b8d819cc2242f780a49fecAnna Zaks  /// Return true if the current LocationContext has no caller context.
2906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool inTopFrame() const override { return getParent() == nullptr;  }
291fadcd5d5bbe1bfc1c6b8d819cc2242f780a49fecAnna Zaks
292326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  unsigned getIndex() const { return Index; }
293326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
294651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void Profile(llvm::FoldingSetNodeID &ID) override;
295d064fdc4b7b64ca55b40b70490c79d6f569df78eTed Kremenek
2961d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx,
297d064fdc4b7b64ca55b40b70490c79d6f569df78eTed Kremenek                      const LocationContext *parent, const Stmt *s,
298892697dd2287caf7c29aaaa82909b0e90b8b63feTed Kremenek                      const CFGBlock *blk, unsigned idx) {
299326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    ProfileCommon(ID, StackFrame, ctx, parent, s);
300326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    ID.AddPointer(blk);
301326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    ID.AddInteger(idx);
302326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  }
303326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
3049c378f705405d37f49795d5e915989de774fe11fTed Kremenek  static bool classof(const LocationContext *Ctx) {
305326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    return Ctx->getKind() == StackFrame;
306326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  }
307326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek};
308326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
309326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekclass ScopeContext : public LocationContext {
310326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  const Stmt *Enter;
311d064fdc4b7b64ca55b40b70490c79d6f569df78eTed Kremenek
312326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  friend class LocationContextManager;
3131d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  ScopeContext(AnalysisDeclContext *ctx, const LocationContext *parent,
314326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek               const Stmt *s)
315326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    : LocationContext(Scope, ctx, parent), Enter(s) {}
316326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
317326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekpublic:
318326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  ~ScopeContext() {}
319326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
320651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void Profile(llvm::FoldingSetNodeID &ID) override;
321326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
3221d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx,
323326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek                      const LocationContext *parent, const Stmt *s) {
324326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    ProfileCommon(ID, Scope, ctx, parent, s);
325326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  }
326326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
3279c378f705405d37f49795d5e915989de774fe11fTed Kremenek  static bool classof(const LocationContext *Ctx) {
328326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    return Ctx->getKind() == Scope;
329326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  }
330326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek};
331326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
332326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekclass BlockInvocationContext : public LocationContext {
333326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  const BlockDecl *BD;
3347fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek
3357fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek  // FIXME: Come up with a more type-safe way to model context-sensitivity.
3367fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek  const void *ContextData;
337326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
338326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  friend class LocationContextManager;
339326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
340ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  BlockInvocationContext(AnalysisDeclContext *ctx,
341ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                         const LocationContext *parent,
3427fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek                         const BlockDecl *bd, const void *contextData)
3437fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek    : LocationContext(Block, ctx, parent), BD(bd), ContextData(contextData) {}
344326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
345326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekpublic:
346326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  ~BlockInvocationContext() {}
347326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
348326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  const BlockDecl *getBlockDecl() const { return BD; }
3497fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek
3507fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek  const void *getContextData() const { return ContextData; }
351326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
352651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void Profile(llvm::FoldingSetNodeID &ID) override;
353326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
3541d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ctx,
3557fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek                      const LocationContext *parent, const BlockDecl *bd,
3567fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek                      const void *contextData) {
357326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    ProfileCommon(ID, Block, ctx, parent, bd);
3587fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek    ID.AddPointer(contextData);
359326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  }
360d064fdc4b7b64ca55b40b70490c79d6f569df78eTed Kremenek
3619c378f705405d37f49795d5e915989de774fe11fTed Kremenek  static bool classof(const LocationContext *Ctx) {
362326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek    return Ctx->getKind() == Block;
363326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  }
364326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek};
365326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
366326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekclass LocationContextManager {
367326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  llvm::FoldingSet<LocationContext> Contexts;
368326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekpublic:
369326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  ~LocationContextManager();
370d064fdc4b7b64ca55b40b70490c79d6f569df78eTed Kremenek
3711d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  const StackFrameContext *getStackFrame(AnalysisDeclContext *ctx,
372326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek                                         const LocationContext *parent,
373892697dd2287caf7c29aaaa82909b0e90b8b63feTed Kremenek                                         const Stmt *s,
374d706434b0231c76fd9acf30060646a7aa8f69aefZhongxing Xu                                         const CFGBlock *blk, unsigned idx);
375326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
3761d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  const ScopeContext *getScope(AnalysisDeclContext *ctx,
377326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek                               const LocationContext *parent,
378326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek                               const Stmt *s);
3797fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek
3807fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek  const BlockInvocationContext *
3817fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek  getBlockInvocationContext(AnalysisDeclContext *ctx,
3827fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek                            const LocationContext *parent,
3837fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek                            const BlockDecl *BD,
3847fa9b4f258636d89342eda28f21a986c8ac353b1Ted Kremenek                            const void *ContextData);
385d064fdc4b7b64ca55b40b70490c79d6f569df78eTed Kremenek
386326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  /// Discard all previously created LocationContext objects.
387326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  void clear();
388326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenekprivate:
389326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek  template <typename LOC, typename DATA>
3901d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  const LOC *getLocationContext(AnalysisDeclContext *ctx,
391326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek                                const LocationContext *parent,
392326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek                                const DATA *d);
393326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek};
394326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek
3951d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenekclass AnalysisDeclContextManager {
3961d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  typedef llvm::DenseMap<const Decl*, AnalysisDeclContext*> ContextMap;
397ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
398b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  ContextMap Contexts;
399b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  LocationContextManager LocContexts;
400b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  CFG::BuildOptions cfgBuildOptions;
401a43df9539644bf1c258e12710cd69d79b0b078cdTed Kremenek
402a43df9539644bf1c258e12710cd69d79b0b078cdTed Kremenek  /// Flag to indicate whether or not bodies should be synthesized
403a43df9539644bf1c258e12710cd69d79b0b078cdTed Kremenek  /// for well-known functions.
404a43df9539644bf1c258e12710cd69d79b0b078cdTed Kremenek  bool SynthesizeBodies;
405ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
406b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenekpublic:
4071d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  AnalysisDeclContextManager(bool useUnoptimizedCFG = false,
4085a1ffe98b04120846a15f7105905b5f363b08635Jordan Rose                             bool addImplicitDtors = false,
4095a1ffe98b04120846a15f7105905b5f363b08635Jordan Rose                             bool addInitializers = false,
410a43df9539644bf1c258e12710cd69d79b0b078cdTed Kremenek                             bool addTemporaryDtors = false,
41102a88c3edf1aeb9580e0b6e444b30c52846a673cTed Kremenek                             bool synthesizeBodies = false,
412651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                             bool addStaticInitBranches = false,
413651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                             bool addCXXNewAllocator = true);
414ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4151d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  ~AnalysisDeclContextManager();
416ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
417d200187bd27f9ad68699693a6e57f9ee3ff260faJordy Rose  AnalysisDeclContext *getContext(const Decl *D);
418ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
419b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  bool getUseUnoptimizedCFG() const {
420b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek    return !cfgBuildOptions.PruneTriviallyFalseEdges;
421b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  }
422ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
423b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  CFG::BuildOptions &getCFGBuildOptions() {
424b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek    return cfgBuildOptions;
425b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  }
426a43df9539644bf1c258e12710cd69d79b0b078cdTed Kremenek
427a43df9539644bf1c258e12710cd69d79b0b078cdTed Kremenek  /// Return true if faux bodies should be synthesized for well-known
428a43df9539644bf1c258e12710cd69d79b0b078cdTed Kremenek  /// functions.
429a43df9539644bf1c258e12710cd69d79b0b078cdTed Kremenek  bool synthesizeBodies() const { return SynthesizeBodies; }
430ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4311d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  const StackFrameContext *getStackFrame(AnalysisDeclContext *Ctx,
432b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                                         LocationContext const *Parent,
433b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                                         const Stmt *S,
434b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                                         const CFGBlock *Blk,
435b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                                         unsigned Idx) {
436b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek    return LocContexts.getStackFrame(Ctx, Parent, S, Blk, Idx);
437b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  }
438ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
439b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  // Get the top level stack frame.
440d200187bd27f9ad68699693a6e57f9ee3ff260faJordy Rose  const StackFrameContext *getStackFrame(const Decl *D) {
4416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    return LocContexts.getStackFrame(getContext(D), nullptr, nullptr, nullptr,
4426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines                                     0);
443b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  }
444ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
445b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  // Get a stack frame with parent.
446ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  StackFrameContext const *getStackFrame(const Decl *D,
447b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                                         LocationContext const *Parent,
448b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                                         const Stmt *S,
449b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                                         const CFGBlock *Blk,
450b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek                                         unsigned Idx) {
451b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek    return LocContexts.getStackFrame(getContext(D), Parent, S, Blk, Idx);
452b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  }
453b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek
4541d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  /// Discard all previously created AnalysisDeclContexts.
455b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  void clear();
456b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek
457b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenekprivate:
4581d26f48dc2eea1c07431ca1519d7034a21b9bcffTed Kremenek  friend class AnalysisDeclContext;
459b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek
460b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  LocationContextManager &getLocationContextManager() {
461b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek    return LocContexts;
462b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek  }
463b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek};
464b1b5daf30d2597e066936772bd206500232d7d65Ted Kremenek
465326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek} // end clang namespace
466326be568e2cb04285c84e6e26a3e6b3822607361Ted Kremenek#endif
467