clang 23.0.0git
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
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"
31#include "llvm/Support/ErrorHandling.h"
32#include "llvm/Support/FormatVariadic.h"
33#include "llvm/Support/TimeProfiler.h"
34#include <algorithm>
35#include <cassert>
36#include <memory>
37#include <optional>
38#include <utility>
39
40using namespace clang;
41using namespace ento;
42
43#define DEBUG_TYPE "CoreEngine"
44
45STAT_COUNTER(NumSteps, "The # of steps executed.");
46STAT_COUNTER(NumSTUSteps, "The # of STU steps executed.");
47STAT_COUNTER(NumCTUSteps, "The # of CTU steps executed.");
48ALWAYS_ENABLED_STATISTIC(NumReachedMaxSteps,
49 "The # of times we reached the max number of steps.");
50STAT_COUNTER(NumPathsExplored, "The # of paths explored by the analyzer.");
51
52//===----------------------------------------------------------------------===//
53// Core analysis engine.
54//===----------------------------------------------------------------------===//
55
73
75 AnalyzerOptions &Opts)
76 : ExprEng(exprengine), WList(generateWorkList(Opts)),
77 CTUWList(Opts.IsNaiveCTUEnabled ? generateWorkList(Opts) : nullptr),
78 BCounterFactory(G.getAllocator()), FunctionSummaries(FS) {}
79
80void CoreEngine::setBlockCounter(BlockCounter C) {
81 WList->setBlockCounter(C);
82 if (CTUWList)
83 CTUWList->setBlockCounter(C);
84}
85
86/// ExecuteWorkList - Run the worklist algorithm for a maximum number of steps.
87bool CoreEngine::ExecuteWorkList(const StackFrame *SF, unsigned MaxSteps,
88 ProgramStateRef InitState) {
89 if (G.empty()) {
90 assert(!G.getRoot() && "empty graph must not have a root node");
91 // Initialize the analysis by constructing the root if there are no nodes.
92
93 const CFGBlock *Entry = &(SF->getCFG()->getEntry());
94
95 assert(Entry->empty() && "Entry block must be empty.");
96
97 assert(Entry->succ_size() == 1 && "Entry block must have 1 successor.");
98
99 // Mark the entry block as visited.
100 FunctionSummaries->markVisitedBasicBlock(Entry->getBlockID(), SF->getDecl(),
101 SF->getCFG()->getNumBlockIDs());
102
103 // Get the solitary successor.
104 const CFGBlock *Succ = *(Entry->succ_begin());
105
106 // Construct an edge representing the
107 // starting location in the function.
108 BlockEdge StartLoc(Entry, Succ, SF);
109
110 // Set the current block counter to being empty.
111 setBlockCounter(BCounterFactory.GetEmptyCounter());
112
113 if (!InitState)
114 InitState = ExprEng.getInitialState(SF);
115
116 bool IsNew;
117 ExplodedNode *Node = G.getNode(StartLoc, InitState, false, &IsNew);
118 assert(IsNew);
119 G.designateAsRoot(Node);
120
121 ExprEng.setCurrStackFrameAndBlock(Node->getStackFrame(), Succ);
122
123 ExplodedNodeSet DstBegin;
124 ExprEng.processBeginOfFunction(Node, DstBegin, StartLoc);
125
126 enqueue(DstBegin);
127 }
128
129 // Check if we have a steps limit
130 bool UnlimitedSteps = MaxSteps == 0;
131
132 // Cap our pre-reservation in the event that the user specifies
133 // a very large number of maximum steps.
134 const unsigned PreReservationCap = 4000000;
135 if(!UnlimitedSteps)
136 G.reserve(std::min(MaxSteps, PreReservationCap));
137
138 auto ProcessWList = [this, UnlimitedSteps](unsigned MaxSteps) {
139 unsigned Steps = MaxSteps;
140 while (WList->hasWork()) {
141 if (!UnlimitedSteps) {
142 if (Steps == 0) {
143 NumReachedMaxSteps++;
144 break;
145 }
146 --Steps;
147 }
148
149 NumSteps++;
150
151 const WorkListUnit &WU = WList->dequeue();
152
153 // Set the current block counter.
154 setBlockCounter(WU.getBlockCounter());
155
156 // Retrieve the node.
157 ExplodedNode *Node = WU.getNode();
158
159 dispatchWorkItem(Node, Node->getLocation(), WU);
160 }
161 return MaxSteps - Steps;
162 };
163 const unsigned STUSteps = ProcessWList(MaxSteps);
164
165 if (CTUWList) {
166 NumSTUSteps += STUSteps;
167 const unsigned MinCTUSteps =
168 this->ExprEng.getAnalysisManager().options.CTUMaxNodesMin;
169 const unsigned Pct =
170 this->ExprEng.getAnalysisManager().options.CTUMaxNodesPercentage;
171 unsigned MaxCTUSteps = std::max(STUSteps * Pct / 100, MinCTUSteps);
172
173 WList = std::move(CTUWList);
174 const unsigned CTUSteps = ProcessWList(MaxCTUSteps);
175 NumCTUSteps += CTUSteps;
176 }
177
178 ExprEng.processEndWorklist();
179 return WList->hasWork();
180}
181
182static std::string timeTraceScopeName(const ProgramPoint &Loc) {
183 if (llvm::timeTraceProfilerEnabled()) {
184 return llvm::formatv("dispatchWorkItem {0}",
186 .str();
187 }
188 return "";
189}
190
191static llvm::TimeTraceMetadata timeTraceMetadata(const ExplodedNode *Pred,
192 const ProgramPoint &Loc) {
193 // If time-trace profiler is not enabled, this function is never called.
194 assert(llvm::timeTraceProfilerEnabled());
195 std::string Detail = "";
196 if (const auto SP = Loc.getAs<StmtPoint>()) {
197 if (const Stmt *S = SP->getStmt())
198 Detail = S->getStmtClassName();
199 }
200 auto SLoc = Loc.getSourceLocation();
201 if (!SLoc)
202 return llvm::TimeTraceMetadata{std::move(Detail), ""};
203 const auto &SM = Pred->getStackFrame()
205 ->getASTContext()
207 auto Line = SM.getPresumedLineNumber(*SLoc);
208 auto Fname = SM.getFilename(*SLoc);
209 return llvm::TimeTraceMetadata{std::move(Detail), Fname.str(),
210 static_cast<int>(Line)};
211}
212
214 const WorkListUnit &WU) {
215 llvm::TimeTraceScope tcs{timeTraceScopeName(Loc), [Loc, Pred]() {
216 return timeTraceMetadata(Pred, Loc);
217 }};
218 PrettyStackTraceStackFrame CrashInfo(Pred->getStackFrame());
219
220 // This work item is not necessarily related to the previous one, so
221 // the old current StackFrame and Block is no longer relevant.
222 // The new current StackFrame and Block should be set soon, but this
223 // guarantees that buggy access before that will trigger loud crashes instead
224 // of silently using stale data.
225 ExprEng.resetCurrStackFrameAndBlock();
226
227 // Dispatch on the location type.
228 switch (Loc.getKind()) {
230 HandleBlockEdge(Loc.castAs<BlockEdge>(), Pred);
231 break;
232
234 HandleBlockEntrance(Loc.castAs<BlockEntrance>(), Pred);
235 break;
236
238 assert(false && "BlockExit location never occur in forward analysis.");
239 break;
240
242 HandleCallEnter(Loc.castAs<CallEnter>(), Pred);
243 break;
244
246 ExprEng.processCallExit(Pred);
247 break;
248
250 assert(Pred->hasSinglePred() &&
251 "Assume epsilon has exactly one predecessor by construction");
252 ExplodedNode *PNode = Pred->getFirstPred();
253 dispatchWorkItem(Pred, PNode->getLocation(), WU);
254 break;
255 }
256 default:
257 assert(Loc.getAs<PostStmt>() || Loc.getAs<PostInitializer>() ||
261 HandlePostStmt(WU.getBlock(), WU.getIndex(), Pred);
262 break;
263 }
264}
265
266void CoreEngine::HandleBlockEdge(const BlockEdge &L, ExplodedNode *Pred) {
267 const CFGBlock *Blk = L.getDst();
268 ExprEng.setCurrStackFrameAndBlock(Pred->getStackFrame(), Blk);
269
270 // Mark this block as visited.
271 const StackFrame *SF = Pred->getStackFrame();
272 FunctionSummaries->markVisitedBasicBlock(Blk->getBlockID(), SF->getDecl(),
273 SF->getCFG()->getNumBlockIDs());
274
275 // Display a prunable path note to the user if it's a virtual bases branch
276 // and we're taking the path that skips virtual base constructors.
278 L.getDst() == *L.getSrc()->succ_begin()) {
279 ProgramPoint P = L.withTag(getDataTags().make<NoteTag>(
280 [](BugReporterContext &, PathSensitiveBugReport &) -> std::string {
281 // TODO: Just call out the name of the most derived class
282 // when we know it.
283 return "Virtual base initialization skipped because "
284 "it has already been handled by the most derived class";
285 },
286 /*IsPrunable=*/true));
287 // Perform the transition.
288 Pred = makeNode(P, Pred->getState(), Pred);
289 if (!Pred)
290 return;
291 }
292
293 // Check if we are entering the EXIT block.
294 const CFGBlock &ExitBlk = L.getStackFrame()->getCFG()->getExit();
295 if (Blk == &ExitBlk) {
296 assert(ExitBlk.empty() && "EXIT block cannot contain Stmts.");
297
298 // Get return statement..
299 const ReturnStmt *RS = nullptr;
300 if (!L.getSrc()->empty()) {
301 CFGElement LastElement = L.getSrc()->back();
302 if (std::optional<CFGStmt> LastStmt = LastElement.getAs<CFGStmt>()) {
303 RS = dyn_cast<ReturnStmt>(LastStmt->getStmt());
304 } else if (std::optional<CFGAutomaticObjDtor> AutoDtor =
305 LastElement.getAs<CFGAutomaticObjDtor>()) {
306 RS = dyn_cast<ReturnStmt>(AutoDtor->getTriggerStmt());
307 } else if (std::optional<CFGScopeMarker> ScopeMarker =
308 LastElement.getAs<CFGScopeMarker>()) {
309 RS = dyn_cast<ReturnStmt>(ScopeMarker->getTriggerStmt());
310 }
311 }
312
313 ExplodedNodeSet CheckerNodes;
314 BlockEntrance BE(L.getSrc(), L.getDst(), Pred->getStackFrame());
315 ExprEng.runCheckersForBlockEntrance(BE, Pred, CheckerNodes);
316
317 // Process the final state transition.
318 for (ExplodedNode *P : CheckerNodes) {
319 ExprEng.processEndOfFunction(P, RS);
320 }
321
322 // This path is done. Don't enqueue any more nodes.
323 return;
324 }
325
326 // Call into the ExprEngine to process entering the CFGBlock.
327 BlockEntrance BE(L.getSrc(), L.getDst(), Pred->getStackFrame());
328 ExplodedNodeSet DstNodes;
329 NodeBuilder Builder(Pred, DstNodes, ExprEng.getBuilderContext());
330 ExprEng.processCFGBlockEntrance(L, BE, Builder, Pred);
331
332 // Auto-generate a node.
333 if (!Builder.hasGeneratedNodes()) {
334 Builder.generateNode(BE, Pred->State, Pred);
335 }
336
337 ExplodedNodeSet CheckerNodes;
338 for (auto *N : DstNodes) {
339 ExprEng.runCheckersForBlockEntrance(BE, N, CheckerNodes);
340 }
341
342 // Enqueue nodes onto the worklist.
343 enqueue(CheckerNodes);
344}
345
346void CoreEngine::HandleBlockEntrance(const BlockEntrance &L,
347 ExplodedNode *Pred) {
348 // Increment the block counter.
349 const StackFrame *SF = Pred->getStackFrame();
350 unsigned BlockId = L.getBlock()->getBlockID();
351 BlockCounter Counter = WList->getBlockCounter();
352 Counter = BCounterFactory.IncrementCount(Counter, SF, BlockId);
353 setBlockCounter(Counter);
354
355 // Process the entrance of the block.
356 if (std::optional<CFGElement> E = L.getFirstElement()) {
357 ExprEng.setCurrStackFrameAndBlock(Pred->getStackFrame(), L.getBlock());
358 ExprEng.processCFGElement(*E, Pred, 0);
359 } else
360 HandleBlockExit(L.getBlock(), Pred);
361}
362
363void CoreEngine::HandleBlockExit(const CFGBlock * B, ExplodedNode *Pred) {
364 if (const Stmt *Term = B->getTerminatorStmt()) {
365 ExprEng.setCurrStackFrameAndBlock(Pred->getStackFrame(), B);
366
367 switch (Term->getStmtClass()) {
368 default:
369 llvm_unreachable("Analysis for this terminator not implemented.");
370
371 case Stmt::CXXBindTemporaryExprClass:
372 HandleCleanupTemporaryBranch(
373 cast<CXXBindTemporaryExpr>(Term), B, Pred);
374 return;
375
376 // Model static initializers.
377 case Stmt::DeclStmtClass:
378 HandleStaticInit(cast<DeclStmt>(Term), B, Pred);
379 return;
380
381 case Stmt::BinaryOperatorClass: // '&&' and '||'
382 HandleBranch(cast<BinaryOperator>(Term)->getLHS(), Term, B, Pred);
383 return;
384
385 case Stmt::BinaryConditionalOperatorClass:
386 case Stmt::ConditionalOperatorClass:
387 HandleBranch(cast<AbstractConditionalOperator>(Term)->getCond(),
388 Term, B, Pred);
389 return;
390
391 // FIXME: Use constant-folding in CFG construction to simplify this
392 // case.
393
394 case Stmt::ChooseExprClass:
395 HandleBranch(cast<ChooseExpr>(Term)->getCond(), Term, B, Pred);
396 return;
397
398 case Stmt::CXXTryStmtClass:
399 // Generate a node for each of the successors.
400 // Our logic for EH analysis can certainly be improved.
401 for (const CFGBlock *Succ : B->succs()) {
402 if (Succ) {
403 BlockEdge BE(B, Succ, Pred->getStackFrame());
404 if (ExplodedNode *N = makeNode(BE, Pred->State, Pred))
405 WList->enqueue(N);
406 }
407 }
408 return;
409
410 case Stmt::DoStmtClass:
411 HandleBranch(cast<DoStmt>(Term)->getCond(), Term, B, Pred);
412 return;
413
414 case Stmt::CXXForRangeStmtClass:
415 HandleBranch(cast<CXXForRangeStmt>(Term)->getCond(), Term, B, Pred);
416 return;
417
418 case Stmt::ForStmtClass:
419 HandleBranch(cast<ForStmt>(Term)->getCond(), Term, B, Pred);
420 return;
421
422 case Stmt::SEHLeaveStmtClass:
423 case Stmt::ContinueStmtClass:
424 case Stmt::BreakStmtClass:
425 case Stmt::GotoStmtClass:
426 break;
427
428 case Stmt::IfStmtClass:
429 HandleBranch(cast<IfStmt>(Term)->getCond(), Term, B, Pred);
430 return;
431
432 case Stmt::IndirectGotoStmtClass: {
433 // Only 1 successor: the indirect goto dispatch block.
434 assert(B->succ_size() == 1);
435 ExplodedNodeSet Dst;
436 ExprEng.processIndirectGoto(Dst,
437 cast<IndirectGotoStmt>(Term)->getTarget(),
438 *(B->succ_begin()), Pred);
439 enqueue(Dst);
440 return;
441 }
442
443 case Stmt::ObjCForCollectionStmtClass:
444 // In the case of ObjCForCollectionStmt, it appears twice in a CFG:
445 //
446 // (1) inside a basic block, which represents the binding of the
447 // 'element' variable to a value.
448 // (2) in a terminator, which represents the branch.
449 //
450 // For (1), ExprEngine will bind a value (i.e., 0 or 1) indicating
451 // whether or not collection contains any more elements. We cannot
452 // just test to see if the element is nil because a container can
453 // contain nil elements.
454 HandleBranch(Term, Term, B, Pred);
455 return;
456
457 case Stmt::SwitchStmtClass: {
458 ExplodedNodeSet Dst;
459 ExprEng.processSwitch(cast<SwitchStmt>(Term), Pred, Dst);
460 // Enqueue the new frontier onto the worklist.
461 enqueue(Dst);
462 return;
463 }
464
465 case Stmt::WhileStmtClass:
466 HandleBranch(cast<WhileStmt>(Term)->getCond(), Term, B, Pred);
467 return;
468
469 case Stmt::GCCAsmStmtClass:
470 assert(cast<GCCAsmStmt>(Term)->isAsmGoto() && "Encountered GCCAsmStmt without labels");
471 // TODO: Handle jumping to labels
472 return;
473 }
474 }
475
477 HandleVirtualBaseBranch(B, Pred);
478 return;
479 }
480
481 assert(B->succ_size() == 1 &&
482 "Blocks with no terminator should have at most 1 successor.");
483
484 BlockEdge BE(B, *(B->succ_begin()), Pred->getStackFrame());
485 if (ExplodedNode *N = makeNode(BE, Pred->State, Pred))
486 WList->enqueue(N);
487}
488
489void CoreEngine::HandleCallEnter(const CallEnter &CE, ExplodedNode *Pred) {
490 ExprEng.setCurrStackFrameAndBlock(Pred->getStackFrame(), CE.getEntry());
491 ExprEng.processCallEnter(CE, Pred);
492}
493
494void CoreEngine::HandleBranch(const Stmt *Cond, const Stmt *Term,
495 const CFGBlock * B, ExplodedNode *Pred) {
496 assert(B->succ_size() == 2);
497 ExplodedNodeSet Dst;
498 ExprEng.processBranch(Cond, Pred, Dst, *(B->succ_begin()),
499 *(B->succ_begin() + 1),
500 getCompletedIterationCount(B, Pred));
501 // Enqueue the new frontier onto the worklist.
502 enqueue(Dst);
503}
504
505void CoreEngine::HandleCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE,
506 const CFGBlock *B,
507 ExplodedNode *Pred) {
508 assert(B->succ_size() == 2);
509 ExplodedNodeSet Dst;
510 ExprEng.processCleanupTemporaryBranch(BTE, Pred, Dst, *(B->succ_begin()),
511 *(B->succ_begin() + 1));
512 // Enqueue the new frontier onto the worklist.
513 enqueue(Dst);
514}
515
516void CoreEngine::HandleStaticInit(const DeclStmt *DS, const CFGBlock *B,
517 ExplodedNode *Pred) {
518 assert(B->succ_size() == 2);
519 ExplodedNodeSet Dst;
520 ExprEng.processStaticInitializer(DS, Pred, Dst, *(B->succ_begin()),
521 *(B->succ_begin() + 1));
522 // Enqueue the new frontier onto the worklist.
523 enqueue(Dst);
524}
525
526void CoreEngine::HandlePostStmt(const CFGBlock *B, unsigned StmtIdx,
527 ExplodedNode *Pred) {
528 assert(B);
529 assert(!B->empty());
530
531 // We no-op by skipping any FullExprCleanup
532 while (StmtIdx < B->size() &&
533 (*B)[StmtIdx].getKind() == CFGElement::FullExprCleanup) {
534 StmtIdx++;
535 }
536
537 if (StmtIdx == B->size())
538 HandleBlockExit(B, Pred);
539 else {
540 ExprEng.setCurrStackFrameAndBlock(Pred->getStackFrame(), B);
541 ExprEng.processCFGElement((*B)[StmtIdx], Pred, StmtIdx);
542 }
543}
544
545void CoreEngine::HandleVirtualBaseBranch(const CFGBlock *B,
546 ExplodedNode *Pred) {
547 const StackFrame *SF = Pred->getStackFrame();
548 if (const auto *CallerCtor =
549 dyn_cast_or_null<CXXConstructExpr>(SF->getCallSite())) {
550 switch (CallerCtor->getConstructionKind()) {
553 BlockEdge Loc(B, *B->succ_begin(), SF);
554 HandleBlockEdge(Loc, Pred);
555 return;
556 }
557 default:
558 break;
559 }
560 }
561
562 // We either don't see a parent stack frame because we're in the top frame,
563 // or the parent stack frame doesn't initialize our virtual bases.
564 BlockEdge Loc(B, *(B->succ_begin() + 1), SF);
565 HandleBlockEdge(Loc, Pred);
566}
567
569 ProgramStateRef State, ExplodedNode *Pred,
570 bool MarkAsSink) const {
571 MarkAsSink = MarkAsSink || State->isPosteriorlyOverconstrained();
572
573 bool IsNew;
574 ExplodedNode *N = G.getNode(Loc, State, MarkAsSink, &IsNew);
575 N->addPredecessor(Pred, G);
576
577 return IsNew ? N : nullptr;
578}
579
581 const CFGBlock *Block, unsigned Idx) {
582 assert(Block);
583 assert(!N->isSink());
584
585 // Check if this node entered a callee.
586 if (N->getLocation().getAs<CallEnter>()) {
587 // Still use the index of the CallExpr. It's needed to create the callee
588 // StackFrame.
589 WList->enqueue(N, Block, Idx);
590 return;
591 }
592
593 // Do not create extra nodes. Move to the next CFG element.
594 if (N->getLocation().getAs<PostInitializer>() ||
596 N->getLocation().getAs<LoopExit>() ||
597 N->getLocation().getAs<LifetimeEnd>()) {
598 WList->enqueue(N, Block, Idx + 1);
599 return;
600 }
601
602 if (N->getLocation().getAs<EpsilonPoint>()) {
603 WList->enqueue(N, Block, Idx);
604 return;
605 }
606
607 if ((*Block)[Idx].getKind() == CFGElement::NewAllocator) {
608 WList->enqueue(N, Block, Idx+1);
609 return;
610 }
611
612 // At this point, we know we're processing a normal statement.
613 CFGStmt CS = (*Block)[Idx].castAs<CFGStmt>();
614 PostStmt Loc(CS.getStmt(), N->getStackFrame());
615
616 if (Loc == N->getLocation().withTag(nullptr)) {
617 // Note: 'N' should be a fresh node because otherwise it shouldn't be
618 // a member of Deferred.
619 WList->enqueue(N, Block, Idx+1);
620 return;
621 }
622
623 ExplodedNode *Succ = makeNode(Loc, N->getState(), N);
624
625 if (Succ)
626 WList->enqueue(Succ, Block, Idx+1);
627}
628
629std::optional<unsigned>
630CoreEngine::getCompletedIterationCount(const CFGBlock *B,
631 ExplodedNode *Pred) const {
632 const StackFrame *SF = Pred->getStackFrame();
633 BlockCounter Counter = WList->getBlockCounter();
634 unsigned BlockCount = Counter.getNumVisited(SF, B->getBlockID());
635
636 const Stmt *Term = B->getTerminatorStmt();
638 assert(BlockCount >= 1 &&
639 "Block count of currently analyzed block must be >= 1");
640 return BlockCount - 1;
641 }
642 if (isa<DoStmt>(Term)) {
643 // In a do-while loop one iteration happens before the first evaluation of
644 // the loop condition, so we don't subtract one.
645 return BlockCount;
646 }
647 // ObjCForCollectionStmt is skipped intentionally because the current
648 // application of the iteration counts is not relevant for it.
649 return std::nullopt;
650}
651
653 for (const auto I : Set)
654 WList->enqueue(I);
655}
656
658 unsigned Idx) {
659 for (const auto I : Set)
660 enqueueStmtNode(I, Block, Idx);
661}
662
664 for (ExplodedNode *Node : Set) {
665 const StackFrame *SF = Node->getStackFrame();
666
667 // If we are in an inlined call, generate CallExitBegin node.
668 if (SF->getParent()) {
669 // Use the callee stack frame.
670 CallExitBegin Loc(SF, RS);
671 if (ExplodedNode *Succ = makeNode(Loc, Node->getState(), Node))
672 WList->enqueue(Succ);
673 } else {
674 // TODO: We should run remove dead bindings here.
675 G.addEndOfPath(Node);
676 NumPathsExplored++;
677 }
678 }
679}
680
682 ProgramStateRef State,
683 ExplodedNode *FromN, bool MarkAsSink) {
684 HasGeneratedNodes = true;
685 Frontier.erase(FromN);
686 ExplodedNode *N = C.getEngine().makeNode(Loc, State, FromN, MarkAsSink);
687
688 Frontier.insert(N);
689
690 return N;
691}
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
static std::unique_ptr< WorkList > generateWorkList(AnalyzerOptions &Opts)
ALWAYS_ENABLED_STATISTIC(NumReachedMaxSteps, "The # of times we reached the max number of steps.")
static std::string timeTraceScopeName(const ProgramPoint &Loc)
static llvm::TimeTraceMetadata timeTraceMetadata(const ExplodedNode *Pred, const ProgramPoint &Loc)
static Decl::Kind getKind(const Decl *D)
#define STAT_COUNTER(VARNAME, DESC)
Defines the clang::Expr interface and subclasses for C++ expressions.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
#define SM(sm)
SourceManager & getSourceManager()
Definition ASTContext.h:863
ASTContext & getASTContext() const
Stores options for the analyzer from the command line.
ExplorationStrategyKind getExplorationStrategy() const
const CFGBlock * getSrc() const
const CFGBlock * getDst() const
std::optional< CFGElement > getFirstElement() const
const CFGBlock * getBlock() const
Represents a single basic block in a source-level CFG.
Definition CFG.h:652
CFGElement back() const
Definition CFG.h:955
unsigned size() const
Definition CFG.h:999
succ_range succs()
Definition CFG.h:1047
bool empty() const
Definition CFG.h:1000
CFGTerminator getTerminator() const
Definition CFG.h:1132
succ_iterator succ_begin()
Definition CFG.h:1037
Stmt * getTerminatorStmt()
Definition CFG.h:1134
unsigned getBlockID() const
Definition CFG.h:1154
unsigned succ_size() const
Definition CFG.h:1055
Represents a top-level expression in a basic block.
Definition CFG.h:55
@ FullExprCleanup
Definition CFG.h:62
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type.
Definition CFG.h:103
std::optional< T > getAs() const
Convert to the specified CFGElement type, returning std::nullopt if this CFGElement is not of the des...
Definition CFG.h:113
const Stmt * getStmt() const
Definition CFG.h:143
bool isVirtualBaseBranch() const
Definition CFG.h:621
CFGBlock & getExit()
Definition CFG.h:1387
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
Definition CFG.h:1464
Represents a point when we begin processing an inlined call.
const CFGBlock * getEntry() const
Returns the entry block in the CFG for the entered function.
Represents a point when we start the call exit sequence (for inlined call).
Represents a point when we finish the call exit sequence (for inlined call).
This is a meta program point, which should be skipped by all the diagnostic reasoning etc.
Represents a point when the lifetime of an automatic object ends.
Represents a point when we exit a loop.
Represents a program point just after an implicit call event.
static StringRef getProgramPointKindName(Kind K)
ProgramPoint withTag(const ProgramPointTag *tag) const
Create a new ProgramPoint object that is the same as the original except for using the specified tag ...
const StackFrame * getStackFrame() const
std::optional< T > getAs() const
Convert to the specified ProgramPoint type, returning std::nullopt if this ProgramPoint is not of the...
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3170
It represents a stack frame of the call stack.
LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const
const Expr * getCallSite() const
const Decl * getDecl() const
const StackFrame * getParent() const
It might return null.
Stmt - This represents one statement.
Definition Stmt.h:86
An abstract data type used to count the number of times a given block has been visited along a path a...
unsigned getNumVisited(const StackFrame *CallSite, unsigned BlockID) const
CoreEngine(ExprEngine &exprengine, FunctionSummariesTy *FS, AnalyzerOptions &Opts)
Construct a CoreEngine object to analyze the provided CFG.
DataTag::Factory & getDataTags()
Definition CoreEngine.h:211
friend class ExprEngine
Definition CoreEngine.h:51
void enqueueStmtNode(ExplodedNode *N, const CFGBlock *Block, unsigned Idx)
Enqueue a single node created as a result of statement processing.
void dispatchWorkItem(ExplodedNode *Pred, ProgramPoint Loc, const WorkListUnit &WU)
Dispatch the work list item based on the given location information.
friend class NodeBuilder
Definition CoreEngine.h:52
void enqueueStmtNodes(ExplodedNodeSet &Set, const CFGBlock *Block, unsigned Idx)
Enqueue nodes that were created as a result of processing a statement onto the work list.
bool ExecuteWorkList(const StackFrame *SF, unsigned Steps, ProgramStateRef InitState)
ExecuteWorkList - Run the worklist algorithm for a maximum number of steps.
void enqueueEndOfFunction(ExplodedNodeSet &Set, const ReturnStmt *RS)
enqueue the nodes corresponding to the end of function onto the end of path / work list.
ExplodedNode * makeNode(const ProgramPoint &Loc, ProgramStateRef State, ExplodedNode *Pred, bool MarkAsSink=false) const
void enqueue(ExplodedNodeSet &Set)
Enqueue the given set of nodes onto the work list.
ExplodedNodeSet is a set of ExplodedNode * elements with the invariant that its elements cannot be nu...
const ProgramStateRef & getState() const
ProgramPoint getLocation() const
getLocation - Returns the edge associated with the given node.
void addPredecessor(ExplodedNode *V, ExplodedGraph &G)
addPredeccessor - Adds a predecessor to the current node, and in tandem add this node as a successor ...
ExplodedNode * getFirstPred()
const StackFrame * getStackFrame() const
void setCurrStackFrameAndBlock(const StackFrame *SF, const CFGBlock *B)
Definition ExprEngine.h:244
void markVisitedBasicBlock(unsigned ID, const Decl *D, unsigned TotalIDs)
const NodeBuilderContext & C
Definition CoreEngine.h:267
ExplodedNode * generateNode(const ProgramPoint &PP, ProgramStateRef State, ExplodedNode *Pred, bool MarkAsSink=false)
Generates a node in the ExplodedGraph.
ExplodedNodeSet & Frontier
The frontier set - a set of nodes which need to be propagated after the builder dies.
Definition CoreEngine.h:273
While alive, includes the current analysis stack in a crash trace.
SValKind getKind() const
Definition SVals.h:91
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
Definition SVals.h:87
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition SVals.h:83
ExplodedNode * getNode() const
Returns the node associated with the worklist unit.
Definition WorkList.h:48
unsigned getIndex() const
Return the index within the CFGBlock for the worklist unit.
Definition WorkList.h:57
const CFGBlock * getBlock() const
Returns the CFGblock associated with the worklist unit.
Definition WorkList.h:54
BlockCounter getBlockCounter() const
Returns the block counter map associated with the worklist unit.
Definition WorkList.h:51
static std::unique_ptr< WorkList > makeUnexploredFirstPriorityLocationQueue()
Definition WorkList.cpp:297
static std::unique_ptr< WorkList > makeUnexploredFirstPriorityQueue()
Definition WorkList.cpp:243
static std::unique_ptr< WorkList > makeBFSBlockDFSContents()
Definition WorkList.cpp:126
static std::unique_ptr< WorkList > makeBFS()
Definition WorkList.cpp:85
static std::unique_ptr< WorkList > makeDFS()
Definition WorkList.cpp:81
static std::unique_ptr< WorkList > makeUnexploredFirst()
Definition WorkList.cpp:187
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
Expr * Cond
};
U cast(CodeGen::Address addr)
Definition Address.h:327