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 
15 #include "clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h"
16 #include "clang/AST/Expr.h"
17 #include "clang/AST/ExprCXX.h"
18 #include "clang/AST/Stmt.h"
19 #include "clang/AST/StmtCXX.h"
20 #include "clang/Analysis/AnalysisDeclContext.h"
21 #include "clang/Analysis/CFG.h"
22 #include "clang/Analysis/ProgramPoint.h"
23 #include "clang/Basic/LLVM.h"
24 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
25 #include "clang/StaticAnalyzer/Core/PathSensitive/BlockCounter.h"
26 #include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
27 #include "clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h"
28 #include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
29 #include "clang/StaticAnalyzer/Core/PathSensitive/WorkList.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()) {
58     case AnalyzerOptions::ExplorationStrategyKind::DFS:
59       return WorkList::makeDFS();
60     case AnalyzerOptions::ExplorationStrategyKind::BFS:
61       return WorkList::makeBFS();
62     case AnalyzerOptions::ExplorationStrategyKind::BFSBlockDFSContents:
63       return WorkList::makeBFSBlockDFSContents();
64     case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirst:
65       return WorkList::makeUnexploredFirst();
66     case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstQueue:
67       return WorkList::makeUnexploredFirstPriorityQueue();
68     default:
69       llvm_unreachable("Unexpected case");
70   }
71 }
72 
73 CoreEngine::CoreEngine(SubEngine &subengine, FunctionSummariesTy *FS,
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   }
149   SubEng.processEndWorklist(hasWorkRemaining());
150   return WList->hasWork();
151 }
152 
153 void CoreEngine::dispatchWorkItem(ExplodedNode* Pred, ProgramPoint Loc,
154                                   const WorkListUnit& WU) {
155   // Dispatch on the location type.
156   switch (Loc.getKind()) {
157     case ProgramPoint::BlockEdgeKind:
158       HandleBlockEdge(Loc.castAs<BlockEdge>(), Pred);
159       break;
160 
161     case ProgramPoint::BlockEntranceKind:
162       HandleBlockEntrance(Loc.castAs<BlockEntrance>(), Pred);
163       break;
164 
165     case ProgramPoint::BlockExitKind:
166       assert(false && "BlockExit location never occur in forward analysis.");
167       break;
168 
169     case ProgramPoint::CallEnterKind:
170       HandleCallEnter(Loc.castAs<CallEnter>(), Pred);
171       break;
172 
173     case ProgramPoint::CallExitBeginKind:
174       SubEng.processCallExit(Pred);
175       break;
176 
177     case ProgramPoint::EpsilonKind: {
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 
196 bool CoreEngine::ExecuteWorkListWithInitialState(const LocationContext *L,
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.
268   if (Optional<CFGElement> E = L.getFirstElement()) {
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.
312         for (CFGBlock::const_succ_iterator it = B->succ_begin(),
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 
346         IndirectGotoNodeBuilder
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,
444                               ProgramStateRef State,
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 
460 void CoreEngine::enqueueStmtNode(ExplodedNode *N,
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>() ||
475       N->getLocation().getAs<PostImplicitCall>()||
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 
524 void CoreEngine::enqueue(ExplodedNodeSet &Set) {
525   for (const auto I : Set)
526     WList->enqueue(I);
527 }
528 
529 void CoreEngine::enqueue(ExplodedNodeSet &Set,
530                          const CFGBlock *Block, unsigned Idx) {
531   for (const auto I : Set)
532     enqueueStmtNode(I, Block, Idx);
533 }
534 
535 void CoreEngine::enqueueEndOfFunction(ExplodedNodeSet &Set, const ReturnStmt *RS) {
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 
552 ExplodedNode* NodeBuilder::generateNodeImpl(const ProgramPoint &Loc,
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 
573 StmtNodeBuilder::~StmtNodeBuilder() {
574   if (EnclosingBldr)
575     for (const auto I : Frontier)
576       EnclosingBldr->addNodes(I);
577 }
578 
579 void BranchNodeBuilder::anchor() {}
580 
581 ExplodedNode *BranchNodeBuilder::generateNode(ProgramStateRef State,
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 
594 ExplodedNode*
595 IndirectGotoNodeBuilder::generateNode(const iterator &I,
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 
613 ExplodedNode*
614 SwitchNodeBuilder::generateCaseStmtNode(const iterator &I,
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 
628 ExplodedNode*
629 SwitchNodeBuilder::generateDefaultCaseNode(ProgramStateRef St,
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 }
654