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