clang  9.0.0svn
CoreEngine.cpp
Go to the documentation of this file.
1 //===- CoreEngine.cpp - Path-Sensitive Dataflow Engine --------------------===//
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 a generic engine for intraprocedural, path-sensitive,
10 // dataflow analysis via graph reachability engine.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "clang/AST/Expr.h"
16 #include "clang/AST/ExprCXX.h"
17 #include "clang/AST/Stmt.h"
18 #include "clang/AST/StmtCXX.h"
20 #include "clang/Analysis/CFG.h"
22 #include "clang/Basic/LLVM.h"
29 #include "llvm/ADT/Optional.h"
30 #include "llvm/ADT/STLExtras.h"
31 #include "llvm/ADT/Statistic.h"
32 #include "llvm/Support/Casting.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include <algorithm>
35 #include <cassert>
36 #include <memory>
37 #include <utility>
38 
39 using namespace clang;
40 using namespace ento;
41 
42 #define DEBUG_TYPE "CoreEngine"
43 
44 STATISTIC(NumSteps,
45  "The # of steps executed.");
46 STATISTIC(NumReachedMaxSteps,
47  "The # of times we reached the max number of steps.");
48 STATISTIC(NumPathsExplored,
49  "The # of paths explored by the analyzer.");
50 
51 //===----------------------------------------------------------------------===//
52 // Core analysis engine.
53 //===----------------------------------------------------------------------===//
54 
55 static std::unique_ptr<WorkList> generateWorkList(AnalyzerOptions &Opts,
56  SubEngine &subengine) {
57  switch (Opts.getExplorationStrategy()) {
59  return WorkList::makeDFS();
61  return WorkList::makeBFS();
70  }
71  llvm_unreachable("Unknown AnalyzerOptions::ExplorationStrategyKind");
72 }
73 
75  AnalyzerOptions &Opts)
76  : SubEng(subengine), WList(generateWorkList(Opts, subengine)),
77  BCounterFactory(G.getAllocator()), FunctionSummaries(FS) {}
78 
79 /// ExecuteWorkList - Run the worklist algorithm for a maximum number of steps.
80 bool CoreEngine::ExecuteWorkList(const LocationContext *L, unsigned Steps,
81  ProgramStateRef InitState) {
82  if (G.num_roots() == 0) { // Initialize the analysis by constructing
83  // the root if none exists.
84 
85  const CFGBlock *Entry = &(L->getCFG()->getEntry());
86 
87  assert(Entry->empty() && "Entry block must be empty.");
88 
89  assert(Entry->succ_size() == 1 && "Entry block must have 1 successor.");
90 
91  // Mark the entry block as visited.
92  FunctionSummaries->markVisitedBasicBlock(Entry->getBlockID(),
93  L->getDecl(),
94  L->getCFG()->getNumBlockIDs());
95 
96  // Get the solitary successor.
97  const CFGBlock *Succ = *(Entry->succ_begin());
98 
99  // Construct an edge representing the
100  // starting location in the function.
101  BlockEdge StartLoc(Entry, Succ, L);
102 
103  // Set the current block counter to being empty.
104  WList->setBlockCounter(BCounterFactory.GetEmptyCounter());
105 
106  if (!InitState)
107  InitState = SubEng.getInitialState(L);
108 
109  bool IsNew;
110  ExplodedNode *Node = G.getNode(StartLoc, InitState, false, &IsNew);
111  assert(IsNew);
112  G.addRoot(Node);
113 
114  NodeBuilderContext BuilderCtx(*this, StartLoc.getDst(), Node);
115  ExplodedNodeSet DstBegin;
116  SubEng.processBeginOfFunction(BuilderCtx, Node, DstBegin, StartLoc);
117 
118  enqueue(DstBegin);
119  }
120 
121  // Check if we have a steps limit
122  bool UnlimitedSteps = Steps == 0;
123  // Cap our pre-reservation in the event that the user specifies
124  // a very large number of maximum steps.
125  const unsigned PreReservationCap = 4000000;
126  if(!UnlimitedSteps)
127  G.reserve(std::min(Steps,PreReservationCap));
128 
129  while (WList->hasWork()) {
130  if (!UnlimitedSteps) {
131  if (Steps == 0) {
132  NumReachedMaxSteps++;
133  break;
134  }
135  --Steps;
136  }
137 
138  NumSteps++;
139 
140  const WorkListUnit& WU = WList->dequeue();
141 
142  // Set the current block counter.
143  WList->setBlockCounter(WU.getBlockCounter());
144 
145  // Retrieve the node.
146  ExplodedNode *Node = WU.getNode();
147 
148  dispatchWorkItem(Node, Node->getLocation(), WU);
149  }
150  SubEng.processEndWorklist();
151  return WList->hasWork();
152 }
153 
155  const WorkListUnit& WU) {
156  // Dispatch on the location type.
157  switch (Loc.getKind()) {
159  HandleBlockEdge(Loc.castAs<BlockEdge>(), Pred);
160  break;
161 
163  HandleBlockEntrance(Loc.castAs<BlockEntrance>(), Pred);
164  break;
165 
167  assert(false && "BlockExit location never occur in forward analysis.");
168  break;
169 
171  HandleCallEnter(Loc.castAs<CallEnter>(), Pred);
172  break;
173 
175  SubEng.processCallExit(Pred);
176  break;
177 
179  assert(Pred->hasSinglePred() &&
180  "Assume epsilon has exactly one predecessor by construction");
181  ExplodedNode *PNode = Pred->getFirstPred();
182  dispatchWorkItem(Pred, PNode->getLocation(), WU);
183  break;
184  }
185  default:
186  assert(Loc.getAs<PostStmt>() ||
187  Loc.getAs<PostInitializer>() ||
188  Loc.getAs<PostImplicitCall>() ||
189  Loc.getAs<CallExitEnd>() ||
190  Loc.getAs<LoopExit>() ||
191  Loc.getAs<PostAllocatorCall>());
192  HandlePostStmt(WU.getBlock(), WU.getIndex(), Pred);
193  break;
194  }
195 }
196 
198  unsigned Steps,
199  ProgramStateRef InitState,
200  ExplodedNodeSet &Dst) {
201  bool DidNotFinish = ExecuteWorkList(L, Steps, InitState);
202  for (ExplodedGraph::eop_iterator I = G.eop_begin(), E = G.eop_end(); I != E;
203  ++I) {
204  Dst.Add(*I);
205  }
206  return DidNotFinish;
207 }
208 
209 void CoreEngine::HandleBlockEdge(const BlockEdge &L, ExplodedNode *Pred) {
210  const CFGBlock *Blk = L.getDst();
211  NodeBuilderContext BuilderCtx(*this, Blk, Pred);
212 
213  // Mark this block as visited.
214  const LocationContext *LC = Pred->getLocationContext();
215  FunctionSummaries->markVisitedBasicBlock(Blk->getBlockID(),
216  LC->getDecl(),
217  LC->getCFG()->getNumBlockIDs());
218 
219  // Display a prunable path note to the user if it's a virtual bases branch
220  // and we're taking the path that skips virtual base constructors.
222  L.getDst() == *L.getSrc()->succ_begin()) {
223  ProgramPoint P = L.withTag(getNoteTags().makeNoteTag(
224  [](BugReporterContext &, BugReport &) -> std::string {
225  // TODO: Just call out the name of the most derived class
226  // when we know it.
227  return "Virtual base initialization skipped because "
228  "it has already been handled by the most derived class";
229  }, /*IsPrunable=*/true));
230  // Perform the transition.
231  ExplodedNodeSet Dst;
232  NodeBuilder Bldr(Pred, Dst, BuilderCtx);
233  Pred = Bldr.generateNode(P, Pred->getState(), Pred);
234  if (!Pred)
235  return;
236  }
237 
238  // Check if we are entering the EXIT block.
239  if (Blk == &(L.getLocationContext()->getCFG()->getExit())) {
240  assert(L.getLocationContext()->getCFG()->getExit().empty() &&
241  "EXIT block cannot contain Stmts.");
242 
243  // Get return statement..
244  const ReturnStmt *RS = nullptr;
245  if (!L.getSrc()->empty()) {
246  CFGElement LastElement = L.getSrc()->back();
247  if (Optional<CFGStmt> LastStmt = LastElement.getAs<CFGStmt>()) {
248  RS = dyn_cast<ReturnStmt>(LastStmt->getStmt());
249  } else if (Optional<CFGAutomaticObjDtor> AutoDtor =
250  LastElement.getAs<CFGAutomaticObjDtor>()) {
251  RS = dyn_cast<ReturnStmt>(AutoDtor->getTriggerStmt());
252  }
253  }
254 
255  // Process the final state transition.
256  SubEng.processEndOfFunction(BuilderCtx, Pred, RS);
257 
258  // This path is done. Don't enqueue any more nodes.
259  return;
260  }
261 
262  // Call into the SubEngine to process entering the CFGBlock.
263  ExplodedNodeSet dstNodes;
264  BlockEntrance BE(Blk, Pred->getLocationContext());
265  NodeBuilderWithSinks nodeBuilder(Pred, dstNodes, BuilderCtx, BE);
266  SubEng.processCFGBlockEntrance(L, nodeBuilder, Pred);
267 
268  // Auto-generate a node.
269  if (!nodeBuilder.hasGeneratedNodes()) {
270  nodeBuilder.generateNode(Pred->State, Pred);
271  }
272 
273  // Enqueue nodes onto the worklist.
274  enqueue(dstNodes);
275 }
276 
277 void CoreEngine::HandleBlockEntrance(const BlockEntrance &L,
278  ExplodedNode *Pred) {
279  // Increment the block counter.
280  const LocationContext *LC = Pred->getLocationContext();
281  unsigned BlockId = L.getBlock()->getBlockID();
282  BlockCounter Counter = WList->getBlockCounter();
283  Counter = BCounterFactory.IncrementCount(Counter, LC->getStackFrame(),
284  BlockId);
285  WList->setBlockCounter(Counter);
286 
287  // Process the entrance of the block.
289  NodeBuilderContext Ctx(*this, L.getBlock(), Pred);
290  SubEng.processCFGElement(*E, Pred, 0, &Ctx);
291  }
292  else
293  HandleBlockExit(L.getBlock(), Pred);
294 }
295 
296 void CoreEngine::HandleBlockExit(const CFGBlock * B, ExplodedNode *Pred) {
297  if (const Stmt *Term = B->getTerminatorStmt()) {
298  switch (Term->getStmtClass()) {
299  default:
300  llvm_unreachable("Analysis for this terminator not implemented.");
301 
302  case Stmt::CXXBindTemporaryExprClass:
303  HandleCleanupTemporaryBranch(
304  cast<CXXBindTemporaryExpr>(Term), B, Pred);
305  return;
306 
307  // Model static initializers.
308  case Stmt::DeclStmtClass:
309  HandleStaticInit(cast<DeclStmt>(Term), B, Pred);
310  return;
311 
312  case Stmt::BinaryOperatorClass: // '&&' and '||'
313  HandleBranch(cast<BinaryOperator>(Term)->getLHS(), Term, B, Pred);
314  return;
315 
316  case Stmt::BinaryConditionalOperatorClass:
317  case Stmt::ConditionalOperatorClass:
318  HandleBranch(cast<AbstractConditionalOperator>(Term)->getCond(),
319  Term, B, Pred);
320  return;
321 
322  // FIXME: Use constant-folding in CFG construction to simplify this
323  // case.
324 
325  case Stmt::ChooseExprClass:
326  HandleBranch(cast<ChooseExpr>(Term)->getCond(), Term, B, Pred);
327  return;
328 
329  case Stmt::CXXTryStmtClass:
330  // Generate a node for each of the successors.
331  // Our logic for EH analysis can certainly be improved.
333  et = B->succ_end(); it != et; ++it) {
334  if (const CFGBlock *succ = *it) {
335  generateNode(BlockEdge(B, succ, Pred->getLocationContext()),
336  Pred->State, Pred);
337  }
338  }
339  return;
340 
341  case Stmt::DoStmtClass:
342  HandleBranch(cast<DoStmt>(Term)->getCond(), Term, B, Pred);
343  return;
344 
345  case Stmt::CXXForRangeStmtClass:
346  HandleBranch(cast<CXXForRangeStmt>(Term)->getCond(), Term, B, Pred);
347  return;
348 
349  case Stmt::ForStmtClass:
350  HandleBranch(cast<ForStmt>(Term)->getCond(), Term, B, Pred);
351  return;
352 
353  case Stmt::ContinueStmtClass:
354  case Stmt::BreakStmtClass:
355  case Stmt::GotoStmtClass:
356  break;
357 
358  case Stmt::IfStmtClass:
359  HandleBranch(cast<IfStmt>(Term)->getCond(), Term, B, Pred);
360  return;
361 
362  case Stmt::IndirectGotoStmtClass: {
363  // Only 1 successor: the indirect goto dispatch block.
364  assert(B->succ_size() == 1);
365 
367  builder(Pred, B, cast<IndirectGotoStmt>(Term)->getTarget(),
368  *(B->succ_begin()), this);
369 
370  SubEng.processIndirectGoto(builder);
371  return;
372  }
373 
374  case Stmt::ObjCForCollectionStmtClass:
375  // In the case of ObjCForCollectionStmt, it appears twice in a CFG:
376  //
377  // (1) inside a basic block, which represents the binding of the
378  // 'element' variable to a value.
379  // (2) in a terminator, which represents the branch.
380  //
381  // For (1), subengines will bind a value (i.e., 0 or 1) indicating
382  // whether or not collection contains any more elements. We cannot
383  // just test to see if the element is nil because a container can
384  // contain nil elements.
385  HandleBranch(Term, Term, B, Pred);
386  return;
387 
388  case Stmt::SwitchStmtClass: {
389  SwitchNodeBuilder builder(Pred, B, cast<SwitchStmt>(Term)->getCond(),
390  this);
391 
392  SubEng.processSwitch(builder);
393  return;
394  }
395 
396  case Stmt::WhileStmtClass:
397  HandleBranch(cast<WhileStmt>(Term)->getCond(), Term, B, Pred);
398  return;
399  }
400  }
401 
402  if (B->getTerminator().isVirtualBaseBranch()) {
403  HandleVirtualBaseBranch(B, Pred);
404  return;
405  }
406 
407  assert(B->succ_size() == 1 &&
408  "Blocks with no terminator should have at most 1 successor.");
409 
410  generateNode(BlockEdge(B, *(B->succ_begin()), Pred->getLocationContext()),
411  Pred->State, Pred);
412 }
413 
414 void CoreEngine::HandleCallEnter(const CallEnter &CE, ExplodedNode *Pred) {
415  NodeBuilderContext BuilderCtx(*this, CE.getEntry(), Pred);
416  SubEng.processCallEnter(BuilderCtx, CE, Pred);
417 }
418 
419 void CoreEngine::HandleBranch(const Stmt *Cond, const Stmt *Term,
420  const CFGBlock * B, ExplodedNode *Pred) {
421  assert(B->succ_size() == 2);
422  NodeBuilderContext Ctx(*this, B, Pred);
423  ExplodedNodeSet Dst;
424  SubEng.processBranch(Cond, Ctx, Pred, Dst, *(B->succ_begin()),
425  *(B->succ_begin() + 1));
426  // Enqueue the new frontier onto the worklist.
427  enqueue(Dst);
428 }
429 
430 void CoreEngine::HandleCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE,
431  const CFGBlock *B,
432  ExplodedNode *Pred) {
433  assert(B->succ_size() == 2);
434  NodeBuilderContext Ctx(*this, B, Pred);
435  ExplodedNodeSet Dst;
436  SubEng.processCleanupTemporaryBranch(BTE, Ctx, Pred, Dst, *(B->succ_begin()),
437  *(B->succ_begin() + 1));
438  // Enqueue the new frontier onto the worklist.
439  enqueue(Dst);
440 }
441 
442 void CoreEngine::HandleStaticInit(const DeclStmt *DS, const CFGBlock *B,
443  ExplodedNode *Pred) {
444  assert(B->succ_size() == 2);
445  NodeBuilderContext Ctx(*this, B, Pred);
446  ExplodedNodeSet Dst;
447  SubEng.processStaticInitializer(DS, Ctx, Pred, Dst,
448  *(B->succ_begin()), *(B->succ_begin()+1));
449  // Enqueue the new frontier onto the worklist.
450  enqueue(Dst);
451 }
452 
453 void CoreEngine::HandlePostStmt(const CFGBlock *B, unsigned StmtIdx,
454  ExplodedNode *Pred) {
455  assert(B);
456  assert(!B->empty());
457 
458  if (StmtIdx == B->size())
459  HandleBlockExit(B, Pred);
460  else {
461  NodeBuilderContext Ctx(*this, B, Pred);
462  SubEng.processCFGElement((*B)[StmtIdx], Pred, StmtIdx, &Ctx);
463  }
464 }
465 
466 void CoreEngine::HandleVirtualBaseBranch(const CFGBlock *B,
467  ExplodedNode *Pred) {
468  const LocationContext *LCtx = Pred->getLocationContext();
469  if (const auto *CallerCtor = dyn_cast_or_null<CXXConstructExpr>(
470  LCtx->getStackFrame()->getCallSite())) {
471  switch (CallerCtor->getConstructionKind()) {
474  BlockEdge Loc(B, *B->succ_begin(), LCtx);
475  HandleBlockEdge(Loc, Pred);
476  return;
477  }
478  default:
479  break;
480  }
481  }
482 
483  // We either don't see a parent stack frame because we're in the top frame,
484  // or the parent stack frame doesn't initialize our virtual bases.
485  BlockEdge Loc(B, *(B->succ_begin() + 1), LCtx);
486  HandleBlockEdge(Loc, Pred);
487 }
488 
489 /// generateNode - Utility method to generate nodes, hook up successors,
490 /// and add nodes to the worklist.
491 void CoreEngine::generateNode(const ProgramPoint &Loc,
493  ExplodedNode *Pred) {
494  bool IsNew;
495  ExplodedNode *Node = G.getNode(Loc, State, false, &IsNew);
496 
497  if (Pred)
498  Node->addPredecessor(Pred, G); // Link 'Node' with its predecessor.
499  else {
500  assert(IsNew);
501  G.addRoot(Node); // 'Node' has no predecessor. Make it a root.
502  }
503 
504  // Only add 'Node' to the worklist if it was freshly generated.
505  if (IsNew) WList->enqueue(Node);
506 }
507 
509  const CFGBlock *Block, unsigned Idx) {
510  assert(Block);
511  assert(!N->isSink());
512 
513  // Check if this node entered a callee.
514  if (N->getLocation().getAs<CallEnter>()) {
515  // Still use the index of the CallExpr. It's needed to create the callee
516  // StackFrameContext.
517  WList->enqueue(N, Block, Idx);
518  return;
519  }
520 
521  // Do not create extra nodes. Move to the next CFG element.
522  if (N->getLocation().getAs<PostInitializer>() ||
524  N->getLocation().getAs<LoopExit>()) {
525  WList->enqueue(N, Block, Idx+1);
526  return;
527  }
528 
529  if (N->getLocation().getAs<EpsilonPoint>()) {
530  WList->enqueue(N, Block, Idx);
531  return;
532  }
533 
534  if ((*Block)[Idx].getKind() == CFGElement::NewAllocator) {
535  WList->enqueue(N, Block, Idx+1);
536  return;
537  }
538 
539  // At this point, we know we're processing a normal statement.
540  CFGStmt CS = (*Block)[Idx].castAs<CFGStmt>();
541  PostStmt Loc(CS.getStmt(), N->getLocationContext());
542 
543  if (Loc == N->getLocation().withTag(nullptr)) {
544  // Note: 'N' should be a fresh node because otherwise it shouldn't be
545  // a member of Deferred.
546  WList->enqueue(N, Block, Idx+1);
547  return;
548  }
549 
550  bool IsNew;
551  ExplodedNode *Succ = G.getNode(Loc, N->getState(), false, &IsNew);
552  Succ->addPredecessor(N, G);
553 
554  if (IsNew)
555  WList->enqueue(Succ, Block, Idx+1);
556 }
557 
558 ExplodedNode *CoreEngine::generateCallExitBeginNode(ExplodedNode *N,
559  const ReturnStmt *RS) {
560  // Create a CallExitBegin node and enqueue it.
561  const auto *LocCtx = cast<StackFrameContext>(N->getLocationContext());
562 
563  // Use the callee location context.
564  CallExitBegin Loc(LocCtx, RS);
565 
566  bool isNew;
567  ExplodedNode *Node = G.getNode(Loc, N->getState(), false, &isNew);
568  Node->addPredecessor(N, G);
569  return isNew ? Node : nullptr;
570 }
571 
573  for (const auto I : Set)
574  WList->enqueue(I);
575 }
576 
578  const CFGBlock *Block, unsigned Idx) {
579  for (const auto I : Set)
580  enqueueStmtNode(I, Block, Idx);
581 }
582 
584  for (auto I : Set) {
585  // If we are in an inlined call, generate CallExitBegin node.
586  if (I->getLocationContext()->getParent()) {
587  I = generateCallExitBeginNode(I, RS);
588  if (I)
589  WList->enqueue(I);
590  } else {
591  // TODO: We should run remove dead bindings here.
592  G.addEndOfPath(I);
593  NumPathsExplored++;
594  }
595  }
596 }
597 
598 void NodeBuilder::anchor() {}
599 
601  ProgramStateRef State,
602  ExplodedNode *FromN,
603  bool MarkAsSink) {
604  HasGeneratedNodes = true;
605  bool IsNew;
606  ExplodedNode *N = C.Eng.G.getNode(Loc, State, MarkAsSink, &IsNew);
607  N->addPredecessor(FromN, C.Eng.G);
608  Frontier.erase(FromN);
609 
610  if (!IsNew)
611  return nullptr;
612 
613  if (!MarkAsSink)
614  Frontier.Add(N);
615 
616  return N;
617 }
618 
619 void NodeBuilderWithSinks::anchor() {}
620 
622  if (EnclosingBldr)
623  for (const auto I : Frontier)
624  EnclosingBldr->addNodes(I);
625 }
626 
627 void BranchNodeBuilder::anchor() {}
628 
630  bool branch,
631  ExplodedNode *NodePred) {
632  // If the branch has been marked infeasible we should not generate a node.
633  if (!isFeasible(branch))
634  return nullptr;
635 
636  ProgramPoint Loc = BlockEdge(C.Block, branch ? DstT:DstF,
637  NodePred->getLocationContext());
638  ExplodedNode *Succ = generateNodeImpl(Loc, State, NodePred);
639  return Succ;
640 }
641 
644  ProgramStateRef St,
645  bool IsSink) {
646  bool IsNew;
647  ExplodedNode *Succ =
648  Eng.G.getNode(BlockEdge(Src, I.getBlock(), Pred->getLocationContext()),
649  St, IsSink, &IsNew);
650  Succ->addPredecessor(Pred, Eng.G);
651 
652  if (!IsNew)
653  return nullptr;
654 
655  if (!IsSink)
656  Eng.WList->enqueue(Succ);
657 
658  return Succ;
659 }
660 
663  ProgramStateRef St) {
664  bool IsNew;
665  ExplodedNode *Succ =
666  Eng.G.getNode(BlockEdge(Src, I.getBlock(), Pred->getLocationContext()),
667  St, false, &IsNew);
668  Succ->addPredecessor(Pred, Eng.G);
669  if (!IsNew)
670  return nullptr;
671 
672  Eng.WList->enqueue(Succ);
673  return Succ;
674 }
675 
678  bool IsSink) {
679  // Get the block for the default case.
680  assert(Src->succ_rbegin() != Src->succ_rend());
681  CFGBlock *DefaultBlock = *Src->succ_rbegin();
682 
683  // Sanity check for default blocks that are unreachable and not caught
684  // by earlier stages.
685  if (!DefaultBlock)
686  return nullptr;
687 
688  bool IsNew;
689  ExplodedNode *Succ =
690  Eng.G.getNode(BlockEdge(Src, DefaultBlock, Pred->getLocationContext()),
691  St, IsSink, &IsNew);
692  Succ->addPredecessor(Pred, Eng.G);
693 
694  if (!IsNew)
695  return nullptr;
696 
697  if (!IsSink)
698  Eng.WList->enqueue(Succ);
699 
700  return Succ;
701 }
succ_reverse_iterator succ_rbegin()
Definition: CFG.h:774
bool empty() const
Definition: CFG.h:732
const Stmt * getStmt() const
Definition: CFG.h:132
succ_iterator succ_begin()
Definition: CFG.h:769
bool ExecuteWorkList(const LocationContext *L, unsigned Steps, ProgramStateRef InitState)
ExecuteWorkList - Run the worklist algorithm for a maximum number of steps.
Definition: CoreEngine.cpp:80
Stmt - This represents one statement.
Definition: Stmt.h:66
CFGBlock & getEntry()
Definition: CFG.h:1118
unsigned getBlockID() const
Definition: CFG.h:876
const CFGBlock * getSrc() const
Definition: ProgramPoint.h:511
Represents a point when we begin processing an inlined call.
Definition: ProgramPoint.h:630
StringRef P
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
virtual ProgramStateRef getInitialState(const LocationContext *InitLoc)=0
NoteTag::Factory & getNoteTags()
Definition: CoreEngine.h:203
STATISTIC(NumSteps, "The # of steps executed.")
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type...
Definition: CFG.h:98
const ProgramStateRef & getState() const
An abstract data type used to count the number of times a given block has been visited along a path a...
Definition: BlockCounter.h:29
static std::unique_ptr< WorkList > makeUnexploredFirstPriorityQueue()
Definition: WorkList.cpp:251
virtual void processBranch(const Stmt *Condition, NodeBuilderContext &BuilderCtx, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF)=0
Called by CoreEngine.
Optional< CFGElement > getFirstElement() const
Definition: ProgramPoint.h:237
Represents a point when we exit a loop.
Definition: ProgramPoint.h:713
unsigned succ_size() const
Definition: CFG.h:787
virtual void processCFGElement(const CFGElement E, ExplodedNode *Pred, unsigned StmtIdx, NodeBuilderContext *Ctx)=0
Called by CoreEngine.
void enqueue(ExplodedNodeSet &Set)
Enqueue the given set of nodes onto the work list.
Definition: CoreEngine.cpp:572
bool ExecuteWorkListWithInitialState(const LocationContext *L, unsigned Steps, ProgramStateRef InitState, ExplodedNodeSet &Dst)
Returns true if there is still simulation state on the worklist.
Definition: CoreEngine.cpp:197
Defines the clang::Expr interface and subclasses for C++ expressions.
const CFGBlock * getEntry() const
Returns the entry block in the CFG for the entered function.
Definition: ProgramPoint.h:645
LineState State
static std::unique_ptr< WorkList > makeDFS()
Definition: WorkList.cpp:81
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
Definition: CFG.h:383
CoreEngine(SubEngine &subengine, FunctionSummariesTy *FS, AnalyzerOptions &Opts)
Construct a CoreEngine object to analyze the provided CFG.
Definition: CoreEngine.cpp:74
void addPredecessor(ExplodedNode *V, ExplodedGraph &G)
addPredeccessor - Adds a predecessor to the current node, and in tandem add this node as a successor ...
Represents a point when we start the call exit sequence (for inlined call).
Definition: ProgramPoint.h:668
AdjacentBlocks::const_iterator const_succ_iterator
Definition: CFG.h:745
This is a meta program point, which should be skipped by all the diagnostic reasoning etc...
Definition: ProgramPoint.h:732
ExplodedNode * generateNodeImpl(const ProgramPoint &PP, ProgramStateRef State, ExplodedNode *Pred, bool MarkAsSink=false)
Definition: CoreEngine.cpp:600
virtual void processIndirectGoto(IndirectGotoNodeBuilder &builder)=0
Called by CoreEngine.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
const LocationContext * getLocationContext() const
ExplodedNode * generateCaseStmtNode(const iterator &I, ProgramStateRef State)
Definition: CoreEngine.cpp:662
const CFGBlock * getBlock() const
Definition: CoreEngine.h:552
BlockCounter getBlockCounter() const
Returns the block counter map associated with the worklist unit.
Definition: WorkList.h:51
unsigned size() const
Definition: CFG.h:731
virtual void processCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE, NodeBuilderContext &BldCtx, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF)=0
Called by CoreEngine.
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1277
ExplodedNode * getFirstPred()
static std::unique_ptr< WorkList > makeBFS()
Definition: WorkList.cpp:85
const Stmt * getCallSite() const
Represents a single basic block in a source-level CFG.
Definition: CFG.h:570
Represents a point when we finish the call exit sequence (for inlined call).
Definition: ProgramPoint.h:688
const CFGBlock * getBlock() const
Definition: ProgramPoint.h:233
virtual void processSwitch(SwitchNodeBuilder &builder)=0
Called by CoreEngine.
unsigned getIndex() const
Return the index within the CFGBlock for the worklist unit.
Definition: WorkList.h:57
Kind getKind() const
Definition: ProgramPoint.h:160
This is the simplest builder which generates nodes in the ExplodedGraph.
Definition: CoreEngine.h:236
void Add(ExplodedNode *N)
unsigned num_roots() const
const CFGBlock * getDst() const
Definition: ProgramPoint.h:515
void enqueueStmtNode(ExplodedNode *N, const CFGBlock *Block, unsigned Idx)
Enqueue a single node created as a result of statement processing.
Definition: CoreEngine.cpp:508
virtual void processStaticInitializer(const DeclStmt *DS, NodeBuilderContext &BuilderCtx, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF)=0
Called by CoreEngine.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
Definition: Stmt.h:2575
ExplodedNode * getNode(const ProgramPoint &L, ProgramStateRef State, bool IsSink=false, bool *IsNew=nullptr)
Retrieve the node associated with a (Location,State) pair, where the &#39;Location&#39; is a ProgramPoint in ...
CFGElement back() const
Definition: CFG.h:719
ExplodedNode * getNode() const
Returns the node associated with the worklist unit.
Definition: WorkList.h:48
ExplodedNode * generateNode(const iterator &I, ProgramStateRef State, bool isSink=false)
Definition: CoreEngine.cpp:643
static std::unique_ptr< WorkList > makeUnexploredFirstPriorityLocationQueue()
Definition: WorkList.cpp:311
T castAs() const
Convert to the specified ProgramPoint type, asserting that this ProgramPoint is of the desired type...
Definition: ProgramPoint.h:140
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:1183
void dispatchWorkItem(ExplodedNode *Pred, ProgramPoint Loc, const WorkListUnit &WU)
Dispatch the work list item based on the given location information.
Definition: CoreEngine.cpp:154
ProgramPoint getLocation() const
getLocation - Returns the edge associated with the given node.
NodeVector::iterator eop_iterator
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
Definition: CFG.h:1194
static std::unique_ptr< WorkList > makeBFSBlockDFSContents()
Definition: WorkList.cpp:126
virtual void processCallExit(ExplodedNode *Pred)=0
succ_iterator succ_end()
Definition: CFG.h:770
Optional< T > getAs() const
Convert to the specified CFGElement type, returning None if this CFGElement is not of the desired typ...
Definition: CFG.h:109
ast_type_traits::DynTypedNode Node
ExplorationStrategyKind getExplorationStrategy() const
Dataflow Directional Tag Classes.
ExplodedNode * generateDefaultCaseNode(ProgramStateRef State, bool isSink=false)
Definition: CoreEngine.cpp:677
Represents a program point just after an implicit call event.
Definition: ProgramPoint.h:600
This node builder keeps track of the generated sink nodes.
Definition: CoreEngine.h:341
bool isVirtualBaseBranch() const
Definition: CFG.h:539
Stmt * getTerminatorStmt()
Definition: CFG.h:860
virtual void processCallEnter(NodeBuilderContext &BC, CallEnter CE, ExplodedNode *Pred)=0
const CFGBlock * getBlock() const
Returns the CFGblock associated with the worklist unit.
Definition: WorkList.h:54
const Decl * getDecl() const
void reserve(unsigned NodeCount)
virtual void processEndWorklist()=0
Called by CoreEngine when the analysis worklist is either empty or the.
const LocationContext * getLocationContext() const
Definition: ProgramPoint.h:179
virtual void processBeginOfFunction(NodeBuilderContext &BC, ExplodedNode *Pred, ExplodedNodeSet &Dst, const BlockEdge &L)=0
Called by CoreEngine.
const StackFrameContext * getStackFrame() const
Stores options for the analyzer from the command line.
void enqueueEndOfFunction(ExplodedNodeSet &Set, const ReturnStmt *RS)
enqueue the nodes corresponding to the end of function onto the end of path / work list...
Definition: CoreEngine.cpp:583
ExplodedNode * generateNode(const ProgramPoint &PP, ProgramStateRef State, ExplodedNode *Pred)
Generates a node in the ExplodedGraph.
Definition: CoreEngine.h:289
ExplodedNode * generateNode(ProgramStateRef State, bool branch, ExplodedNode *Pred)
Definition: CoreEngine.cpp:629
Represents a top-level expression in a basic block.
Definition: CFG.h:55
BlockCounter IncrementCount(BlockCounter BC, const StackFrameContext *CallSite, unsigned BlockID)
virtual void processEndOfFunction(NodeBuilderContext &BC, ExplodedNode *Pred, const ReturnStmt *RS=nullptr)=0
Called by CoreEngine.
ExplodedNode * addEndOfPath(ExplodedNode *V)
addEndOfPath - Add an untyped node to the set of EOP nodes.
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:943
static std::unique_ptr< WorkList > makeUnexploredFirst()
Definition: WorkList.cpp:188
virtual void processCFGBlockEntrance(const BlockEdge &L, NodeBuilderWithSinks &nodeBuilder, ExplodedNode *Pred)=0
Called by CoreEngine when it starts processing a CFGBlock.
__DEVICE__ int min(int __a, int __b)
Optional< T > getAs() const
Convert to the specified ProgramPoint type, returning None if this ProgramPoint is not of the desired...
Definition: ProgramPoint.h:151
This class provides an interface through which checkers can create individual bug reports...
Definition: BugReporter.h:75
CFGTerminator getTerminator() const
Definition: CFG.h:858
ExplodedNode * addRoot(ExplodedNode *V)
addRoot - Add an untyped node to the set of roots.
void markVisitedBasicBlock(unsigned ID, const Decl *D, unsigned TotalIDs)
static std::unique_ptr< WorkList > generateWorkList(AnalyzerOptions &Opts, SubEngine &subengine)
Definition: CoreEngine.cpp:55
CFGBlock & getExit()
Definition: CFG.h:1120