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