clang  9.0.0svn
AnalysisDeclContext.cpp
Go to the documentation of this file.
1 //===- AnalysisDeclContext.cpp - Analysis context for Path Sens analysis --===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines AnalysisDeclContext, a class that manages the analysis
10 // context data for path sensitive analysis.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclBase.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/Expr.h"
23 #include "clang/AST/ParentMap.h"
25 #include "clang/AST/Stmt.h"
26 #include "clang/AST/StmtCXX.h"
27 #include "clang/AST/StmtVisitor.h"
30 #include "clang/Analysis/CFG.h"
33 #include "clang/Basic/LLVM.h"
36 #include "llvm/ADT/DenseMap.h"
37 #include "llvm/ADT/FoldingSet.h"
38 #include "llvm/ADT/STLExtras.h"
39 #include "llvm/ADT/SmallPtrSet.h"
40 #include "llvm/ADT/iterator_range.h"
41 #include "llvm/Support/Allocator.h"
42 #include "llvm/Support/Casting.h"
43 #include "llvm/Support/Compiler.h"
44 #include "llvm/Support/ErrorHandling.h"
45 #include "llvm/Support/SaveAndRestore.h"
46 #include "llvm/Support/raw_ostream.h"
47 #include <cassert>
48 #include <memory>
49 
50 using namespace clang;
51 
52 using ManagedAnalysisMap = llvm::DenseMap<const void *, ManagedAnalysis *>;
53 
55  const Decl *d,
56  const CFG::BuildOptions &buildOptions)
57  : Manager(Mgr), D(d), cfgBuildOptions(buildOptions) {
58  cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
59 }
60 
62  const Decl *d)
63  : Manager(Mgr), D(d) {
64  cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
65 }
66 
68  ASTContext &ASTCtx, bool useUnoptimizedCFG, bool addImplicitDtors,
69  bool addInitializers, bool addTemporaryDtors, bool addLifetime,
70  bool addLoopExit, bool addScopes, bool synthesizeBodies,
71  bool addStaticInitBranch, bool addCXXNewAllocator,
72  bool addRichCXXConstructors, bool markElidedCXXConstructors,
73  CodeInjector *injector)
74  : Injector(injector), FunctionBodyFarm(ASTCtx, injector),
75  SynthesizeBodies(synthesizeBodies) {
76  cfgBuildOptions.PruneTriviallyFalseEdges = !useUnoptimizedCFG;
77  cfgBuildOptions.AddImplicitDtors = addImplicitDtors;
78  cfgBuildOptions.AddInitializers = addInitializers;
79  cfgBuildOptions.AddTemporaryDtors = addTemporaryDtors;
80  cfgBuildOptions.AddLifetime = addLifetime;
81  cfgBuildOptions.AddLoopExit = addLoopExit;
82  cfgBuildOptions.AddScopes = addScopes;
83  cfgBuildOptions.AddStaticInitBranches = addStaticInitBranch;
84  cfgBuildOptions.AddCXXNewAllocator = addCXXNewAllocator;
85  cfgBuildOptions.AddRichCXXConstructors = addRichCXXConstructors;
86  cfgBuildOptions.MarkElidedCXXConstructors = markElidedCXXConstructors;
87 }
88 
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->getBeginLoc().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 (const auto *FD = dyn_cast<FunctionDecl>(D)) {
295  // Calling 'hasBody' replaces 'FD' in place with the FunctionDecl
296  // that has the body.
297  FD->hasBody(FD);
298  D = FD;
299  }
300 
301  std::unique_ptr<AnalysisDeclContext> &AC = Contexts[D];
302  if (!AC)
303  AC = llvm::make_unique<AnalysisDeclContext>(this, D, cfgBuildOptions);
304  return AC.get();
305 }
306 
307 BodyFarm &AnalysisDeclContextManager::getBodyFarm() { return FunctionBodyFarm; }
308 
309 const StackFrameContext *
311  const CFGBlock *Blk, unsigned Idx) {
312  return getLocationContextManager().getStackFrame(this, Parent, S, Blk, Idx);
313 }
314 
317  const BlockDecl *BD,
318  const void *ContextData) {
319  return getLocationContextManager().getBlockInvocationContext(this, parent,
320  BD, ContextData);
321 }
322 
325  const auto *ND = dyn_cast<NamespaceDecl>(DC);
326  if (!ND)
327  return false;
328 
329  while (const DeclContext *Parent = ND->getParent()) {
330  if (!isa<NamespaceDecl>(Parent))
331  break;
332  ND = cast<NamespaceDecl>(Parent);
333  }
334 
335  return ND->isStdNamespace();
336 }
337 
338 LocationContextManager &AnalysisDeclContext::getLocationContextManager() {
339  assert(Manager &&
340  "Cannot create LocationContexts without an AnalysisDeclContextManager!");
341  return Manager->getLocationContextManager();
342 }
343 
344 //===----------------------------------------------------------------------===//
345 // FoldingSet profiling.
346 //===----------------------------------------------------------------------===//
347 
348 void LocationContext::ProfileCommon(llvm::FoldingSetNodeID &ID,
349  ContextKind ck,
350  AnalysisDeclContext *ctx,
351  const LocationContext *parent,
352  const void *data) {
353  ID.AddInteger(ck);
354  ID.AddPointer(ctx);
355  ID.AddPointer(parent);
356  ID.AddPointer(data);
357 }
358 
359 void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID) {
360  Profile(ID, getAnalysisDeclContext(), getParent(), CallSite, Block, Index);
361 }
362 
363 void ScopeContext::Profile(llvm::FoldingSetNodeID &ID) {
364  Profile(ID, getAnalysisDeclContext(), getParent(), Enter);
365 }
366 
367 void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) {
368  Profile(ID, getAnalysisDeclContext(), getParent(), BD, ContextData);
369 }
370 
371 //===----------------------------------------------------------------------===//
372 // LocationContext creation.
373 //===----------------------------------------------------------------------===//
374 
375 template <typename LOC, typename DATA>
376 const LOC*
377 LocationContextManager::getLocationContext(AnalysisDeclContext *ctx,
378  const LocationContext *parent,
379  const DATA *d) {
380  llvm::FoldingSetNodeID ID;
381  LOC::Profile(ID, ctx, parent, d);
382  void *InsertPos;
383 
384  LOC *L = cast_or_null<LOC>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
385 
386  if (!L) {
387  L = new LOC(ctx, parent, d, ++NewID);
388  Contexts.InsertNode(L, InsertPos);
389  }
390  return L;
391 }
392 
393 const StackFrameContext*
395  const LocationContext *parent,
396  const Stmt *s,
397  const CFGBlock *blk, unsigned idx) {
398  llvm::FoldingSetNodeID ID;
399  StackFrameContext::Profile(ID, ctx, parent, s, blk, idx);
400  void *InsertPos;
401  auto *L =
402  cast_or_null<StackFrameContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
403  if (!L) {
404  L = new StackFrameContext(ctx, parent, s, blk, idx, ++NewID);
405  Contexts.InsertNode(L, InsertPos);
406  }
407  return L;
408 }
409 
410 const ScopeContext *
412  const LocationContext *parent,
413  const Stmt *s) {
414  return getLocationContext<ScopeContext, Stmt>(ctx, parent, s);
415 }
416 
419  const LocationContext *parent,
420  const BlockDecl *BD,
421  const void *ContextData) {
422  llvm::FoldingSetNodeID ID;
423  BlockInvocationContext::Profile(ID, ctx, parent, BD, ContextData);
424  void *InsertPos;
425  auto *L =
426  cast_or_null<BlockInvocationContext>(Contexts.FindNodeOrInsertPos(ID,
427  InsertPos));
428  if (!L) {
429  L = new BlockInvocationContext(ctx, parent, BD, ContextData, ++NewID);
430  Contexts.InsertNode(L, InsertPos);
431  }
432  return L;
433 }
434 
435 //===----------------------------------------------------------------------===//
436 // LocationContext methods.
437 //===----------------------------------------------------------------------===//
438 
440  const LocationContext *LC = this;
441  while (LC) {
442  if (const auto *SFC = dyn_cast<StackFrameContext>(LC))
443  return SFC;
444  LC = LC->getParent();
445  }
446  return nullptr;
447 }
448 
450  return getStackFrame()->inTopFrame();
451 }
452 
454  do {
455  const LocationContext *Parent = LC->getParent();
456  if (Parent == this)
457  return true;
458  else
459  LC = Parent;
460  } while (LC);
461 
462  return false;
463 }
464 
465 static void printLocation(raw_ostream &OS, const SourceManager &SM,
466  SourceLocation SLoc) {
467  if (SLoc.isFileID() && SM.isInMainFile(SLoc))
468  OS << "line " << SM.getExpansionLineNumber(SLoc);
469  else
470  SLoc.print(OS, SM);
471 }
472 
474  raw_ostream &OS, StringRef Indent, const char *NL, const char *Sep,
475  std::function<void(const LocationContext *)> printMoreInfoPerContext) const {
476  ASTContext &Ctx = getAnalysisDeclContext()->getASTContext();
477  PrintingPolicy PP(Ctx.getLangOpts());
478  PP.TerseOutput = 1;
479 
480  const SourceManager &SM =
481  getAnalysisDeclContext()->getASTContext().getSourceManager();
482 
483  unsigned Frame = 0;
484  for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
485  switch (LCtx->getKind()) {
486  case StackFrame:
487  OS << Indent << '#' << Frame << ' ';
488  ++Frame;
489  if (const auto *D = dyn_cast<NamedDecl>(LCtx->getDecl()))
490  OS << "Calling " << D->getQualifiedNameAsString();
491  else
492  OS << "Calling anonymous code";
493  if (const Stmt *S = cast<StackFrameContext>(LCtx)->getCallSite()) {
494  OS << " at ";
495  printLocation(OS, SM, S->getBeginLoc());
496  }
497  break;
498  case Scope:
499  OS << "Entering scope";
500  break;
501  case Block:
502  OS << "Invoking block";
503  if (const Decl *D = cast<BlockInvocationContext>(LCtx)->getDecl()) {
504  OS << " defined at ";
505  printLocation(OS, SM, D->getBeginLoc());
506  }
507  break;
508  }
509  OS << NL;
510 
511  printMoreInfoPerContext(LCtx);
512  }
513 }
514 
515 LLVM_DUMP_METHOD void LocationContext::dumpStack() const {
516  dumpStack(llvm::errs());
517 }
518 
519 //===----------------------------------------------------------------------===//
520 // Lazily generated map to query the external variables referenced by a Block.
521 //===----------------------------------------------------------------------===//
522 
523 namespace {
524 
525 class FindBlockDeclRefExprsVals : public StmtVisitor<FindBlockDeclRefExprsVals>{
527  BumpVectorContext &BC;
528  llvm::SmallPtrSet<const VarDecl *, 4> Visited;
529  llvm::SmallPtrSet<const DeclContext *, 4> IgnoredContexts;
530 
531 public:
532  FindBlockDeclRefExprsVals(BumpVector<const VarDecl*> &bevals,
533  BumpVectorContext &bc)
534  : BEVals(bevals), BC(bc) {}
535 
536  void VisitStmt(Stmt *S) {
537  for (auto *Child : S->children())
538  if (Child)
539  Visit(Child);
540  }
541 
542  void VisitDeclRefExpr(DeclRefExpr *DR) {
543  // Non-local variables are also directly modified.
544  if (const auto *VD = dyn_cast<VarDecl>(DR->getDecl())) {
545  if (!VD->hasLocalStorage()) {
546  if (Visited.insert(VD).second)
547  BEVals.push_back(VD, BC);
548  }
549  }
550  }
551 
552  void VisitBlockExpr(BlockExpr *BR) {
553  // Blocks containing blocks can transitively capture more variables.
554  IgnoredContexts.insert(BR->getBlockDecl());
555  Visit(BR->getBlockDecl()->getBody());
556  }
557 
558  void VisitPseudoObjectExpr(PseudoObjectExpr *PE) {
560  et = PE->semantics_end(); it != et; ++it) {
561  Expr *Semantic = *it;
562  if (auto *OVE = dyn_cast<OpaqueValueExpr>(Semantic))
563  Semantic = OVE->getSourceExpr();
564  Visit(Semantic);
565  }
566  }
567 };
568 
569 } // namespace
570 
572 
574  void *&Vec,
575  llvm::BumpPtrAllocator &A) {
576  if (Vec)
577  return (DeclVec*) Vec;
578 
579  BumpVectorContext BC(A);
580  DeclVec *BV = (DeclVec*) A.Allocate<DeclVec>();
581  new (BV) DeclVec(BC, 10);
582 
583  // Go through the capture list.
584  for (const auto &CI : BD->captures()) {
585  BV->push_back(CI.getVariable(), BC);
586  }
587 
588  // Find the referenced global/static variables.
589  FindBlockDeclRefExprsVals F(*BV, BC);
590  F.Visit(BD->getBody());
591 
592  Vec = BV;
593  return BV;
594 }
595 
596 llvm::iterator_range<AnalysisDeclContext::referenced_decls_iterator>
598  if (!ReferencedBlockVars)
599  ReferencedBlockVars = new llvm::DenseMap<const BlockDecl*,void*>();
600 
601  const DeclVec *V =
602  LazyInitializeReferencedDecls(BD, (*ReferencedBlockVars)[BD], A);
603  return llvm::make_range(V->begin(), V->end());
604 }
605 
606 ManagedAnalysis *&AnalysisDeclContext::getAnalysisImpl(const void *tag) {
607  if (!ManagedAnalyses)
608  ManagedAnalyses = new ManagedAnalysisMap();
609  ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses;
610  return (*M)[tag];
611 }
612 
613 //===----------------------------------------------------------------------===//
614 // Cleanup.
615 //===----------------------------------------------------------------------===//
616 
618 
620  delete forcedBlkExprs;
621  delete ReferencedBlockVars;
622  // Release the managed analyses.
623  if (ManagedAnalyses) {
624  ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses;
625  llvm::DeleteContainerSeconds(*M);
626  delete M;
627  }
628 }
629 
631 
633  clear();
634 }
635 
637  for (llvm::FoldingSet<LocationContext>::iterator I = Contexts.begin(),
638  E = Contexts.end(); I != E; ) {
639  LocationContext *LC = &*I;
640  ++I;
641  delete LC;
642  }
643  Contexts.clear();
644 }
Defines the clang::ASTContext interface.
const BlockDecl * getBlockDecl() const
Definition: Expr.h:5475
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:5649
Stmt - This represents one statement.
Definition: Stmt.h:65
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:88
Defines the C++ template declaration subclasses.
Stmt * getParent(Stmt *) const
Definition: ParentMap.cpp:122
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:37
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:154
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:263
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:3942
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:1751
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:212
virtual bool inTopFrame() const
Return true if the current LocationContext has no caller context.
semantics_iterator semantics_end()
Definition: Expr.h:5657
const LocationContext * getParent() const
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:1195
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:191
const StackFrameContext * getStackFrame(AnalysisDeclContext *Ctx, LocationContext const *Parent, const Stmt *S, const CFGBlock *Blk, unsigned Idx)
ForcedBlkExprs ** forcedBlkExprs
Definition: CFG.h:1014
Represents a single basic block in a source-level CFG.
Definition: CFG.h:551
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.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:3863
This represents one expression.
Definition: Expr.h:108
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
#define V(N, I)
Definition: ASTContext.h:2905
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:5461
DeclContext * getDeclContext()
Definition: DeclBase.h:431
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:1763
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:1147
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:1568
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:5583
Encodes a location in the source.
static std::unique_ptr< CFG > buildCFG(const Decl *D, Stmt *AST, ASTContext *C, const BuildOptions &BO)
Builds a CFG from an AST.
Definition: CFG.cpp:4674
bool PruneTriviallyFalseEdges
Definition: CFG.h:1016
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2108
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:182
bool isStdNamespace() const
Definition: DeclBase.cpp:1062
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:159
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:77
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1264
ArrayRef< Capture > captures() const
Definition: Decl.h:3990
CodeInjector is an interface which is responsible for injecting AST of function definitions that may ...
Definition: CodeInjector.h:35
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:5651
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...
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:299
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:1074
const BlockInvocationContext * getBlockInvocationContext(const LocationContext *parent, const BlockDecl *BD, const void *ContextData)
void clear()
Discard all previously created AnalysisDeclContexts.
const LangOptions & getLangOpts() const
Definition: ASTContext.h:707
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.