clang 24.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 ExplodedNode *Processed = ExprEng.processCFGBlockEntrance(BE, Pred);
329
330 ExplodedNodeSet CheckerNodes;
331
332 if (Processed)
333 ExprEng.runCheckersForBlockEntrance(BE, Processed, CheckerNodes);
334
335 // Enqueue nodes onto the worklist.
336 enqueue(CheckerNodes);
337}
338
339void CoreEngine::HandleBlockEntrance(const BlockEntrance &L,
340 ExplodedNode *Pred) {
341 // Increment the block counter.
342 const StackFrame *SF = Pred->getStackFrame();
343 unsigned BlockId = L.getBlock()->getBlockID();
344 BlockCounter Counter = WList->getBlockCounter();
345 Counter = BCounterFactory.IncrementCount(Counter, SF, BlockId);
346 setBlockCounter(Counter);
347
348 // Process the entrance of the block.
349 if (std::optional<CFGElement> E = L.getFirstElement()) {
350 ExprEng.setCurrStackFrameAndBlock(Pred->getStackFrame(), L.getBlock());
351 ExprEng.processCFGElement(*E, Pred, 0);
352 } else
353 HandleBlockExit(L.getBlock(), Pred);
354}
355
356void CoreEngine::HandleBlockExit(const CFGBlock * B, ExplodedNode *Pred) {
357 if (const Stmt *Term = B->getTerminatorStmt()) {
358 ExprEng.setCurrStackFrameAndBlock(Pred->getStackFrame(), B);
359
360 switch (Term->getStmtClass()) {
361 default:
362 llvm_unreachable("Analysis for this terminator not implemented.");
363
364 case Stmt::CXXBindTemporaryExprClass:
365 HandleCleanupTemporaryBranch(
366 cast<CXXBindTemporaryExpr>(Term), B, Pred);
367 return;
368
369 // Model static initializers.
370 case Stmt::DeclStmtClass:
371 HandleStaticInit(cast<DeclStmt>(Term), B, Pred);
372 return;
373
374 case Stmt::BinaryOperatorClass: // '&&' and '||'
375 HandleBranch(cast<BinaryOperator>(Term)->getLHS(), Term, B, Pred);
376 return;
377
378 case Stmt::BinaryConditionalOperatorClass:
379 case Stmt::ConditionalOperatorClass:
380 HandleBranch(cast<AbstractConditionalOperator>(Term)->getCond(),
381 Term, B, Pred);
382 return;
383
384 // FIXME: Use constant-folding in CFG construction to simplify this
385 // case.
386
387 case Stmt::ChooseExprClass:
388 HandleBranch(cast<ChooseExpr>(Term)->getCond(), Term, B, Pred);
389 return;
390
391 case Stmt::CXXTryStmtClass:
392 // Generate a node for each of the successors.
393 // Our logic for EH analysis can certainly be improved.
394 for (const CFGBlock *Succ : B->succs()) {
395 if (Succ) {
396 BlockEdge BE(B, Succ, Pred->getStackFrame());
397 if (ExplodedNode *N = makeNode(BE, Pred->State, Pred))
398 WList->enqueue(N);
399 }
400 }
401 return;
402
403 case Stmt::DoStmtClass:
404 HandleBranch(cast<DoStmt>(Term)->getCond(), Term, B, Pred);
405 return;
406
407 case Stmt::CXXForRangeStmtClass:
408 HandleBranch(cast<CXXForRangeStmt>(Term)->getCond(), Term, B, Pred);
409 return;
410
411 case Stmt::ForStmtClass:
412 HandleBranch(cast<ForStmt>(Term)->getCond(), Term, B, Pred);
413 return;
414
415 case Stmt::SEHLeaveStmtClass:
416 case Stmt::ContinueStmtClass:
417 case Stmt::BreakStmtClass:
418 case Stmt::GotoStmtClass:
419 break;
420
421 case Stmt::IfStmtClass:
422 HandleBranch(cast<IfStmt>(Term)->getCond(), Term, B, Pred);
423 return;
424
425 case Stmt::IndirectGotoStmtClass: {
426 // Only 1 successor: the indirect goto dispatch block.
427 assert(B->succ_size() == 1);
428 ExplodedNodeSet Dst;
429 ExprEng.processIndirectGoto(Dst,
430 cast<IndirectGotoStmt>(Term)->getTarget(),
431 *(B->succ_begin()), Pred);
432 enqueue(Dst);
433 return;
434 }
435
436 case Stmt::ObjCForCollectionStmtClass:
437 // In the case of ObjCForCollectionStmt, it appears twice in a CFG:
438 //
439 // (1) inside a basic block, which represents the binding of the
440 // 'element' variable to a value.
441 // (2) in a terminator, which represents the branch.
442 //
443 // For (1), ExprEngine will bind a value (i.e., 0 or 1) indicating
444 // whether or not collection contains any more elements. We cannot
445 // just test to see if the element is nil because a container can
446 // contain nil elements.
447 HandleBranch(Term, Term, B, Pred);
448 return;
449
450 case Stmt::SwitchStmtClass: {
451 ExplodedNodeSet Dst;
452 ExprEng.processSwitch(cast<SwitchStmt>(Term), Pred, Dst);
453 // Enqueue the new frontier onto the worklist.
454 enqueue(Dst);
455 return;
456 }
457
458 case Stmt::WhileStmtClass:
459 HandleBranch(cast<WhileStmt>(Term)->getCond(), Term, B, Pred);
460 return;
461
462 case Stmt::GCCAsmStmtClass:
463 assert(cast<GCCAsmStmt>(Term)->isAsmGoto() && "Encountered GCCAsmStmt without labels");
464 // TODO: Handle jumping to labels
465 return;
466 }
467 }
468
470 HandleVirtualBaseBranch(B, Pred);
471 return;
472 }
473
474 assert(B->succ_size() == 1 &&
475 "Blocks with no terminator should have at most 1 successor.");
476
477 BlockEdge BE(B, *(B->succ_begin()), Pred->getStackFrame());
478 if (ExplodedNode *N = makeNode(BE, Pred->State, Pred))
479 WList->enqueue(N);
480}
481
482void CoreEngine::HandleCallEnter(const CallEnter &CE, ExplodedNode *Pred) {
483 ExprEng.setCurrStackFrameAndBlock(Pred->getStackFrame(), CE.getEntry());
484 ExprEng.processCallEnter(CE, Pred);
485}
486
487void CoreEngine::HandleBranch(const Stmt *Cond, const Stmt *Term,
488 const CFGBlock * B, ExplodedNode *Pred) {
489 assert(B->succ_size() == 2);
490 ExplodedNodeSet Dst;
491 ExprEng.processBranch(Cond, Pred, Dst, *(B->succ_begin()),
492 *(B->succ_begin() + 1),
493 getCompletedIterationCount(B, Pred));
494 // Enqueue the new frontier onto the worklist.
495 enqueue(Dst);
496}
497
498void CoreEngine::HandleCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE,
499 const CFGBlock *B,
500 ExplodedNode *Pred) {
501 assert(B->succ_size() == 2);
502 ExplodedNodeSet Dst;
503 ExprEng.processCleanupTemporaryBranch(BTE, Pred, Dst, *(B->succ_begin()),
504 *(B->succ_begin() + 1));
505 // Enqueue the new frontier onto the worklist.
506 enqueue(Dst);
507}
508
509void CoreEngine::HandleStaticInit(const DeclStmt *DS, const CFGBlock *B,
510 ExplodedNode *Pred) {
511 assert(B->succ_size() == 2);
512 ExplodedNodeSet Dst;
513 ExprEng.processStaticInitializer(DS, Pred, Dst, *(B->succ_begin()),
514 *(B->succ_begin() + 1));
515 // Enqueue the new frontier onto the worklist.
516 enqueue(Dst);
517}
518
519void CoreEngine::HandlePostStmt(const CFGBlock *B, unsigned StmtIdx,
520 ExplodedNode *Pred) {
521 assert(B);
522 assert(!B->empty());
523
524 // We no-op by skipping any FullExprCleanup
525 while (StmtIdx < B->size() &&
526 (*B)[StmtIdx].getKind() == CFGElement::FullExprCleanup) {
527 StmtIdx++;
528 }
529
530 if (StmtIdx == B->size())
531 HandleBlockExit(B, Pred);
532 else {
533 ExprEng.setCurrStackFrameAndBlock(Pred->getStackFrame(), B);
534 ExprEng.processCFGElement((*B)[StmtIdx], Pred, StmtIdx);
535 }
536}
537
538void CoreEngine::HandleVirtualBaseBranch(const CFGBlock *B,
539 ExplodedNode *Pred) {
540 const StackFrame *SF = Pred->getStackFrame();
541 if (const auto *CallerCtor =
542 dyn_cast_or_null<CXXConstructExpr>(SF->getCallSite())) {
543 switch (CallerCtor->getConstructionKind()) {
546 BlockEdge Loc(B, *B->succ_begin(), SF);
547 HandleBlockEdge(Loc, Pred);
548 return;
549 }
550 default:
551 break;
552 }
553 }
554
555 // We either don't see a parent stack frame because we're in the top frame,
556 // or the parent stack frame doesn't initialize our virtual bases.
557 BlockEdge Loc(B, *(B->succ_begin() + 1), SF);
558 HandleBlockEdge(Loc, Pred);
559}
560
562 ProgramStateRef State, ExplodedNode *Pred,
563 bool MarkAsSink) const {
564 MarkAsSink = MarkAsSink || State->isPosteriorlyOverconstrained();
565
566 bool IsNew;
567 ExplodedNode *N = G.getNode(Loc, State, MarkAsSink, &IsNew);
568 N->addPredecessor(Pred, G);
569
570 return IsNew ? N : nullptr;
571}
572
574 const CFGBlock *Block, unsigned Idx) {
575 assert(Block);
576 assert(!N->isSink());
577
578 // Check if this node entered a callee.
579 if (N->getLocation().getAs<CallEnter>()) {
580 // Still use the index of the CallExpr. It's needed to create the callee
581 // StackFrame.
582 WList->enqueue(N, Block, Idx);
583 return;
584 }
585
586 // Do not create extra nodes. Move to the next CFG element.
587 if (N->getLocation().getAs<PostInitializer>() ||
589 N->getLocation().getAs<LoopExit>() ||
590 N->getLocation().getAs<LifetimeEnd>()) {
591 WList->enqueue(N, Block, Idx + 1);
592 return;
593 }
594
595 if (N->getLocation().getAs<EpsilonPoint>()) {
596 WList->enqueue(N, Block, Idx);
597 return;
598 }
599
600 if ((*Block)[Idx].getKind() == CFGElement::NewAllocator) {
601 WList->enqueue(N, Block, Idx+1);
602 return;
603 }
604
605 // At this point, we know we're processing a normal statement.
606 CFGStmt CS = (*Block)[Idx].castAs<CFGStmt>();
607 PostStmt Loc(CS.getStmt(), N->getStackFrame());
608
609 if (Loc == N->getLocation().withTag(nullptr)) {
610 // Note: 'N' should be a fresh node because otherwise it shouldn't be
611 // a member of Deferred.
612 WList->enqueue(N, Block, Idx+1);
613 return;
614 }
615
616 ExplodedNode *Succ = makeNode(Loc, N->getState(), N);
617
618 if (Succ)
619 WList->enqueue(Succ, Block, Idx+1);
620}
621
622std::optional<unsigned>
623CoreEngine::getCompletedIterationCount(const CFGBlock *B,
624 ExplodedNode *Pred) const {
625 const StackFrame *SF = Pred->getStackFrame();
626 BlockCounter Counter = WList->getBlockCounter();
627 unsigned BlockCount = Counter.getNumVisited(SF, B->getBlockID());
628
629 const Stmt *Term = B->getTerminatorStmt();
631 assert(BlockCount >= 1 &&
632 "Block count of currently analyzed block must be >= 1");
633 return BlockCount - 1;
634 }
635 if (isa<DoStmt>(Term)) {
636 // In a do-while loop one iteration happens before the first evaluation of
637 // the loop condition, so we don't subtract one.
638 return BlockCount;
639 }
640 // ObjCForCollectionStmt is skipped intentionally because the current
641 // application of the iteration counts is not relevant for it.
642 return std::nullopt;
643}
644
646 for (const auto I : Set)
647 WList->enqueue(I);
648}
649
651 unsigned Idx) {
652 for (const auto I : Set)
653 enqueueStmtNode(I, Block, Idx);
654}
655
657 for (ExplodedNode *Node : Set) {
658 const StackFrame *SF = Node->getStackFrame();
659
660 // If we are in an inlined call, generate CallExitBegin node.
661 if (SF->getParent()) {
662 // Use the callee stack frame.
663 CallExitBegin Loc(SF, RS);
664 if (ExplodedNode *Succ = makeNode(Loc, Node->getState(), Node))
665 WList->enqueue(Succ);
666 } else {
667 // TODO: We should run remove dead bindings here.
668 G.addEndOfPath(Node);
669 NumPathsExplored++;
670 }
671 }
672}
673
675 ProgramStateRef State,
676 ExplodedNode *FromN, bool MarkAsSink) {
677 Frontier.erase(FromN);
678 ExplodedNode *N = C.getEngine().makeNode(Loc, State, FromN, MarkAsSink);
679
680 Frontier.insert(N);
681
682 return N;
683}
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.
SourceManager & getSourceManager()
Definition ASTContext.h:885
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:3172
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:85
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.
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:271
While alive, includes the current analysis stack in a crash trace.
SValKind getKind() const
Definition SVals.h:92
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:88
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition SVals.h:84
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
Top level wrappers for InstallAPI frontend operations.
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