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, bool markElidedCXXConstructors,
75  CodeInjector *injector)
76  : Injector(injector), FunctionBodyFarm(ASTCtx, injector),
77  SynthesizeBodies(synthesizeBodies) {
78  cfgBuildOptions.PruneTriviallyFalseEdges = !useUnoptimizedCFG;
79  cfgBuildOptions.AddImplicitDtors = addImplicitDtors;
80  cfgBuildOptions.AddInitializers = addInitializers;
81  cfgBuildOptions.AddTemporaryDtors = addTemporaryDtors;
82  cfgBuildOptions.AddLifetime = addLifetime;
83  cfgBuildOptions.AddLoopExit = addLoopExit;
84  cfgBuildOptions.AddScopes = addScopes;
85  cfgBuildOptions.AddStaticInitBranches = addStaticInitBranch;
86  cfgBuildOptions.AddCXXNewAllocator = addCXXNewAllocator;
87  cfgBuildOptions.AddRichCXXConstructors = addRichCXXConstructors;
88  cfgBuildOptions.MarkElidedCXXConstructors = markElidedCXXConstructors;
89 }
90 
91 void AnalysisDeclContextManager::clear() { Contexts.clear(); }
92 
93 Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const {
94  IsAutosynthesized = false;
95  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
96  Stmt *Body = FD->getBody();
97  if (auto *CoroBody = dyn_cast_or_null<CoroutineBodyStmt>(Body))
98  Body = CoroBody->getBody();
99  if (Manager && Manager->synthesizeBodies()) {
100  Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(FD);
101  if (SynthesizedBody) {
102  Body = SynthesizedBody;
103  IsAutosynthesized = true;
104  }
105  }
106  return Body;
107  }
108  else if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
109  Stmt *Body = MD->getBody();
110  if (Manager && Manager->synthesizeBodies()) {
111  Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(MD);
112  if (SynthesizedBody) {
113  Body = SynthesizedBody;
114  IsAutosynthesized = true;
115  }
116  }
117  return Body;
118  } else if (const auto *BD = dyn_cast<BlockDecl>(D))
119  return BD->getBody();
120  else if (const auto *FunTmpl = dyn_cast_or_null<FunctionTemplateDecl>(D))
121  return FunTmpl->getTemplatedDecl()->getBody();
122 
123  llvm_unreachable("unknown code decl");
124 }
125 
127  bool Tmp;
128  return getBody(Tmp);
129 }
130 
132  bool Tmp;
133  getBody(Tmp);
134  return Tmp;
135 }
136 
138  bool Tmp;
139  Stmt *Body = getBody(Tmp);
140  return Tmp && Body->getLocStart().isValid();
141 }
142 
143 /// Returns true if \param VD is an Objective-C implicit 'self' parameter.
144 static bool isSelfDecl(const VarDecl *VD) {
145  return isa<ImplicitParamDecl>(VD) && VD->getName() == "self";
146 }
147 
149  if (const auto *MD = dyn_cast<ObjCMethodDecl>(D))
150  return MD->getSelfDecl();
151  if (const auto *BD = dyn_cast<BlockDecl>(D)) {
152  // See if 'self' was captured by the block.
153  for (const auto &I : BD->captures()) {
154  const VarDecl *VD = I.getVariable();
155  if (isSelfDecl(VD))
156  return dyn_cast<ImplicitParamDecl>(VD);
157  }
158  }
159 
160  auto *CXXMethod = dyn_cast<CXXMethodDecl>(D);
161  if (!CXXMethod)
162  return nullptr;
163 
164  const CXXRecordDecl *parent = CXXMethod->getParent();
165  if (!parent->isLambda())
166  return nullptr;
167 
168  for (const auto &LC : parent->captures()) {
169  if (!LC.capturesVariable())
170  continue;
171 
172  VarDecl *VD = LC.getCapturedVar();
173  if (isSelfDecl(VD))
174  return dyn_cast<ImplicitParamDecl>(VD);
175  }
176 
177  return nullptr;
178 }
179 
181  if (!forcedBlkExprs)
182  forcedBlkExprs = new CFG::BuildOptions::ForcedBlkExprs();
183  // Default construct an entry for 'stmt'.
184  if (const auto *e = dyn_cast<Expr>(stmt))
185  stmt = e->IgnoreParens();
186  (void) (*forcedBlkExprs)[stmt];
187 }
188 
189 const CFGBlock *
191  assert(forcedBlkExprs);
192  if (const auto *e = dyn_cast<Expr>(stmt))
193  stmt = e->IgnoreParens();
194  CFG::BuildOptions::ForcedBlkExprs::const_iterator itr =
195  forcedBlkExprs->find(stmt);
196  assert(itr != forcedBlkExprs->end());
197  return itr->second;
198 }
199 
200 /// Add each synthetic statement in the CFG to the parent map, using the
201 /// source statement's parent.
202 static void addParentsForSyntheticStmts(const CFG *TheCFG, ParentMap &PM) {
203  if (!TheCFG)
204  return;
205 
207  E = TheCFG->synthetic_stmt_end();
208  I != E; ++I) {
209  PM.setParent(I->first, PM.getParent(I->second));
210  }
211 }
212 
214  if (!cfgBuildOptions.PruneTriviallyFalseEdges)
215  return getUnoptimizedCFG();
216 
217  if (!builtCFG) {
218  cfg = CFG::buildCFG(D, getBody(), &D->getASTContext(), cfgBuildOptions);
219  // Even when the cfg is not successfully built, we don't
220  // want to try building it again.
221  builtCFG = true;
222 
223  if (PM)
224  addParentsForSyntheticStmts(cfg.get(), *PM);
225 
226  // The Observer should only observe one build of the CFG.
227  getCFGBuildOptions().Observer = nullptr;
228  }
229  return cfg.get();
230 }
231 
233  if (!builtCompleteCFG) {
234  SaveAndRestore<bool> NotPrune(cfgBuildOptions.PruneTriviallyFalseEdges,
235  false);
236  completeCFG =
237  CFG::buildCFG(D, getBody(), &D->getASTContext(), cfgBuildOptions);
238  // Even when the cfg is not successfully built, we don't
239  // want to try building it again.
240  builtCompleteCFG = true;
241 
242  if (PM)
243  addParentsForSyntheticStmts(completeCFG.get(), *PM);
244 
245  // The Observer should only observe one build of the CFG.
246  getCFGBuildOptions().Observer = nullptr;
247  }
248  return completeCFG.get();
249 }
250 
252  if (cfgStmtMap)
253  return cfgStmtMap.get();
254 
255  if (CFG *c = getCFG()) {
256  cfgStmtMap.reset(CFGStmtMap::Build(c, &getParentMap()));
257  return cfgStmtMap.get();
258  }
259 
260  return nullptr;
261 }
262 
264  if (CFA)
265  return CFA.get();
266 
267  if (CFG *c = getCFG()) {
268  CFA.reset(new CFGReverseBlockReachabilityAnalysis(*c));
269  return CFA.get();
270  }
271 
272  return nullptr;
273 }
274 
275 void AnalysisDeclContext::dumpCFG(bool ShowColors) {
276  getCFG()->dump(getASTContext().getLangOpts(), ShowColors);
277 }
278 
280  if (!PM) {
281  PM.reset(new ParentMap(getBody()));
282  if (const auto *C = dyn_cast<CXXConstructorDecl>(getDecl())) {
283  for (const auto *I : C->inits()) {
284  PM->addStmt(I->getInit());
285  }
286  }
287  if (builtCFG)
288  addParentsForSyntheticStmts(getCFG(), *PM);
289  if (builtCompleteCFG)
290  addParentsForSyntheticStmts(getUnoptimizedCFG(), *PM);
291  }
292  return *PM;
293 }
294 
296  if (!PCA)
297  PCA.reset(new PseudoConstantAnalysis(getBody()));
298  return PCA.get();
299 }
300 
302  if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
303  // Calling 'hasBody' replaces 'FD' in place with the FunctionDecl
304  // that has the body.
305  FD->hasBody(FD);
306  D = FD;
307  }
308 
309  std::unique_ptr<AnalysisDeclContext> &AC = Contexts[D];
310  if (!AC)
311  AC = llvm::make_unique<AnalysisDeclContext>(this, D, cfgBuildOptions);
312  return AC.get();
313 }
314 
315 BodyFarm &AnalysisDeclContextManager::getBodyFarm() { return FunctionBodyFarm; }
316 
317 const StackFrameContext *
319  const CFGBlock *Blk, unsigned Idx) {
320  return getLocationContextManager().getStackFrame(this, Parent, S, Blk, Idx);
321 }
322 
325  const BlockDecl *BD,
326  const void *ContextData) {
327  return getLocationContextManager().getBlockInvocationContext(this, parent,
328  BD, ContextData);
329 }
330 
333  const auto *ND = dyn_cast<NamespaceDecl>(DC);
334  if (!ND)
335  return false;
336 
337  while (const DeclContext *Parent = ND->getParent()) {
338  if (!isa<NamespaceDecl>(Parent))
339  break;
340  ND = cast<NamespaceDecl>(Parent);
341  }
342 
343  return ND->isStdNamespace();
344 }
345 
346 LocationContextManager &AnalysisDeclContext::getLocationContextManager() {
347  assert(Manager &&
348  "Cannot create LocationContexts without an AnalysisDeclContextManager!");
349  return Manager->getLocationContextManager();
350 }
351 
352 //===----------------------------------------------------------------------===//
353 // FoldingSet profiling.
354 //===----------------------------------------------------------------------===//
355 
356 void LocationContext::ProfileCommon(llvm::FoldingSetNodeID &ID,
357  ContextKind ck,
358  AnalysisDeclContext *ctx,
359  const LocationContext *parent,
360  const void *data) {
361  ID.AddInteger(ck);
362  ID.AddPointer(ctx);
363  ID.AddPointer(parent);
364  ID.AddPointer(data);
365 }
366 
367 void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID) {
368  Profile(ID, getAnalysisDeclContext(), getParent(), CallSite, Block, Index);
369 }
370 
371 void ScopeContext::Profile(llvm::FoldingSetNodeID &ID) {
372  Profile(ID, getAnalysisDeclContext(), getParent(), Enter);
373 }
374 
375 void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) {
376  Profile(ID, getAnalysisDeclContext(), getParent(), BD, ContextData);
377 }
378 
379 //===----------------------------------------------------------------------===//
380 // LocationContext creation.
381 //===----------------------------------------------------------------------===//
382 
383 template <typename LOC, typename DATA>
384 const LOC*
385 LocationContextManager::getLocationContext(AnalysisDeclContext *ctx,
386  const LocationContext *parent,
387  const DATA *d) {
388  llvm::FoldingSetNodeID ID;
389  LOC::Profile(ID, ctx, parent, d);
390  void *InsertPos;
391 
392  LOC *L = cast_or_null<LOC>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
393 
394  if (!L) {
395  L = new LOC(ctx, parent, d);
396  Contexts.InsertNode(L, InsertPos);
397  }
398  return L;
399 }
400 
401 const StackFrameContext*
403  const LocationContext *parent,
404  const Stmt *s,
405  const CFGBlock *blk, unsigned idx) {
406  llvm::FoldingSetNodeID ID;
407  StackFrameContext::Profile(ID, ctx, parent, s, blk, idx);
408  void *InsertPos;
409  auto *L =
410  cast_or_null<StackFrameContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
411  if (!L) {
412  L = new StackFrameContext(ctx, parent, s, blk, idx);
413  Contexts.InsertNode(L, InsertPos);
414  }
415  return L;
416 }
417 
418 const ScopeContext *
420  const LocationContext *parent,
421  const Stmt *s) {
422  return getLocationContext<ScopeContext, Stmt>(ctx, parent, s);
423 }
424 
427  const LocationContext *parent,
428  const BlockDecl *BD,
429  const void *ContextData) {
430  llvm::FoldingSetNodeID ID;
431  BlockInvocationContext::Profile(ID, ctx, parent, BD, ContextData);
432  void *InsertPos;
433  auto *L =
434  cast_or_null<BlockInvocationContext>(Contexts.FindNodeOrInsertPos(ID,
435  InsertPos));
436  if (!L) {
437  L = new BlockInvocationContext(ctx, parent, BD, ContextData);
438  Contexts.InsertNode(L, InsertPos);
439  }
440  return L;
441 }
442 
443 //===----------------------------------------------------------------------===//
444 // LocationContext methods.
445 //===----------------------------------------------------------------------===//
446 
448  const LocationContext *LC = this;
449  while (LC) {
450  if (const auto *SFC = dyn_cast<StackFrameContext>(LC))
451  return SFC;
452  LC = LC->getParent();
453  }
454  return nullptr;
455 }
456 
458  return getStackFrame()->inTopFrame();
459 }
460 
462  do {
463  const LocationContext *Parent = LC->getParent();
464  if (Parent == this)
465  return true;
466  else
467  LC = Parent;
468  } while (LC);
469 
470  return false;
471 }
472 
473 static void printLocation(raw_ostream &OS, const SourceManager &SM,
474  SourceLocation SLoc) {
475  if (SLoc.isFileID() && SM.isInMainFile(SLoc))
476  OS << "line " << SM.getExpansionLineNumber(SLoc);
477  else
478  SLoc.print(OS, SM);
479 }
480 
482  raw_ostream &OS, StringRef Indent, const char *NL, const char *Sep,
483  std::function<void(const LocationContext *)> printMoreInfoPerContext) const {
484  ASTContext &Ctx = getAnalysisDeclContext()->getASTContext();
485  PrintingPolicy PP(Ctx.getLangOpts());
486  PP.TerseOutput = 1;
487 
488  const SourceManager &SM =
489  getAnalysisDeclContext()->getASTContext().getSourceManager();
490 
491  unsigned Frame = 0;
492  for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
493  switch (LCtx->getKind()) {
494  case StackFrame:
495  OS << Indent << '#' << Frame << ' ';
496  ++Frame;
497  if (const auto *D = dyn_cast<NamedDecl>(LCtx->getDecl()))
498  OS << "Calling " << D->getQualifiedNameAsString();
499  else
500  OS << "Calling anonymous code";
501  if (const Stmt *S = cast<StackFrameContext>(LCtx)->getCallSite()) {
502  OS << " at ";
503  printLocation(OS, SM, S->getLocStart());
504  }
505  break;
506  case Scope:
507  OS << "Entering scope";
508  break;
509  case Block:
510  OS << "Invoking block";
511  if (const Decl *D = cast<BlockInvocationContext>(LCtx)->getDecl()) {
512  OS << " defined at ";
513  printLocation(OS, SM, D->getLocStart());
514  }
515  break;
516  }
517  OS << NL;
518 
519  printMoreInfoPerContext(LCtx);
520  }
521 }
522 
523 LLVM_DUMP_METHOD void LocationContext::dumpStack() const {
524  dumpStack(llvm::errs());
525 }
526 
527 //===----------------------------------------------------------------------===//
528 // Lazily generated map to query the external variables referenced by a Block.
529 //===----------------------------------------------------------------------===//
530 
531 namespace {
532 
533 class FindBlockDeclRefExprsVals : public StmtVisitor<FindBlockDeclRefExprsVals>{
535  BumpVectorContext &BC;
536  llvm::SmallPtrSet<const VarDecl *, 4> Visited;
537  llvm::SmallPtrSet<const DeclContext *, 4> IgnoredContexts;
538 
539 public:
540  FindBlockDeclRefExprsVals(BumpVector<const VarDecl*> &bevals,
541  BumpVectorContext &bc)
542  : BEVals(bevals), BC(bc) {}
543 
544  void VisitStmt(Stmt *S) {
545  for (auto *Child : S->children())
546  if (Child)
547  Visit(Child);
548  }
549 
550  void VisitDeclRefExpr(DeclRefExpr *DR) {
551  // Non-local variables are also directly modified.
552  if (const auto *VD = dyn_cast<VarDecl>(DR->getDecl())) {
553  if (!VD->hasLocalStorage()) {
554  if (Visited.insert(VD).second)
555  BEVals.push_back(VD, BC);
556  }
557  }
558  }
559 
560  void VisitBlockExpr(BlockExpr *BR) {
561  // Blocks containing blocks can transitively capture more variables.
562  IgnoredContexts.insert(BR->getBlockDecl());
563  Visit(BR->getBlockDecl()->getBody());
564  }
565 
566  void VisitPseudoObjectExpr(PseudoObjectExpr *PE) {
568  et = PE->semantics_end(); it != et; ++it) {
569  Expr *Semantic = *it;
570  if (auto *OVE = dyn_cast<OpaqueValueExpr>(Semantic))
571  Semantic = OVE->getSourceExpr();
572  Visit(Semantic);
573  }
574  }
575 };
576 
577 } // namespace
578 
580 
582  void *&Vec,
583  llvm::BumpPtrAllocator &A) {
584  if (Vec)
585  return (DeclVec*) Vec;
586 
587  BumpVectorContext BC(A);
588  DeclVec *BV = (DeclVec*) A.Allocate<DeclVec>();
589  new (BV) DeclVec(BC, 10);
590 
591  // Go through the capture list.
592  for (const auto &CI : BD->captures()) {
593  BV->push_back(CI.getVariable(), BC);
594  }
595 
596  // Find the referenced global/static variables.
597  FindBlockDeclRefExprsVals F(*BV, BC);
598  F.Visit(BD->getBody());
599 
600  Vec = BV;
601  return BV;
602 }
603 
604 llvm::iterator_range<AnalysisDeclContext::referenced_decls_iterator>
606  if (!ReferencedBlockVars)
607  ReferencedBlockVars = new llvm::DenseMap<const BlockDecl*,void*>();
608 
609  const DeclVec *V =
610  LazyInitializeReferencedDecls(BD, (*ReferencedBlockVars)[BD], A);
611  return llvm::make_range(V->begin(), V->end());
612 }
613 
614 ManagedAnalysis *&AnalysisDeclContext::getAnalysisImpl(const void *tag) {
615  if (!ManagedAnalyses)
616  ManagedAnalyses = new ManagedAnalysisMap();
617  ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses;
618  return (*M)[tag];
619 }
620 
621 //===----------------------------------------------------------------------===//
622 // Cleanup.
623 //===----------------------------------------------------------------------===//
624 
626 
628  delete forcedBlkExprs;
629  delete ReferencedBlockVars;
630  // Release the managed analyses.
631  if (ManagedAnalyses) {
632  ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses;
633  llvm::DeleteContainerSeconds(*M);
634  delete M;
635  }
636 }
637 
639 
641  clear();
642 }
643 
645  for (llvm::FoldingSet<LocationContext>::iterator I = Contexts.begin(),
646  E = Contexts.end(); I != E; ) {
647  LocationContext *LC = &*I;
648  ++I;
649  delete LC;
650  }
651  Contexts.clear();
652 }
Defines the clang::ASTContext interface.
const BlockDecl * getBlockDecl() const
Definition: Expr.h:4949
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:5119
Stmt - This represents one statement.
Definition: Stmt.h:66
Defines the SourceManager interface.
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, bool markElidedCXXConstructors=true, CodeInjector *injector=nullptr)
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:1250
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
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:3931
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:1683
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()
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:5127
const LocationContext * getParent() const
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:1202
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:1127
llvm::DenseMap< const Stmt *, const CFGBlock * > ForcedBlkExprs
Definition: CFG.h:1012
NodeId Parent
Definition: ASTDiff.cpp:192
const StackFrameContext * getStackFrame(AnalysisDeclContext *Ctx, LocationContext const *Parent, const Stmt *S, const CFGBlock *Blk, unsigned Idx)
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:3849
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:4935
DeclContext * getDeclContext()
Definition: DeclBase.h:426
bool inTopFrame() const override
Return true if the current LocationContext has no caller context.
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:1474
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:5053
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:4585
bool PruneTriviallyFalseEdges
Definition: CFG.h:1016
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2043
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.
bool MarkElidedCXXConstructors
Definition: CFG.h:1028
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:3979
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:5121
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 StackFrameContext * getStackFrame() const
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:1140
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:1135
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:690
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.