clang  7.0.0svn
AnalysisDeclContext.cpp
Go to the documentation of this file.
1 //===- AnalysisDeclContext.cpp - Analysis context for Path Sens analysis --===//
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
11 // context data for path sensitive analysis.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/DeclBase.h"
19 #include "clang/AST/DeclCXX.h"
20 #include "clang/AST/DeclObjC.h"
21 #include "clang/AST/DeclTemplate.h"
22 #include "clang/AST/Expr.h"
24 #include "clang/AST/ParentMap.h"
26 #include "clang/AST/Stmt.h"
27 #include "clang/AST/StmtCXX.h"
28 #include "clang/AST/StmtVisitor.h"
32 #include "clang/Analysis/CFG.h"
35 #include "clang/Basic/LLVM.h"
38 #include "llvm/ADT/DenseMap.h"
39 #include "llvm/ADT/FoldingSet.h"
40 #include "llvm/ADT/STLExtras.h"
41 #include "llvm/ADT/SmallPtrSet.h"
42 #include "llvm/ADT/iterator_range.h"
43 #include "llvm/Support/Allocator.h"
44 #include "llvm/Support/Casting.h"
45 #include "llvm/Support/Compiler.h"
46 #include "llvm/Support/ErrorHandling.h"
47 #include "llvm/Support/SaveAndRestore.h"
48 #include "llvm/Support/raw_ostream.h"
49 #include <cassert>
50 #include <memory>
51 
52 using namespace clang;
53 
54 using ManagedAnalysisMap = llvm::DenseMap<const void *, ManagedAnalysis *>;
55 
57  const Decl *d,
58  const CFG::BuildOptions &buildOptions)
59  : Manager(Mgr), D(d), cfgBuildOptions(buildOptions) {
60  cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
61 }
62 
64  const Decl *d)
65  : Manager(Mgr), D(d) {
66  cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
67 }
68 
70  ASTContext &ASTCtx, bool useUnoptimizedCFG, bool addImplicitDtors,
71  bool addInitializers, bool addTemporaryDtors, bool addLifetime,
72  bool addLoopExit, bool addScopes, bool synthesizeBodies,
73  bool addStaticInitBranch, bool addCXXNewAllocator,
74  bool addRichCXXConstructors, CodeInjector *injector)
75  : Injector(injector), FunctionBodyFarm(ASTCtx, injector),
76  SynthesizeBodies(synthesizeBodies) {
77  cfgBuildOptions.PruneTriviallyFalseEdges = !useUnoptimizedCFG;
78  cfgBuildOptions.AddImplicitDtors = addImplicitDtors;
79  cfgBuildOptions.AddInitializers = addInitializers;
80  cfgBuildOptions.AddTemporaryDtors = addTemporaryDtors;
81  cfgBuildOptions.AddLifetime = addLifetime;
82  cfgBuildOptions.AddLoopExit = addLoopExit;
83  cfgBuildOptions.AddScopes = addScopes;
84  cfgBuildOptions.AddStaticInitBranches = addStaticInitBranch;
85  cfgBuildOptions.AddCXXNewAllocator = addCXXNewAllocator;
86  cfgBuildOptions.AddRichCXXConstructors = addRichCXXConstructors;
87 }
88 
89 void AnalysisDeclContextManager::clear() { Contexts.clear(); }
90 
91 Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const {
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 
125  bool Tmp;
126  return getBody(Tmp);
127 }
128 
130  bool Tmp;
131  getBody(Tmp);
132  return Tmp;
133 }
134 
136  bool Tmp;
137  Stmt *Body = getBody(Tmp);
138  return Tmp && Body->getLocStart().isValid();
139 }
140 
141 /// Returns true if \param VD is an Objective-C implicit 'self' parameter.
142 static bool isSelfDecl(const VarDecl *VD) {
143  return isa<ImplicitParamDecl>(VD) && VD->getName() == "self";
144 }
145 
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 
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 
187 const CFGBlock *
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  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.
200 static void addParentsForSyntheticStmts(const CFG *TheCFG, ParentMap &PM) {
201  if (!TheCFG)
202  return;
203 
205  E = TheCFG->synthetic_stmt_end();
206  I != E; ++I) {
207  PM.setParent(I->first, PM.getParent(I->second));
208  }
209 }
210 
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 
231  if (!builtCompleteCFG) {
232  SaveAndRestore<bool> NotPrune(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 
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 
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 
273 void AnalysisDeclContext::dumpCFG(bool ShowColors) {
274  getCFG()->dump(getASTContext().getLangOpts(), ShowColors);
275 }
276 
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 
294  if (!PCA)
295  PCA.reset(new PseudoConstantAnalysis(getBody()));
296  return PCA.get();
297 }
298 
300  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
301  // Calling 'hasBody' replaces 'FD' in place with the FunctionDecl
302  // that has the body.
303  FD->hasBody(FD);
304  D = FD;
305  }
306 
307  std::unique_ptr<AnalysisDeclContext> &AC = Contexts[D];
308  if (!AC)
309  AC = llvm::make_unique<AnalysisDeclContext>(this, D, cfgBuildOptions);
310  return AC.get();
311 }
312 
313 BodyFarm &AnalysisDeclContextManager::getBodyFarm() { return FunctionBodyFarm; }
314 
315 const StackFrameContext *
317  const CFGBlock *Blk, unsigned Idx) {
318  return getLocationContextManager().getStackFrame(this, Parent, S, Blk, Idx);
319 }
320 
323  const BlockDecl *BD,
324  const void *ContextData) {
325  return getLocationContextManager().getBlockInvocationContext(this, parent,
326  BD, ContextData);
327 }
328 
331  const auto *ND = dyn_cast<NamespaceDecl>(DC);
332  if (!ND)
333  return false;
334 
335  while (const DeclContext *Parent = ND->getParent()) {
336  if (!isa<NamespaceDecl>(Parent))
337  break;
338  ND = cast<NamespaceDecl>(Parent);
339  }
340 
341  return ND->isStdNamespace();
342 }
343 
344 LocationContextManager &AnalysisDeclContext::getLocationContextManager() {
345  assert(Manager &&
346  "Cannot create LocationContexts without an AnalysisDeclContextManager!");
347  return Manager->getLocationContextManager();
348 }
349 
350 //===----------------------------------------------------------------------===//
351 // FoldingSet profiling.
352 //===----------------------------------------------------------------------===//
353 
354 void LocationContext::ProfileCommon(llvm::FoldingSetNodeID &ID,
355  ContextKind ck,
356  AnalysisDeclContext *ctx,
357  const LocationContext *parent,
358  const void *data) {
359  ID.AddInteger(ck);
360  ID.AddPointer(ctx);
361  ID.AddPointer(parent);
362  ID.AddPointer(data);
363 }
364 
365 void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID) {
366  Profile(ID, getAnalysisDeclContext(), getParent(), CallSite, Block, Index);
367 }
368 
369 void ScopeContext::Profile(llvm::FoldingSetNodeID &ID) {
370  Profile(ID, getAnalysisDeclContext(), getParent(), Enter);
371 }
372 
373 void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) {
374  Profile(ID, getAnalysisDeclContext(), getParent(), BD, ContextData);
375 }
376 
377 //===----------------------------------------------------------------------===//
378 // LocationContext creation.
379 //===----------------------------------------------------------------------===//
380 
381 template <typename LOC, typename DATA>
382 const LOC*
383 LocationContextManager::getLocationContext(AnalysisDeclContext *ctx,
384  const LocationContext *parent,
385  const DATA *d) {
386  llvm::FoldingSetNodeID ID;
387  LOC::Profile(ID, ctx, parent, d);
388  void *InsertPos;
389 
390  LOC *L = cast_or_null<LOC>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
391 
392  if (!L) {
393  L = new LOC(ctx, parent, d);
394  Contexts.InsertNode(L, InsertPos);
395  }
396  return L;
397 }
398 
399 const StackFrameContext*
401  const LocationContext *parent,
402  const Stmt *s,
403  const CFGBlock *blk, unsigned idx) {
404  llvm::FoldingSetNodeID ID;
405  StackFrameContext::Profile(ID, ctx, parent, s, blk, idx);
406  void *InsertPos;
407  auto *L =
408  cast_or_null<StackFrameContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
409  if (!L) {
410  L = new StackFrameContext(ctx, parent, s, blk, idx);
411  Contexts.InsertNode(L, InsertPos);
412  }
413  return L;
414 }
415 
416 const ScopeContext *
418  const LocationContext *parent,
419  const Stmt *s) {
420  return getLocationContext<ScopeContext, Stmt>(ctx, parent, s);
421 }
422 
425  const LocationContext *parent,
426  const BlockDecl *BD,
427  const void *ContextData) {
428  llvm::FoldingSetNodeID ID;
429  BlockInvocationContext::Profile(ID, ctx, parent, BD, ContextData);
430  void *InsertPos;
431  auto *L =
432  cast_or_null<BlockInvocationContext>(Contexts.FindNodeOrInsertPos(ID,
433  InsertPos));
434  if (!L) {
435  L = new BlockInvocationContext(ctx, parent, BD, ContextData);
436  Contexts.InsertNode(L, InsertPos);
437  }
438  return L;
439 }
440 
441 //===----------------------------------------------------------------------===//
442 // LocationContext methods.
443 //===----------------------------------------------------------------------===//
444 
446  const LocationContext *LC = this;
447  while (LC) {
448  if (const auto *SFC = dyn_cast<StackFrameContext>(LC))
449  return SFC;
450  LC = LC->getParent();
451  }
452  return nullptr;
453 }
454 
456  return getCurrentStackFrame()->inTopFrame();
457 }
458 
460  do {
461  const LocationContext *Parent = LC->getParent();
462  if (Parent == this)
463  return true;
464  else
465  LC = Parent;
466  } while (LC);
467 
468  return false;
469 }
470 
471 static void printLocation(raw_ostream &OS, const SourceManager &SM,
472  SourceLocation SLoc) {
473  if (SLoc.isFileID() && SM.isInMainFile(SLoc))
474  OS << "line " << SM.getExpansionLineNumber(SLoc);
475  else
476  SLoc.print(OS, SM);
477 }
478 
480  raw_ostream &OS, StringRef Indent, const char *NL, const char *Sep,
481  std::function<void(const LocationContext *)> printMoreInfoPerContext) const {
482  ASTContext &Ctx = getAnalysisDeclContext()->getASTContext();
483  PrintingPolicy PP(Ctx.getLangOpts());
484  PP.TerseOutput = 1;
485 
486  const SourceManager &SM =
487  getAnalysisDeclContext()->getASTContext().getSourceManager();
488 
489  unsigned Frame = 0;
490  for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
491  switch (LCtx->getKind()) {
492  case StackFrame:
493  OS << Indent << '#' << Frame << ' ';
494  ++Frame;
495  if (const auto *D = dyn_cast<NamedDecl>(LCtx->getDecl()))
496  OS << "Calling " << D->getQualifiedNameAsString();
497  else
498  OS << "Calling anonymous code";
499  if (const Stmt *S = cast<StackFrameContext>(LCtx)->getCallSite()) {
500  OS << " at ";
501  printLocation(OS, SM, S->getLocStart());
502  }
503  break;
504  case Scope:
505  OS << "Entering scope";
506  break;
507  case Block:
508  OS << "Invoking block";
509  if (const Decl *D = cast<BlockInvocationContext>(LCtx)->getDecl()) {
510  OS << " defined at ";
511  printLocation(OS, SM, D->getLocStart());
512  }
513  break;
514  }
515  OS << NL;
516 
517  printMoreInfoPerContext(LCtx);
518  }
519 }
520 
521 LLVM_DUMP_METHOD void LocationContext::dumpStack() const {
522  dumpStack(llvm::errs());
523 }
524 
525 //===----------------------------------------------------------------------===//
526 // Lazily generated map to query the external variables referenced by a Block.
527 //===----------------------------------------------------------------------===//
528 
529 namespace {
530 
531 class FindBlockDeclRefExprsVals : public StmtVisitor<FindBlockDeclRefExprsVals>{
533  BumpVectorContext &BC;
534  llvm::SmallPtrSet<const VarDecl *, 4> Visited;
535  llvm::SmallPtrSet<const DeclContext *, 4> IgnoredContexts;
536 
537 public:
538  FindBlockDeclRefExprsVals(BumpVector<const VarDecl*> &bevals,
539  BumpVectorContext &bc)
540  : BEVals(bevals), BC(bc) {}
541 
542  void VisitStmt(Stmt *S) {
543  for (auto *Child : S->children())
544  if (Child)
545  Visit(Child);
546  }
547 
548  void VisitDeclRefExpr(DeclRefExpr *DR) {
549  // Non-local variables are also directly modified.
550  if (const auto *VD = dyn_cast<VarDecl>(DR->getDecl())) {
551  if (!VD->hasLocalStorage()) {
552  if (Visited.insert(VD).second)
553  BEVals.push_back(VD, BC);
554  }
555  }
556  }
557 
558  void VisitBlockExpr(BlockExpr *BR) {
559  // Blocks containing blocks can transitively capture more variables.
560  IgnoredContexts.insert(BR->getBlockDecl());
561  Visit(BR->getBlockDecl()->getBody());
562  }
563 
564  void VisitPseudoObjectExpr(PseudoObjectExpr *PE) {
566  et = PE->semantics_end(); it != et; ++it) {
567  Expr *Semantic = *it;
568  if (auto *OVE = dyn_cast<OpaqueValueExpr>(Semantic))
569  Semantic = OVE->getSourceExpr();
570  Visit(Semantic);
571  }
572  }
573 };
574 
575 } // namespace
576 
578 
580  void *&Vec,
581  llvm::BumpPtrAllocator &A) {
582  if (Vec)
583  return (DeclVec*) Vec;
584 
585  BumpVectorContext BC(A);
586  DeclVec *BV = (DeclVec*) A.Allocate<DeclVec>();
587  new (BV) DeclVec(BC, 10);
588 
589  // Go through the capture list.
590  for (const auto &CI : BD->captures()) {
591  BV->push_back(CI.getVariable(), BC);
592  }
593 
594  // Find the referenced global/static variables.
595  FindBlockDeclRefExprsVals F(*BV, BC);
596  F.Visit(BD->getBody());
597 
598  Vec = BV;
599  return BV;
600 }
601 
602 llvm::iterator_range<AnalysisDeclContext::referenced_decls_iterator>
604  if (!ReferencedBlockVars)
605  ReferencedBlockVars = new llvm::DenseMap<const BlockDecl*,void*>();
606 
607  const DeclVec *V =
608  LazyInitializeReferencedDecls(BD, (*ReferencedBlockVars)[BD], A);
609  return llvm::make_range(V->begin(), V->end());
610 }
611 
612 ManagedAnalysis *&AnalysisDeclContext::getAnalysisImpl(const void *tag) {
613  if (!ManagedAnalyses)
614  ManagedAnalyses = new ManagedAnalysisMap();
615  ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses;
616  return (*M)[tag];
617 }
618 
619 //===----------------------------------------------------------------------===//
620 // Cleanup.
621 //===----------------------------------------------------------------------===//
622 
624 
626  delete forcedBlkExprs;
627  delete ReferencedBlockVars;
628  // Release the managed analyses.
629  if (ManagedAnalyses) {
630  ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses;
631  llvm::DeleteContainerSeconds(*M);
632  delete M;
633  }
634 }
635 
637 
639  clear();
640 }
641 
643  for (llvm::FoldingSet<LocationContext>::iterator I = Contexts.begin(),
644  E = Contexts.end(); I != E; ) {
645  LocationContext *LC = &*I;
646  ++I;
647  delete LC;
648  }
649  Contexts.clear();
650 }
Defines the clang::ASTContext interface.
const BlockDecl * getBlockDecl() const
Definition: Expr.h:4904
The base class of a hierarchy of objects representing analyses tied to AnalysisDeclContext.
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:5074
Stmt - This represents one statement.
Definition: Stmt.h:66
Defines the SourceManager interface.
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:123
Represent a C++ namespace.
Definition: Decl.h:514
capture_const_range captures() const
Definition: DeclCXX.h:1238
bool AddStaticInitBranches
Definition: CFG.h:1024
Represents a variable declaration or definition.
Definition: Decl.h:812
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
AnalysisDeclContextManager(ASTContext &ASTCtx, bool useUnoptimizedCFG=false, bool addImplicitDtors=false, bool addInitializers=false, bool addTemporaryDtors=false, bool addLifetime=false, bool addLoopExit=false, bool addScopes=false, bool synthesizeBodies=false, bool addStaticInitBranches=false, bool addCXXNewAllocator=true, bool addRichCXXConstructors=true, CodeInjector *injector=nullptr)
void print(raw_ostream &OS, const SourceManager &SM) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:150
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:110
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:3920
void setParent(const Stmt *S, const Stmt *Parent)
Manually sets the parent of S to Parent.
Definition: ParentMap.cpp:116
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
Definition: DeclBase.cpp:1677
static bool isInStdNamespace(const Decl *D)
Returns true if the root namespace of the given declaration is the &#39;std&#39; C++ namespace.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
CFGReverseBlockReachabilityAnalysis * getCFGReachablityAnalysis()
const StackFrameContext * getCurrentStackFrame() const
CFGCallback * Observer
Definition: CFG.h:1015
child_range children()
Definition: Stmt.cpp:227
virtual bool inTopFrame() const
Return true if the current LocationContext has no caller context.
semantics_iterator semantics_end()
Definition: Expr.h:5082
const LocationContext * getParent() const
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:1190
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
void clear()
Discard all previously created LocationContext objects.
llvm::DenseMap< const DeclStmt *, const DeclStmt * >::const_iterator synthetic_stmt_iterator
Definition: CFG.h:1126
llvm::DenseMap< const Stmt *, const CFGBlock * > ForcedBlkExprs
Definition: CFG.h:1012
NodeId Parent
Definition: ASTDiff.cpp:192
ForcedBlkExprs ** forcedBlkExprs
Definition: CFG.h:1014
CFGBlock - Represents a single basic block in a source-level CFG.
Definition: CFG.h:548
AnalysisDeclContext * getContext(const Decl *D)
static void printLocation(raw_ostream &OS, const SourceManager &SM, SourceLocation SLoc)
bool isBodyAutosynthesizedFromModelFile() const
Checks if the body of the Decl is generated by the BodyFarm from a model file.
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:3838
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:1002
BumpVector< const VarDecl * > DeclVec
void Profile(llvm::FoldingSetNodeID &ID) override
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:4890
DeclContext * getDeclContext()
Definition: DeclBase.h:426
BodyFarm & getBodyFarm()
Get a reference to {.
const CFGBlock * getBlockForRegisteredExpression(const Stmt *stmt)
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1341
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:1057
CFG::BuildOptions & getCFGBuildOptions()
const StackFrameContext * getStackFrame(AnalysisDeclContext *ctx, const LocationContext *parent, const Stmt *s, const CFGBlock *blk, unsigned idx)
unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
const SourceManager & SM
Definition: Format.cpp:1468
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...
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:5008
Encodes a location in the source.
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:4563
bool PruneTriviallyFalseEdges
Definition: CFG.h:1016
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2031
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:186
bool isStdNamespace() const
Definition: DeclBase.cpp:1024
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
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:1262
ArrayRef< Capture > captures() const
Definition: Decl.h:3968
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:5076
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)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
llvm::DenseMap< const void *, ManagedAnalysis * > ManagedAnalysisMap
Defines the clang::SourceLocation class and associated facilities.
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
synthetic_stmt_iterator synthetic_stmt_end() const
Definition: CFG.h:1139
bool AddRichCXXConstructors
Definition: CFG.h:1027
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:275
void registerForcedBlockExpression(const Stmt *stmt)
synthetic_stmt_iterator synthetic_stmt_begin() const
Iterates over synthetic DeclStmts in the CFG.
Definition: CFG.h:1134
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:972
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:278
const LangOptions & getLangOpts() const
Definition: ASTContext.h:689
This class handles loading and caching of source files into memory.
AnalysisDeclContext(AnalysisDeclContextManager *Mgr, const Decl *D)
static void ProfileCommon(llvm::FoldingSetNodeID &ID, ContextKind ck, AnalysisDeclContext *ctx, const LocationContext *parent, const void *data)
Defines the LambdaCapture class.