clang  6.0.0svn
CheckerManager.cpp
Go to the documentation of this file.
1 //===--- CheckerManager.cpp - Static Analyzer Checker Manager -------------===//
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 // Defines the Static Analyzer Checker Manager.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "clang/AST/DeclBase.h"
20 
21 using namespace clang;
22 using namespace ento;
23 
25  return !StmtCheckers.empty() ||
26  !PreObjCMessageCheckers.empty() ||
27  !PostObjCMessageCheckers.empty() ||
28  !PreCallCheckers.empty() ||
29  !PostCallCheckers.empty() ||
30  !LocationCheckers.empty() ||
31  !BindCheckers.empty() ||
32  !EndAnalysisCheckers.empty() ||
33  !EndFunctionCheckers.empty() ||
34  !BranchConditionCheckers.empty() ||
35  !LiveSymbolsCheckers.empty() ||
36  !DeadSymbolsCheckers.empty() ||
37  !RegionChangesCheckers.empty() ||
38  !EvalAssumeCheckers.empty() ||
39  !EvalCallCheckers.empty();
40 }
41 
43 #ifndef NDEBUG
44  // Make sure that for every event that has listeners, there is at least
45  // one dispatcher registered for it.
46  for (llvm::DenseMap<EventTag, EventInfo>::iterator
47  I = Events.begin(), E = Events.end(); I != E; ++I)
48  assert(I->second.HasDispatcher && "No dispatcher registered for an event");
49 #endif
50 }
51 
52 //===----------------------------------------------------------------------===//
53 // Functions for running checkers for AST traversing..
54 //===----------------------------------------------------------------------===//
55 
57  BugReporter &BR) {
58  assert(D);
59 
60  unsigned DeclKind = D->getKind();
61  CachedDeclCheckers *checkers = nullptr;
62  CachedDeclCheckersMapTy::iterator CCI = CachedDeclCheckersMap.find(DeclKind);
63  if (CCI != CachedDeclCheckersMap.end()) {
64  checkers = &(CCI->second);
65  } else {
66  // Find the checkers that should run for this Decl and cache them.
67  checkers = &CachedDeclCheckersMap[DeclKind];
68  for (unsigned i = 0, e = DeclCheckers.size(); i != e; ++i) {
69  DeclCheckerInfo &info = DeclCheckers[i];
70  if (info.IsForDeclFn(D))
71  checkers->push_back(info.CheckFn);
72  }
73  }
74 
75  assert(checkers);
76  for (CachedDeclCheckers::iterator
77  I = checkers->begin(), E = checkers->end(); I != E; ++I)
78  (*I)(D, mgr, BR);
79 }
80 
82  BugReporter &BR) {
83  assert(D && D->hasBody());
84 
85  for (unsigned i = 0, e = BodyCheckers.size(); i != e; ++i)
86  BodyCheckers[i](D, mgr, BR);
87 }
88 
89 //===----------------------------------------------------------------------===//
90 // Functions for running checkers for path-sensitive checking.
91 //===----------------------------------------------------------------------===//
92 
93 template <typename CHECK_CTX>
94 static void expandGraphWithCheckers(CHECK_CTX checkCtx,
95  ExplodedNodeSet &Dst,
96  const ExplodedNodeSet &Src) {
97  const NodeBuilderContext &BldrCtx = checkCtx.Eng.getBuilderContext();
98  if (Src.empty())
99  return;
100 
101  typename CHECK_CTX::CheckersTy::const_iterator
102  I = checkCtx.checkers_begin(), E = checkCtx.checkers_end();
103  if (I == E) {
104  Dst.insert(Src);
105  return;
106  }
107 
108  ExplodedNodeSet Tmp1, Tmp2;
109  const ExplodedNodeSet *PrevSet = &Src;
110 
111  for (; I != E; ++I) {
112  ExplodedNodeSet *CurrSet = nullptr;
113  if (I+1 == E)
114  CurrSet = &Dst;
115  else {
116  CurrSet = (PrevSet == &Tmp1) ? &Tmp2 : &Tmp1;
117  CurrSet->clear();
118  }
119 
120  NodeBuilder B(*PrevSet, *CurrSet, BldrCtx);
121  for (ExplodedNodeSet::iterator NI = PrevSet->begin(), NE = PrevSet->end();
122  NI != NE; ++NI) {
123  checkCtx.runChecker(*I, B, *NI);
124  }
125 
126  // If all the produced transitions are sinks, stop.
127  if (CurrSet->empty())
128  return;
129 
130  // Update which NodeSet is the current one.
131  PrevSet = CurrSet;
132  }
133 }
134 
135 namespace {
136  struct CheckStmtContext {
138  bool IsPreVisit;
139  const CheckersTy &Checkers;
140  const Stmt *S;
141  ExprEngine &Eng;
142  bool WasInlined;
143 
144  CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
145  CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
146 
147  CheckStmtContext(bool isPreVisit, const CheckersTy &checkers,
148  const Stmt *s, ExprEngine &eng, bool wasInlined = false)
149  : IsPreVisit(isPreVisit), Checkers(checkers), S(s), Eng(eng),
150  WasInlined(wasInlined) {}
151 
152  void runChecker(CheckerManager::CheckStmtFunc checkFn,
153  NodeBuilder &Bldr, ExplodedNode *Pred) {
154  // FIXME: Remove respondsToCallback from CheckerContext;
158  Pred->getLocationContext(), checkFn.Checker);
159  CheckerContext C(Bldr, Eng, Pred, L, WasInlined);
160  checkFn(S, C);
161  }
162  };
163 }
164 
165 /// \brief Run checkers for visiting Stmts.
167  ExplodedNodeSet &Dst,
168  const ExplodedNodeSet &Src,
169  const Stmt *S,
170  ExprEngine &Eng,
171  bool WasInlined) {
172  CheckStmtContext C(isPreVisit, getCachedStmtCheckersFor(S, isPreVisit),
173  S, Eng, WasInlined);
174  expandGraphWithCheckers(C, Dst, Src);
175 }
176 
177 namespace {
178  struct CheckObjCMessageContext {
179  typedef std::vector<CheckerManager::CheckObjCMessageFunc> CheckersTy;
180 
182  bool WasInlined;
183  const CheckersTy &Checkers;
184  const ObjCMethodCall &Msg;
185  ExprEngine &Eng;
186 
187  CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
188  CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
189 
190  CheckObjCMessageContext(ObjCMessageVisitKind visitKind,
191  const CheckersTy &checkers,
192  const ObjCMethodCall &msg, ExprEngine &eng,
193  bool wasInlined)
194  : Kind(visitKind), WasInlined(wasInlined), Checkers(checkers),
195  Msg(msg), Eng(eng) { }
196 
197  void runChecker(CheckerManager::CheckObjCMessageFunc checkFn,
198  NodeBuilder &Bldr, ExplodedNode *Pred) {
199 
200  bool IsPreVisit;
201 
202  switch (Kind) {
204  IsPreVisit = true;
205  break;
208  IsPreVisit = false;
209  break;
210  }
211 
212  const ProgramPoint &L = Msg.getProgramPoint(IsPreVisit,checkFn.Checker);
213  CheckerContext C(Bldr, Eng, Pred, L, WasInlined);
214 
215  checkFn(*Msg.cloneWithState<ObjCMethodCall>(Pred->getState()), C);
216  }
217  };
218 }
219 
220 /// \brief Run checkers for visiting obj-c messages.
222  ExplodedNodeSet &Dst,
223  const ExplodedNodeSet &Src,
224  const ObjCMethodCall &msg,
225  ExprEngine &Eng,
226  bool WasInlined) {
227  auto &checkers = getObjCMessageCheckers(visitKind);
228  CheckObjCMessageContext C(visitKind, checkers, msg, Eng, WasInlined);
229  expandGraphWithCheckers(C, Dst, Src);
230 }
231 
232 const std::vector<CheckerManager::CheckObjCMessageFunc> &
233 CheckerManager::getObjCMessageCheckers(ObjCMessageVisitKind Kind) {
234  switch (Kind) {
236  return PreObjCMessageCheckers;
237  break;
239  return PostObjCMessageCheckers;
241  return ObjCMessageNilCheckers;
242  }
243  llvm_unreachable("Unknown Kind");
244 }
245 namespace {
246  // FIXME: This has all the same signatures as CheckObjCMessageContext.
247  // Is there a way we can merge the two?
248  struct CheckCallContext {
249  typedef std::vector<CheckerManager::CheckCallFunc> CheckersTy;
250  bool IsPreVisit, WasInlined;
251  const CheckersTy &Checkers;
252  const CallEvent &Call;
253  ExprEngine &Eng;
254 
255  CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
256  CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
257 
258  CheckCallContext(bool isPreVisit, const CheckersTy &checkers,
259  const CallEvent &call, ExprEngine &eng,
260  bool wasInlined)
261  : IsPreVisit(isPreVisit), WasInlined(wasInlined), Checkers(checkers),
262  Call(call), Eng(eng) { }
263 
264  void runChecker(CheckerManager::CheckCallFunc checkFn,
265  NodeBuilder &Bldr, ExplodedNode *Pred) {
266  const ProgramPoint &L = Call.getProgramPoint(IsPreVisit,checkFn.Checker);
267  CheckerContext C(Bldr, Eng, Pred, L, WasInlined);
268 
269  checkFn(*Call.cloneWithState(Pred->getState()), C);
270  }
271  };
272 }
273 
274 /// \brief Run checkers for visiting an abstract call event.
276  ExplodedNodeSet &Dst,
277  const ExplodedNodeSet &Src,
278  const CallEvent &Call,
279  ExprEngine &Eng,
280  bool WasInlined) {
281  CheckCallContext C(isPreVisit,
282  isPreVisit ? PreCallCheckers
283  : PostCallCheckers,
284  Call, Eng, WasInlined);
285  expandGraphWithCheckers(C, Dst, Src);
286 }
287 
288 namespace {
289  struct CheckLocationContext {
290  typedef std::vector<CheckerManager::CheckLocationFunc> CheckersTy;
291  const CheckersTy &Checkers;
292  SVal Loc;
293  bool IsLoad;
294  const Stmt *NodeEx; /* Will become a CFGStmt */
295  const Stmt *BoundEx;
296  ExprEngine &Eng;
297 
298  CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
299  CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
300 
301  CheckLocationContext(const CheckersTy &checkers,
302  SVal loc, bool isLoad, const Stmt *NodeEx,
303  const Stmt *BoundEx,
304  ExprEngine &eng)
305  : Checkers(checkers), Loc(loc), IsLoad(isLoad), NodeEx(NodeEx),
306  BoundEx(BoundEx), Eng(eng) {}
307 
308  void runChecker(CheckerManager::CheckLocationFunc checkFn,
309  NodeBuilder &Bldr, ExplodedNode *Pred) {
312  const ProgramPoint &L =
314  Pred->getLocationContext(),
315  checkFn.Checker);
316  CheckerContext C(Bldr, Eng, Pred, L);
317  checkFn(Loc, IsLoad, BoundEx, C);
318  }
319  };
320 }
321 
322 /// \brief Run checkers for load/store of a location.
323 
325  const ExplodedNodeSet &Src,
326  SVal location, bool isLoad,
327  const Stmt *NodeEx,
328  const Stmt *BoundEx,
329  ExprEngine &Eng) {
330  CheckLocationContext C(LocationCheckers, location, isLoad, NodeEx,
331  BoundEx, Eng);
332  expandGraphWithCheckers(C, Dst, Src);
333 }
334 
335 namespace {
336  struct CheckBindContext {
337  typedef std::vector<CheckerManager::CheckBindFunc> CheckersTy;
338  const CheckersTy &Checkers;
339  SVal Loc;
340  SVal Val;
341  const Stmt *S;
342  ExprEngine &Eng;
343  const ProgramPoint &PP;
344 
345  CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
346  CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
347 
348  CheckBindContext(const CheckersTy &checkers,
349  SVal loc, SVal val, const Stmt *s, ExprEngine &eng,
350  const ProgramPoint &pp)
351  : Checkers(checkers), Loc(loc), Val(val), S(s), Eng(eng), PP(pp) {}
352 
353  void runChecker(CheckerManager::CheckBindFunc checkFn,
354  NodeBuilder &Bldr, ExplodedNode *Pred) {
355  const ProgramPoint &L = PP.withTag(checkFn.Checker);
356  CheckerContext C(Bldr, Eng, Pred, L);
357 
358  checkFn(Loc, Val, S, C);
359  }
360  };
361 }
362 
363 /// \brief Run checkers for binding of a value to a location.
365  const ExplodedNodeSet &Src,
366  SVal location, SVal val,
367  const Stmt *S, ExprEngine &Eng,
368  const ProgramPoint &PP) {
369  CheckBindContext C(BindCheckers, location, val, S, Eng, PP);
370  expandGraphWithCheckers(C, Dst, Src);
371 }
372 
374  BugReporter &BR,
375  ExprEngine &Eng) {
376  for (unsigned i = 0, e = EndAnalysisCheckers.size(); i != e; ++i)
377  EndAnalysisCheckers[i](G, BR, Eng);
378 }
379 
380 namespace {
381 struct CheckBeginFunctionContext {
382  typedef std::vector<CheckerManager::CheckBeginFunctionFunc> CheckersTy;
383  const CheckersTy &Checkers;
384  ExprEngine &Eng;
385  const ProgramPoint &PP;
386 
387  CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
388  CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
389 
390  CheckBeginFunctionContext(const CheckersTy &Checkers, ExprEngine &Eng,
391  const ProgramPoint &PP)
392  : Checkers(Checkers), Eng(Eng), PP(PP) {}
393 
394  void runChecker(CheckerManager::CheckBeginFunctionFunc checkFn,
395  NodeBuilder &Bldr, ExplodedNode *Pred) {
396  const ProgramPoint &L = PP.withTag(checkFn.Checker);
397  CheckerContext C(Bldr, Eng, Pred, L);
398 
399  checkFn(C);
400  }
401 };
402 }
403 
405  const BlockEdge &L,
406  ExplodedNode *Pred,
407  ExprEngine &Eng) {
408  ExplodedNodeSet Src;
409  Src.insert(Pred);
410  CheckBeginFunctionContext C(BeginFunctionCheckers, Eng, L);
411  expandGraphWithCheckers(C, Dst, Src);
412 }
413 
414 /// \brief Run checkers for end of path.
415 // Note, We do not chain the checker output (like in expandGraphWithCheckers)
416 // for this callback since end of path nodes are expected to be final.
418  ExplodedNodeSet &Dst,
419  ExplodedNode *Pred,
420  ExprEngine &Eng) {
421 
422  // We define the builder outside of the loop bacause if at least one checkers
423  // creates a sucsessor for Pred, we do not need to generate an
424  // autotransition for it.
425  NodeBuilder Bldr(Pred, Dst, BC);
426  for (unsigned i = 0, e = EndFunctionCheckers.size(); i != e; ++i) {
427  CheckEndFunctionFunc checkFn = EndFunctionCheckers[i];
428 
429  const ProgramPoint &L = BlockEntrance(BC.Block,
430  Pred->getLocationContext(),
431  checkFn.Checker);
432  CheckerContext C(Bldr, Eng, Pred, L);
433  checkFn(C);
434  }
435 }
436 
437 namespace {
438  struct CheckBranchConditionContext {
439  typedef std::vector<CheckerManager::CheckBranchConditionFunc> CheckersTy;
440  const CheckersTy &Checkers;
441  const Stmt *Condition;
442  ExprEngine &Eng;
443 
444  CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
445  CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
446 
447  CheckBranchConditionContext(const CheckersTy &checkers,
448  const Stmt *Cond, ExprEngine &eng)
449  : Checkers(checkers), Condition(Cond), Eng(eng) {}
450 
451  void runChecker(CheckerManager::CheckBranchConditionFunc checkFn,
452  NodeBuilder &Bldr, ExplodedNode *Pred) {
453  ProgramPoint L = PostCondition(Condition, Pred->getLocationContext(),
454  checkFn.Checker);
455  CheckerContext C(Bldr, Eng, Pred, L);
456  checkFn(Condition, C);
457  }
458  };
459 }
460 
461 /// \brief Run checkers for branch condition.
463  ExplodedNodeSet &Dst,
464  ExplodedNode *Pred,
465  ExprEngine &Eng) {
466  ExplodedNodeSet Src;
467  Src.insert(Pred);
468  CheckBranchConditionContext C(BranchConditionCheckers, Condition, Eng);
469  expandGraphWithCheckers(C, Dst, Src);
470 }
471 
472 /// \brief Run checkers for live symbols.
474  SymbolReaper &SymReaper) {
475  for (unsigned i = 0, e = LiveSymbolsCheckers.size(); i != e; ++i)
476  LiveSymbolsCheckers[i](state, SymReaper);
477 }
478 
479 namespace {
480  struct CheckDeadSymbolsContext {
481  typedef std::vector<CheckerManager::CheckDeadSymbolsFunc> CheckersTy;
482  const CheckersTy &Checkers;
483  SymbolReaper &SR;
484  const Stmt *S;
485  ExprEngine &Eng;
486  ProgramPoint::Kind ProgarmPointKind;
487 
488  CheckersTy::const_iterator checkers_begin() { return Checkers.begin(); }
489  CheckersTy::const_iterator checkers_end() { return Checkers.end(); }
490 
491  CheckDeadSymbolsContext(const CheckersTy &checkers, SymbolReaper &sr,
492  const Stmt *s, ExprEngine &eng,
494  : Checkers(checkers), SR(sr), S(s), Eng(eng), ProgarmPointKind(K) { }
495 
496  void runChecker(CheckerManager::CheckDeadSymbolsFunc checkFn,
497  NodeBuilder &Bldr, ExplodedNode *Pred) {
498  const ProgramPoint &L = ProgramPoint::getProgramPoint(S, ProgarmPointKind,
499  Pred->getLocationContext(), checkFn.Checker);
500  CheckerContext C(Bldr, Eng, Pred, L);
501 
502  // Note, do not pass the statement to the checkers without letting them
503  // differentiate if we ran remove dead bindings before or after the
504  // statement.
505  checkFn(SR, C);
506  }
507  };
508 }
509 
510 /// \brief Run checkers for dead symbols.
512  const ExplodedNodeSet &Src,
513  SymbolReaper &SymReaper,
514  const Stmt *S,
515  ExprEngine &Eng,
516  ProgramPoint::Kind K) {
517  CheckDeadSymbolsContext C(DeadSymbolsCheckers, SymReaper, S, Eng, K);
518  expandGraphWithCheckers(C, Dst, Src);
519 }
520 
521 /// \brief Run checkers for region changes.
524  const InvalidatedSymbols *invalidated,
525  ArrayRef<const MemRegion *> ExplicitRegions,
527  const LocationContext *LCtx,
528  const CallEvent *Call) {
529  for (unsigned i = 0, e = RegionChangesCheckers.size(); i != e; ++i) {
530  // If any checker declares the state infeasible (or if it starts that way),
531  // bail out.
532  if (!state)
533  return nullptr;
534  state = RegionChangesCheckers[i](state, invalidated,
535  ExplicitRegions, Regions,
536  LCtx, Call);
537  }
538  return state;
539 }
540 
541 /// \brief Run checkers to process symbol escape event.
544  const InvalidatedSymbols &Escaped,
545  const CallEvent *Call,
548  assert((Call != nullptr ||
549  (Kind != PSK_DirectEscapeOnCall &&
550  Kind != PSK_IndirectEscapeOnCall)) &&
551  "Call must not be NULL when escaping on call");
552  for (unsigned i = 0, e = PointerEscapeCheckers.size(); i != e; ++i) {
553  // If any checker declares the state infeasible (or if it starts that
554  // way), bail out.
555  if (!State)
556  return nullptr;
557  State = PointerEscapeCheckers[i](State, Escaped, Call, Kind, ETraits);
558  }
559  return State;
560 }
561 
562 /// \brief Run checkers for handling assumptions on symbolic values.
565  SVal Cond, bool Assumption) {
566  for (unsigned i = 0, e = EvalAssumeCheckers.size(); i != e; ++i) {
567  // If any checker declares the state infeasible (or if it starts that way),
568  // bail out.
569  if (!state)
570  return nullptr;
571  state = EvalAssumeCheckers[i](state, Cond, Assumption);
572  }
573  return state;
574 }
575 
576 /// \brief Run checkers for evaluating a call.
577 /// Only one checker will evaluate the call.
579  const ExplodedNodeSet &Src,
580  const CallEvent &Call,
581  ExprEngine &Eng) {
582  const CallExpr *CE = cast<CallExpr>(Call.getOriginExpr());
584  NI = Src.begin(), NE = Src.end(); NI != NE; ++NI) {
585  ExplodedNode *Pred = *NI;
586  bool anyEvaluated = false;
587 
588  ExplodedNodeSet checkDst;
589  NodeBuilder B(Pred, checkDst, Eng.getBuilderContext());
590 
591  // Check if any of the EvalCall callbacks can evaluate the call.
592  for (std::vector<EvalCallFunc>::iterator
593  EI = EvalCallCheckers.begin(), EE = EvalCallCheckers.end();
594  EI != EE; ++EI) {
597  Pred->getLocationContext(), EI->Checker);
598  bool evaluated = false;
599  { // CheckerContext generates transitions(populates checkDest) on
600  // destruction, so introduce the scope to make sure it gets properly
601  // populated.
602  CheckerContext C(B, Eng, Pred, L);
603  evaluated = (*EI)(CE, C);
604  }
605  assert(!(evaluated && anyEvaluated)
606  && "There are more than one checkers evaluating the call");
607  if (evaluated) {
608  anyEvaluated = true;
609  Dst.insert(checkDst);
610 #ifdef NDEBUG
611  break; // on release don't check that no other checker also evals.
612 #endif
613  }
614  }
615 
616  // If none of the checkers evaluated the call, ask ExprEngine to handle it.
617  if (!anyEvaluated) {
618  NodeBuilder B(Pred, Dst, Eng.getBuilderContext());
619  Eng.defaultEvalCall(B, Pred, Call);
620  }
621  }
622 }
623 
624 /// \brief Run checkers for the entire Translation Unit.
626  const TranslationUnitDecl *TU,
627  AnalysisManager &mgr,
628  BugReporter &BR) {
629  for (unsigned i = 0, e = EndOfTranslationUnitCheckers.size(); i != e; ++i)
630  EndOfTranslationUnitCheckers[i](TU, mgr, BR);
631 }
632 
635  const char *NL, const char *Sep) {
636  for (llvm::DenseMap<CheckerTag, CheckerRef>::iterator
637  I = CheckerTags.begin(), E = CheckerTags.end(); I != E; ++I)
638  I->second->printState(Out, State, NL, Sep);
639 }
640 
641 //===----------------------------------------------------------------------===//
642 // Internal registration functions for AST traversing.
643 //===----------------------------------------------------------------------===//
644 
646  HandlesDeclFunc isForDeclFn) {
647  DeclCheckerInfo info = { checkfn, isForDeclFn };
648  DeclCheckers.push_back(info);
649 }
650 
652  BodyCheckers.push_back(checkfn);
653 }
654 
655 //===----------------------------------------------------------------------===//
656 // Internal registration functions for path-sensitive checking.
657 //===----------------------------------------------------------------------===//
658 
660  HandlesStmtFunc isForStmtFn) {
661  StmtCheckerInfo info = { checkfn, isForStmtFn, /*IsPreVisit*/true };
662  StmtCheckers.push_back(info);
663 }
665  HandlesStmtFunc isForStmtFn) {
666  StmtCheckerInfo info = { checkfn, isForStmtFn, /*IsPreVisit*/false };
667  StmtCheckers.push_back(info);
668 }
669 
671  PreObjCMessageCheckers.push_back(checkfn);
672 }
673 
675  ObjCMessageNilCheckers.push_back(checkfn);
676 }
677 
679  PostObjCMessageCheckers.push_back(checkfn);
680 }
681 
683  PreCallCheckers.push_back(checkfn);
684 }
686  PostCallCheckers.push_back(checkfn);
687 }
688 
690  LocationCheckers.push_back(checkfn);
691 }
692 
694  BindCheckers.push_back(checkfn);
695 }
696 
698  EndAnalysisCheckers.push_back(checkfn);
699 }
700 
702  BeginFunctionCheckers.push_back(checkfn);
703 }
704 
706  EndFunctionCheckers.push_back(checkfn);
707 }
708 
710  CheckBranchConditionFunc checkfn) {
711  BranchConditionCheckers.push_back(checkfn);
712 }
713 
715  LiveSymbolsCheckers.push_back(checkfn);
716 }
717 
719  DeadSymbolsCheckers.push_back(checkfn);
720 }
721 
723  RegionChangesCheckers.push_back(checkfn);
724 }
725 
727  PointerEscapeCheckers.push_back(checkfn);
728 }
729 
731  CheckPointerEscapeFunc checkfn) {
732  PointerEscapeCheckers.push_back(checkfn);
733 }
734 
736  EvalAssumeCheckers.push_back(checkfn);
737 }
738 
740  EvalCallCheckers.push_back(checkfn);
741 }
742 
744  CheckEndOfTranslationUnit checkfn) {
745  EndOfTranslationUnitCheckers.push_back(checkfn);
746 }
747 
748 //===----------------------------------------------------------------------===//
749 // Implementation details.
750 //===----------------------------------------------------------------------===//
751 
753 CheckerManager::getCachedStmtCheckersFor(const Stmt *S, bool isPreVisit) {
754  assert(S);
755 
756  unsigned Key = (S->getStmtClass() << 1) | unsigned(isPreVisit);
757  CachedStmtCheckersMapTy::iterator CCI = CachedStmtCheckersMap.find(Key);
758  if (CCI != CachedStmtCheckersMap.end())
759  return CCI->second;
760 
761  // Find the checkers that should run for this Stmt and cache them.
762  CachedStmtCheckers &Checkers = CachedStmtCheckersMap[Key];
763  for (unsigned i = 0, e = StmtCheckers.size(); i != e; ++i) {
764  StmtCheckerInfo &Info = StmtCheckers[i];
765  if (Info.IsPreVisit == isPreVisit && Info.IsForStmtFn(S))
766  Checkers.push_back(Info.CheckFn);
767  }
768  return Checkers;
769 }
770 
772  for (unsigned i = 0, e = CheckerDtors.size(); i != e; ++i)
773  CheckerDtors[i]();
774 }
CallEventRef< T > cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
void _registerForDeadSymbols(CheckDeadSymbolsFunc checkfn)
Stmt - This represents one statement.
Definition: Stmt.h:66
Information about invalidation for a particular region/symbol.
Definition: MemRegion.h:1383
ProgramPoint getProgramPoint(bool IsPreVisit=false, const ProgramPointTag *Tag=nullptr) const
Returns an appropriate ProgramPoint for this call.
Definition: CallEvent.cpp:196
static void expandGraphWithCheckers(CHECK_CTX checkCtx, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src)
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
void runCheckersForEndFunction(NodeBuilderContext &BC, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers on end of function.
ProgramPoint withTag(const ProgramPointTag *tag) const
Create a new ProgramPoint object that is the same as the original except for using the specified tag ...
Definition: ProgramPoint.h:132
The pointer has been passed to a function indirectly.
const ProgramStateRef & getState() const
void _registerForBeginFunction(CheckEndFunctionFunc checkfn)
const Expr * getOriginExpr() const
Returns the expression whose value will be the result of this call.
Definition: CallEvent.h:225
void _registerForRegionChanges(CheckRegionChangesFunc checkfn)
void _registerForObjCMessageNil(CheckObjCMessageFunc checkfn)
const NodeBuilderContext & getBuilderContext()
Definition: ExprEngine.h:135
bool(* HandlesDeclFunc)(const Decl *D)
void runCheckersForLocation(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, SVal location, bool isLoad, const Stmt *NodeEx, const Stmt *BoundEx, ExprEngine &Eng)
Run checkers for load/store of a location.
static ProgramPoint getProgramPoint(const Stmt *S, ProgramPoint::Kind K, const LocationContext *LC, const ProgramPointTag *tag)
ProgramStateRef runCheckersForPointerEscape(ProgramStateRef State, const InvalidatedSymbols &Escaped, const CallEvent *Call, PointerEscapeKind Kind, RegionAndSymbolInvalidationTraits *ITraits)
Run checkers when pointers escape.
void _registerForPreCall(CheckCallFunc checkfn)
LineState State
void runCheckersForLiveSymbols(ProgramStateRef state, SymbolReaper &SymReaper)
Run checkers for live symbols.
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
for(const auto &A :T->param_types())
void _registerForEndOfTranslationUnit(CheckEndOfTranslationUnit checkfn)
Represents any expression that calls an Objective-C method.
Definition: CallEvent.h:870
const LocationContext * getLocationContext() const
void _registerForLiveSymbols(CheckLiveSymbolsFunc checkfn)
void runCheckersOnASTDecl(const Decl *D, AnalysisManager &mgr, BugReporter &BR)
Run checkers handling Decls.
bool(* HandlesStmtFunc)(const Stmt *D)
void runCheckersForPrintState(raw_ostream &Out, ProgramStateRef State, const char *NL, const char *Sep)
Run checkers for debug-printing a ProgramState.
void runCheckersForBind(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, SVal location, SVal val, const Stmt *S, ExprEngine &Eng, const ProgramPoint &PP)
Run checkers for binding of a value to a location.
void _registerForBody(CheckDeclFunc checkfn)
This is the simplest builder which generates nodes in the ExplodedGraph.
Definition: CoreEngine.h:211
void _registerForEndAnalysis(CheckEndAnalysisFunc checkfn)
void _registerForLocation(CheckLocationFunc checkfn)
The pointer has been passed to a function call directly.
void _registerForPointerEscape(CheckPointerEscapeFunc checkfn)
void runCheckersForEvalCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &CE, ExprEngine &Eng)
Run checkers for evaluating a call.
void _registerForPostCall(CheckCallFunc checkfn)
virtual bool hasBody() const
Returns true if this Decl represents a declaration for a body of code, such as a function or method d...
Definition: DeclBase.h:980
BugReporter is a utility class for generating PathDiagnostics for analysis.
Definition: BugReporter.h:403
void _registerForPreObjCMessage(CheckObjCMessageFunc checkfn)
Kind
void runCheckersForBranchCondition(const Stmt *condition, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers for branch condition.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Definition: SVals.h:63
void _registerForBranchCondition(CheckBranchConditionFunc checkfn)
ProgramStateRef runCheckersForEvalAssume(ProgramStateRef state, SVal Cond, bool Assumption)
Run checkers for handling assumptions on symbolic values.
void runCheckersForObjCMessage(ObjCMessageVisitKind visitKind, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng, bool wasInlined=false)
Run checkers for visiting obj-c messages.
A class responsible for cleaning up unused symbols.
void runCheckersOnASTBody(const Decl *D, AnalysisManager &mgr, BugReporter &BR)
Run checkers handling Decls containing a Stmt body.
void insert(const ExplodedNodeSet &S)
void runCheckersForDeadSymbols(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, SymbolReaper &SymReaper, const Stmt *S, ExprEngine &Eng, ProgramPoint::Kind K)
Run checkers for dead symbols.
Dataflow Directional Tag Classes.
StmtClass getStmtClass() const
Definition: Stmt.h:378
void runCheckersForStmt(bool isPreVisit, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng, bool wasInlined=false)
Run checkers for visiting Stmts.
Kind getKind() const
Definition: DeclBase.h:419
void _registerForDecl(CheckDeclFunc checkfn, HandlesDeclFunc isForDeclFn)
void _registerForPostObjCMessage(CheckObjCMessageFunc checkfn)
Represents an abstract call to a function or method along a particular path.
Definition: CallEvent.h:140
void _registerForEndFunction(CheckEndFunctionFunc checkfn)
void _registerForEvalAssume(EvalAssumeFunc checkfn)
void _registerForPostStmt(CheckStmtFunc checkfn, HandlesStmtFunc isForStmtFn)
PointerEscapeKind
Describes the different reasons a pointer escapes during analysis.
void runCheckersForCallEvent(bool isPreVisit, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng, bool wasInlined=false)
Run checkers for visiting obj-c messages.
void runCheckersForEndAnalysis(ExplodedGraph &G, BugReporter &BR, ExprEngine &Eng)
Run checkers for end of analysis.
void _registerForEvalCall(EvalCallFunc checkfn)
void defaultEvalCall(NodeBuilder &B, ExplodedNode *Pred, const CallEvent &Call)
Default implementation of call evaluation.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2209
ProgramStateRef runCheckersForRegionChanges(ProgramStateRef state, const InvalidatedSymbols *invalidated, ArrayRef< const MemRegion *> ExplicitRegions, ArrayRef< const MemRegion *> Regions, const LocationContext *LCtx, const CallEvent *Call)
Run checkers for region changes.
void runCheckersForBeginFunction(ExplodedNodeSet &Dst, const BlockEdge &L, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers on beginning of function.
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:107
void _registerForConstPointerEscape(CheckPointerEscapeFunc checkfn)
void runCheckersOnEndOfTranslationUnit(const TranslationUnitDecl *TU, AnalysisManager &mgr, BugReporter &BR)
Run checkers for the entire Translation Unit.
void _registerForPreStmt(CheckStmtFunc checkfn, HandlesStmtFunc isForStmtFn)
void _registerForBind(CheckBindFunc checkfn)