clang  6.0.0svn
AnalysisDeclContext.cpp
Go to the documentation of this file.
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 
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"
26 #include "clang/Analysis/CFG.h"
29 #include "llvm/ADT/SmallPtrSet.h"
30 #include "llvm/Support/ErrorHandling.h"
31 #include "llvm/Support/SaveAndRestore.h"
32 #include "llvm/Support/raw_ostream.h"
33 
34 using namespace clang;
35 
36 typedef llvm::DenseMap<const void *, ManagedAnalysis *> ManagedAnalysisMap;
37 
39  const Decl *d,
40  const CFG::BuildOptions &buildOptions)
41  : Manager(Mgr),
42  D(d),
43  cfgBuildOptions(buildOptions),
44  forcedBlkExprs(nullptr),
45  builtCFG(false),
46  builtCompleteCFG(false),
47  ReferencedBlockVars(nullptr),
48  ManagedAnalyses(nullptr)
49 {
50  cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
51 }
52 
54  const Decl *d)
55 : Manager(Mgr),
56  D(d),
57  forcedBlkExprs(nullptr),
58  builtCFG(false),
59  builtCompleteCFG(false),
60  ReferencedBlockVars(nullptr),
61  ManagedAnalyses(nullptr)
62 {
63  cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
64 }
65 
67  ASTContext &ASTCtx, bool useUnoptimizedCFG, bool addImplicitDtors,
68  bool addInitializers, bool addTemporaryDtors, bool addLifetime,
69  bool addLoopExit, bool synthesizeBodies, bool addStaticInitBranch,
70  bool addCXXNewAllocator, CodeInjector *injector)
71  : Injector(injector), FunctionBodyFarm(ASTCtx, injector),
72  SynthesizeBodies(synthesizeBodies) {
73  cfgBuildOptions.PruneTriviallyFalseEdges = !useUnoptimizedCFG;
74  cfgBuildOptions.AddImplicitDtors = addImplicitDtors;
75  cfgBuildOptions.AddInitializers = addInitializers;
76  cfgBuildOptions.AddTemporaryDtors = addTemporaryDtors;
77  cfgBuildOptions.AddLifetime = addLifetime;
78  cfgBuildOptions.AddLoopExit = addLoopExit;
79  cfgBuildOptions.AddStaticInitBranches = addStaticInitBranch;
80  cfgBuildOptions.AddCXXNewAllocator = addCXXNewAllocator;
81 }
82 
83 void AnalysisDeclContextManager::clear() { Contexts.clear(); }
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 (auto *CoroBody = dyn_cast_or_null<CoroutineBodyStmt>(Body))
90  Body = CoroBody->getBody();
91  if (Manager && Manager->synthesizeBodies()) {
92  Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(FD);
93  if (SynthesizedBody) {
94  Body = SynthesizedBody;
95  IsAutosynthesized = true;
96  }
97  }
98  return Body;
99  }
100  else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
101  Stmt *Body = MD->getBody();
102  if (Manager && Manager->synthesizeBodies()) {
103  Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(MD);
104  if (SynthesizedBody) {
105  Body = SynthesizedBody;
106  IsAutosynthesized = true;
107  }
108  }
109  return Body;
110  } else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D))
111  return BD->getBody();
112  else if (const FunctionTemplateDecl *FunTmpl
113  = dyn_cast_or_null<FunctionTemplateDecl>(D))
114  return FunTmpl->getTemplatedDecl()->getBody();
115 
116  llvm_unreachable("unknown code decl");
117 }
118 
120  bool Tmp;
121  return getBody(Tmp);
122 }
123 
125  bool Tmp;
126  getBody(Tmp);
127  return Tmp;
128 }
129 
131  bool Tmp;
132  Stmt *Body = getBody(Tmp);
133  return Tmp && Body->getLocStart().isValid();
134 }
135 
136 /// Returns true if \param VD is an Objective-C implicit 'self' parameter.
137 static bool isSelfDecl(const VarDecl *VD) {
138  return isa<ImplicitParamDecl>(VD) && VD->getName() == "self";
139 }
140 
142  if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
143  return MD->getSelfDecl();
144  if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
145  // See if 'self' was captured by the block.
146  for (const auto &I : BD->captures()) {
147  const VarDecl *VD = I.getVariable();
148  if (isSelfDecl(VD))
149  return dyn_cast<ImplicitParamDecl>(VD);
150  }
151  }
152 
153  auto *CXXMethod = dyn_cast<CXXMethodDecl>(D);
154  if (!CXXMethod)
155  return nullptr;
156 
157  const CXXRecordDecl *parent = CXXMethod->getParent();
158  if (!parent->isLambda())
159  return nullptr;
160 
161  for (const LambdaCapture &LC : parent->captures()) {
162  if (!LC.capturesVariable())
163  continue;
164 
165  VarDecl *VD = LC.getCapturedVar();
166  if (isSelfDecl(VD))
167  return dyn_cast<ImplicitParamDecl>(VD);
168  }
169 
170  return nullptr;
171 }
172 
174  if (!forcedBlkExprs)
175  forcedBlkExprs = new CFG::BuildOptions::ForcedBlkExprs();
176  // Default construct an entry for 'stmt'.
177  if (const Expr *e = dyn_cast<Expr>(stmt))
178  stmt = e->IgnoreParens();
179  (void) (*forcedBlkExprs)[stmt];
180 }
181 
182 const CFGBlock *
184  assert(forcedBlkExprs);
185  if (const Expr *e = dyn_cast<Expr>(stmt))
186  stmt = e->IgnoreParens();
187  CFG::BuildOptions::ForcedBlkExprs::const_iterator itr =
188  forcedBlkExprs->find(stmt);
189  assert(itr != forcedBlkExprs->end());
190  return itr->second;
191 }
192 
193 /// Add each synthetic statement in the CFG to the parent map, using the
194 /// source statement's parent.
195 static void addParentsForSyntheticStmts(const CFG *TheCFG, ParentMap &PM) {
196  if (!TheCFG)
197  return;
198 
200  E = TheCFG->synthetic_stmt_end();
201  I != E; ++I) {
202  PM.setParent(I->first, PM.getParent(I->second));
203  }
204 }
205 
207  if (!cfgBuildOptions.PruneTriviallyFalseEdges)
208  return getUnoptimizedCFG();
209 
210  if (!builtCFG) {
211  cfg = CFG::buildCFG(D, getBody(), &D->getASTContext(), cfgBuildOptions);
212  // Even when the cfg is not successfully built, we don't
213  // want to try building it again.
214  builtCFG = true;
215 
216  if (PM)
217  addParentsForSyntheticStmts(cfg.get(), *PM);
218 
219  // The Observer should only observe one build of the CFG.
220  getCFGBuildOptions().Observer = nullptr;
221  }
222  return cfg.get();
223 }
224 
226  if (!builtCompleteCFG) {
227  SaveAndRestore<bool> NotPrune(cfgBuildOptions.PruneTriviallyFalseEdges,
228  false);
229  completeCFG =
230  CFG::buildCFG(D, getBody(), &D->getASTContext(), cfgBuildOptions);
231  // Even when the cfg is not successfully built, we don't
232  // want to try building it again.
233  builtCompleteCFG = true;
234 
235  if (PM)
236  addParentsForSyntheticStmts(completeCFG.get(), *PM);
237 
238  // The Observer should only observe one build of the CFG.
239  getCFGBuildOptions().Observer = nullptr;
240  }
241  return completeCFG.get();
242 }
243 
245  if (cfgStmtMap)
246  return cfgStmtMap.get();
247 
248  if (CFG *c = getCFG()) {
249  cfgStmtMap.reset(CFGStmtMap::Build(c, &getParentMap()));
250  return cfgStmtMap.get();
251  }
252 
253  return nullptr;
254 }
255 
257  if (CFA)
258  return CFA.get();
259 
260  if (CFG *c = getCFG()) {
261  CFA.reset(new CFGReverseBlockReachabilityAnalysis(*c));
262  return CFA.get();
263  }
264 
265  return nullptr;
266 }
267 
268 void AnalysisDeclContext::dumpCFG(bool ShowColors) {
269  getCFG()->dump(getASTContext().getLangOpts(), ShowColors);
270 }
271 
273  if (!PM) {
274  PM.reset(new ParentMap(getBody()));
275  if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(getDecl())) {
276  for (const auto *I : C->inits()) {
277  PM->addStmt(I->getInit());
278  }
279  }
280  if (builtCFG)
281  addParentsForSyntheticStmts(getCFG(), *PM);
282  if (builtCompleteCFG)
283  addParentsForSyntheticStmts(getUnoptimizedCFG(), *PM);
284  }
285  return *PM;
286 }
287 
289  if (!PCA)
290  PCA.reset(new PseudoConstantAnalysis(getBody()));
291  return PCA.get();
292 }
293 
295  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
296  // Calling 'hasBody' replaces 'FD' in place with the FunctionDecl
297  // that has the body.
298  FD->hasBody(FD);
299  D = FD;
300  }
301 
302  std::unique_ptr<AnalysisDeclContext> &AC = Contexts[D];
303  if (!AC)
304  AC = llvm::make_unique<AnalysisDeclContext>(this, D, cfgBuildOptions);
305  return AC.get();
306 }
307 
308 BodyFarm &AnalysisDeclContextManager::getBodyFarm() { return FunctionBodyFarm; }
309 
310 const StackFrameContext *
312  const CFGBlock *Blk, unsigned Idx) {
313  return getLocationContextManager().getStackFrame(this, Parent, S, Blk, Idx);
314 }
315 
318  const clang::BlockDecl *BD,
319  const void *ContextData) {
320  return getLocationContextManager().getBlockInvocationContext(this, parent,
321  BD, ContextData);
322 }
323 
326  const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
327  if (!ND)
328  return false;
329 
330  while (const DeclContext *Parent = ND->getParent()) {
331  if (!isa<NamespaceDecl>(Parent))
332  break;
333  ND = cast<NamespaceDecl>(Parent);
334  }
335 
336  return ND->isStdNamespace();
337 }
338 
339 LocationContextManager & AnalysisDeclContext::getLocationContextManager() {
340  assert(Manager &&
341  "Cannot create LocationContexts without an AnalysisDeclContextManager!");
342  return Manager->getLocationContextManager();
343 }
344 
345 //===----------------------------------------------------------------------===//
346 // FoldingSet profiling.
347 //===----------------------------------------------------------------------===//
348 
349 void LocationContext::ProfileCommon(llvm::FoldingSetNodeID &ID,
350  ContextKind ck,
351  AnalysisDeclContext *ctx,
352  const LocationContext *parent,
353  const void *data) {
354  ID.AddInteger(ck);
355  ID.AddPointer(ctx);
356  ID.AddPointer(parent);
357  ID.AddPointer(data);
358 }
359 
360 void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID) {
361  Profile(ID, getAnalysisDeclContext(), getParent(), CallSite, Block, Index);
362 }
363 
364 void ScopeContext::Profile(llvm::FoldingSetNodeID &ID) {
365  Profile(ID, getAnalysisDeclContext(), getParent(), Enter);
366 }
367 
368 void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) {
369  Profile(ID, getAnalysisDeclContext(), getParent(), BD, ContextData);
370 }
371 
372 //===----------------------------------------------------------------------===//
373 // LocationContext creation.
374 //===----------------------------------------------------------------------===//
375 
376 template <typename LOC, typename DATA>
377 const LOC*
378 LocationContextManager::getLocationContext(AnalysisDeclContext *ctx,
379  const LocationContext *parent,
380  const DATA *d) {
381  llvm::FoldingSetNodeID ID;
382  LOC::Profile(ID, ctx, parent, d);
383  void *InsertPos;
384 
385  LOC *L = cast_or_null<LOC>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
386 
387  if (!L) {
388  L = new LOC(ctx, parent, d);
389  Contexts.InsertNode(L, InsertPos);
390  }
391  return L;
392 }
393 
394 const StackFrameContext*
396  const LocationContext *parent,
397  const Stmt *s,
398  const CFGBlock *blk, unsigned idx) {
399  llvm::FoldingSetNodeID ID;
400  StackFrameContext::Profile(ID, ctx, parent, s, blk, idx);
401  void *InsertPos;
402  StackFrameContext *L =
403  cast_or_null<StackFrameContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
404  if (!L) {
405  L = new StackFrameContext(ctx, parent, s, blk, idx);
406  Contexts.InsertNode(L, InsertPos);
407  }
408  return L;
409 }
410 
411 const ScopeContext *
413  const LocationContext *parent,
414  const Stmt *s) {
415  return getLocationContext<ScopeContext, Stmt>(ctx, parent, s);
416 }
417 
420  const LocationContext *parent,
421  const BlockDecl *BD,
422  const void *ContextData) {
423  llvm::FoldingSetNodeID ID;
424  BlockInvocationContext::Profile(ID, ctx, parent, BD, ContextData);
425  void *InsertPos;
427  cast_or_null<BlockInvocationContext>(Contexts.FindNodeOrInsertPos(ID,
428  InsertPos));
429  if (!L) {
430  L = new BlockInvocationContext(ctx, parent, BD, ContextData);
431  Contexts.InsertNode(L, InsertPos);
432  }
433  return L;
434 }
435 
436 //===----------------------------------------------------------------------===//
437 // LocationContext methods.
438 //===----------------------------------------------------------------------===//
439 
441  const LocationContext *LC = this;
442  while (LC) {
443  if (const StackFrameContext *SFC = dyn_cast<StackFrameContext>(LC))
444  return SFC;
445  LC = LC->getParent();
446  }
447  return nullptr;
448 }
449 
451  return getCurrentStackFrame()->inTopFrame();
452 }
453 
455  do {
456  const LocationContext *Parent = LC->getParent();
457  if (Parent == this)
458  return true;
459  else
460  LC = Parent;
461  } while (LC);
462 
463  return false;
464 }
465 
466 void LocationContext::dumpStack(raw_ostream &OS, StringRef Indent) const {
467  ASTContext &Ctx = getAnalysisDeclContext()->getASTContext();
468  PrintingPolicy PP(Ctx.getLangOpts());
469  PP.TerseOutput = 1;
470 
471  unsigned Frame = 0;
472  for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
473  switch (LCtx->getKind()) {
474  case StackFrame:
475  OS << Indent << '#' << Frame++ << ' ';
476  cast<StackFrameContext>(LCtx)->getDecl()->print(OS, PP);
477  OS << '\n';
478  break;
479  case Scope:
480  OS << Indent << " (scope)\n";
481  break;
482  case Block:
483  OS << Indent << " (block context: "
484  << cast<BlockInvocationContext>(LCtx)->getContextData()
485  << ")\n";
486  break;
487  }
488  }
489 }
490 
491 LLVM_DUMP_METHOD void LocationContext::dumpStack() const {
492  dumpStack(llvm::errs());
493 }
494 
495 //===----------------------------------------------------------------------===//
496 // Lazily generated map to query the external variables referenced by a Block.
497 //===----------------------------------------------------------------------===//
498 
499 namespace {
500 class FindBlockDeclRefExprsVals : public StmtVisitor<FindBlockDeclRefExprsVals>{
502  BumpVectorContext &BC;
503  llvm::SmallPtrSet<const VarDecl*, 4> Visited;
504  llvm::SmallPtrSet<const DeclContext*, 4> IgnoredContexts;
505 public:
506  FindBlockDeclRefExprsVals(BumpVector<const VarDecl*> &bevals,
507  BumpVectorContext &bc)
508  : BEVals(bevals), BC(bc) {}
509 
510  void VisitStmt(Stmt *S) {
511  for (Stmt *Child : S->children())
512  if (Child)
513  Visit(Child);
514  }
515 
516  void VisitDeclRefExpr(DeclRefExpr *DR) {
517  // Non-local variables are also directly modified.
518  if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) {
519  if (!VD->hasLocalStorage()) {
520  if (Visited.insert(VD).second)
521  BEVals.push_back(VD, BC);
522  }
523  }
524  }
525 
526  void VisitBlockExpr(BlockExpr *BR) {
527  // Blocks containing blocks can transitively capture more variables.
528  IgnoredContexts.insert(BR->getBlockDecl());
529  Visit(BR->getBlockDecl()->getBody());
530  }
531 
532  void VisitPseudoObjectExpr(PseudoObjectExpr *PE) {
534  et = PE->semantics_end(); it != et; ++it) {
535  Expr *Semantic = *it;
536  if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Semantic))
537  Semantic = OVE->getSourceExpr();
538  Visit(Semantic);
539  }
540  }
541 };
542 } // end anonymous namespace
543 
545 
547  void *&Vec,
548  llvm::BumpPtrAllocator &A) {
549  if (Vec)
550  return (DeclVec*) Vec;
551 
552  BumpVectorContext BC(A);
553  DeclVec *BV = (DeclVec*) A.Allocate<DeclVec>();
554  new (BV) DeclVec(BC, 10);
555 
556  // Go through the capture list.
557  for (const auto &CI : BD->captures()) {
558  BV->push_back(CI.getVariable(), BC);
559  }
560 
561  // Find the referenced global/static variables.
562  FindBlockDeclRefExprsVals F(*BV, BC);
563  F.Visit(BD->getBody());
564 
565  Vec = BV;
566  return BV;
567 }
568 
569 llvm::iterator_range<AnalysisDeclContext::referenced_decls_iterator>
571  if (!ReferencedBlockVars)
572  ReferencedBlockVars = new llvm::DenseMap<const BlockDecl*,void*>();
573 
574  const DeclVec *V =
575  LazyInitializeReferencedDecls(BD, (*ReferencedBlockVars)[BD], A);
576  return llvm::make_range(V->begin(), V->end());
577 }
578 
579 ManagedAnalysis *&AnalysisDeclContext::getAnalysisImpl(const void *tag) {
580  if (!ManagedAnalyses)
581  ManagedAnalyses = new ManagedAnalysisMap();
582  ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses;
583  return (*M)[tag];
584 }
585 
586 //===----------------------------------------------------------------------===//
587 // Cleanup.
588 //===----------------------------------------------------------------------===//
589 
591 
593  delete forcedBlkExprs;
594  delete ReferencedBlockVars;
595  // Release the managed analyses.
596  if (ManagedAnalyses) {
597  ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses;
598  llvm::DeleteContainerSeconds(*M);
599  delete M;
600  }
601 }
602 
604 
606  clear();
607 }
608 
610  for (llvm::FoldingSet<LocationContext>::iterator I = Contexts.begin(),
611  E = Contexts.end(); I != E; ) {
612  LocationContext *LC = &*I;
613  ++I;
614  delete LC;
615  }
616 
617  Contexts.clear();
618 }
619 
Defines the clang::ASTContext interface.
const BlockDecl * getBlockDecl() const
Definition: Expr.h:4865
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1698
The base class of a hierarchy of objects representing analyses tied to AnalysisDeclContext.
BumpVector< const VarDecl * > DeclVec
void Profile(llvm::FoldingSetNodeID &ID) override
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
Stmt * getBody() const
Get the body of the Declaration.
Expr *const * semantics_iterator
Definition: Expr.h:5035
Stmt - This represents one statement.
Definition: Stmt.h:66
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Defines the C++ template declaration subclasses.
Stmt * getParent(Stmt *) const
Definition: ParentMap.cpp:122
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:506
capture_const_range captures() const
Definition: DeclCXX.h:1200
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:26
bool AddStaticInitBranches
Definition: CFG.h:855
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2397
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:807
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
unsigned TerseOutput
Provide a &#39;terse&#39; output.
bool isParentOf(const LocationContext *LC) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
AnalysisDeclContext contains the context data for the function or method under analysis.
void addStmt(Stmt *S)
Adds and/or updates the parent/child-relations of the complete stmt tree of S.
Definition: ParentMap.cpp:109
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition: Decl.h:3767
void setParent(const Stmt *S, const Stmt *Parent)
Manually sets the parent of S to Parent.
Definition: ParentMap.cpp:115
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
Definition: DeclBase.cpp:1656
static bool isInStdNamespace(const Decl *D)
Returns true if the root namespace of the given declaration is the &#39;std&#39; C++ namespace.
llvm::DenseMap< const void *, ManagedAnalysis * > ManagedAnalysisMap
CFGReverseBlockReachabilityAnalysis * getCFGReachablityAnalysis()
const StackFrameContext * getCurrentStackFrame() const
CFGCallback * Observer
Definition: CFG.h:847
child_range children()
Definition: Stmt.cpp:226
virtual bool inTopFrame() const
Return true if the current LocationContext has no caller context.
semantics_iterator semantics_end()
Definition: Expr.h:5043
const LocationContext * getParent() const
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:1152
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:39
void clear()
Discard all previously created LocationContext objects.
llvm::DenseMap< const DeclStmt *, const DeclStmt * >::const_iterator synthetic_stmt_iterator
Definition: CFG.h:956
llvm::DenseMap< const Stmt *, const CFGBlock * > ForcedBlkExprs
Definition: CFG.h:844
NodeId Parent
Definition: ASTDiff.cpp:192
ForcedBlkExprs ** forcedBlkExprs
Definition: CFG.h:846
CFGBlock - Represents a single basic block in a source-level CFG.
Definition: CFG.h:422
AnalysisDeclContext * getContext(const Decl *D)
bool isBodyAutosynthesizedFromModelFile() const
Checks if the body of the Decl is generated by the BodyFarm from a model file.
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
Definition: Decl.h:3689
Expr - This represents one expression.
Definition: Expr.h:106
CFG - Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
Definition: CFG.h:834
void Profile(llvm::FoldingSetNodeID &ID) override
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:4851
DeclContext * getDeclContext()
Definition: DeclBase.h:425
BodyFarm & getBodyFarm()
Get a reference to {.
const CFGBlock * getBlockForRegisteredExpression(const Stmt *stmt)
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1331
bool isBodyAutosynthesized() const
Checks if the body of the Decl is generated by the BodyFarm.
const ScopeContext * getScope(AnalysisDeclContext *ctx, const LocationContext *parent, const Stmt *s)
const StackFrameContext * getStackFrame(LocationContext const *Parent, const Stmt *S, const CFGBlock *Blk, unsigned Idx)
ValueDecl * getDecl()
Definition: Expr.h:1041
CFG::BuildOptions & getCFGBuildOptions()
const StackFrameContext * getStackFrame(AnalysisDeclContext *ctx, const LocationContext *parent, const Stmt *s, const CFGBlock *blk, unsigned idx)
CFG * getUnoptimizedCFG()
Return a version of the CFG without any edges pruned.
const ImplicitParamDecl * getSelfDecl() const
Return the ImplicitParamDecl* associated with &#39;self&#39; if this AnalysisDeclContext wraps an ObjCMethodD...
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Definition: Expr.h:868
#define false
Definition: stdbool.h:33
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:4969
static std::unique_ptr< CFG > buildCFG(const Decl *D, Stmt *AST, ASTContext *C, const BuildOptions &BO)
buildCFG - Builds a CFG from an AST.
Definition: CFG.cpp:4204
bool PruneTriviallyFalseEdges
Definition: CFG.h:848
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1964
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:183
bool isStdNamespace() const
Definition: DeclBase.cpp:1010
void push_back(const_reference Elt, BumpVectorContext &C)
Definition: BumpVector.h:160
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
static CFGStmtMap * Build(CFG *C, ParentMap *PM)
Returns a new CFGMap for the given CFG.
Definition: CFGStmtMap.cpp:78
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1252
ArrayRef< Capture > captures() const
Definition: Decl.h:3815
CodeInjector is an interface which is responsible for injecting AST of function definitions that may ...
Definition: CodeInjector.h:36
llvm::iterator_range< referenced_decls_iterator > getReferencedBlockVars(const BlockDecl *BD)
static DeclVec * LazyInitializeReferencedDecls(const BlockDecl *BD, void *&Vec, llvm::BumpPtrAllocator &A)
void Profile(llvm::FoldingSetNodeID &ID) override
semantics_iterator semantics_begin()
Definition: Expr.h:5037
static bool isSelfDecl(const VarDecl *VD)
Returns true if.
static void addParentsForSyntheticStmts(const CFG *TheCFG, ParentMap &PM)
Add each synthetic statement in the CFG to the parent map, using the source statement&#39;s parent...
PseudoConstantAnalysis * getPseudoConstantAnalysis()
const BlockInvocationContext * getBlockInvocationContext(AnalysisDeclContext *ctx, const LocationContext *parent, const BlockDecl *BD, const void *ContextData)
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
synthetic_stmt_iterator synthetic_stmt_end() const
Definition: CFG.h:969
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:270
void registerForcedBlockExpression(const Stmt *stmt)
synthetic_stmt_iterator synthetic_stmt_begin() const
Iterates over synthetic DeclStmts in the CFG.
Definition: CFG.h:964
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:956
const BlockInvocationContext * getBlockInvocationContext(const LocationContext *parent, const BlockDecl *BD, const void *ContextData)
void clear()
Discard all previously created AnalysisDeclContexts.
SourceLocation getLocStart() const LLVM_READONLY
Definition: Stmt.cpp:277
const LangOptions & getLangOpts() const
Definition: ASTContext.h:688
Declaration of a template function.
Definition: DeclTemplate.h:958
AnalysisDeclContextManager(ASTContext &ASTCtx, bool useUnoptimizedCFG=false, bool addImplicitDtors=false, bool addInitializers=false, bool addTemporaryDtors=false, bool addLifetime=false, bool addLoopExit=false, bool synthesizeBodies=false, bool addStaticInitBranches=false, bool addCXXNewAllocator=true, CodeInjector *injector=nullptr)
AnalysisDeclContext(AnalysisDeclContextManager *Mgr, const Decl *D)
static void ProfileCommon(llvm::FoldingSetNodeID &ID, ContextKind ck, AnalysisDeclContext *ctx, const LocationContext *parent, const void *data)