clang 23.0.0git
ExprEngine.h
Go to the documentation of this file.
1//===- ExprEngine.h - Path-Sensitive Expression-Level Dataflow --*- C++ -*-===//
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 meta-engine for path-sensitive dataflow analysis that
10// is built on CoreEngine, but provides the boilerplate to execute transfer
11// functions and build the ExplodedGraph at the expression level.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_EXPRENGINE_H
16#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_EXPRENGINE_H
17
18#include "clang/AST/Expr.h"
19#include "clang/AST/Type.h"
20#include "clang/Analysis/CFG.h"
23#include "clang/Basic/LLVM.h"
37#include "llvm/ADT/ArrayRef.h"
38#include <cassert>
39#include <optional>
40#include <utility>
41
42namespace clang {
43
45class AnalyzerOptions;
46class ASTContext;
47class CFGBlock;
48class CFGElement;
51class CXXCatchStmt;
53class CXXDeleteExpr;
54class CXXNewExpr;
55class CXXThisExpr;
56class Decl;
57class DeclStmt;
58class GCCAsmStmt;
59class LambdaExpr;
61class MSAsmStmt;
62class NamedDecl;
65class ObjCIvarRefExpr;
66class ObjCMessageExpr;
67class ReturnStmt;
68class Stmt;
69
70namespace cross_tu {
71
73
74} // namespace cross_tu
75
76namespace ento {
77
78class AnalysisManager;
80class CallEvent;
81class CheckerManager;
83class ExplodedNodeSet;
84class ExplodedNode;
85class MemRegion;
87class ProgramState;
90class SymbolManager;
91
92/// Hints for figuring out if a call should be inlined during evalCall().
94 /// This call is a constructor or a destructor for which we do not currently
95 /// compute the this-region correctly.
97
98 /// This call is a constructor or a destructor for a single element within
99 /// an array, a part of array construction or destruction.
100 bool IsArrayCtorOrDtor = false;
101
102 /// This call is a constructor or a destructor of a temporary value.
104
105 /// This call is a constructor for a temporary that is lifetime-extended
106 /// by binding it to a reference-type field within an aggregate,
107 /// for example 'A { const C &c; }; A a = { C() };'
109
110 /// This call is a pre-C++17 elidable constructor that we failed to elide
111 /// because we failed to compute the target region into which
112 /// this constructor would have been ultimately elided. Analysis that
113 /// we perform in this case is still correct but it behaves differently,
114 /// as if copy elision is disabled.
116
118};
119
121 void anchor();
122
123public:
124 /// The modes of inlining, which override the default analysis-wide settings.
126 /// Follow the default settings for inlining callees.
128
129 /// Do minimal inlining of callees.
131 };
132
133private:
135 bool IsCTUEnabled;
136
137 AnalysisManager &AMgr;
138
139 AnalysisDeclContextManager &AnalysisDeclContexts;
140
141 CoreEngine Engine;
142
143 /// G - the simulation graph.
144 ExplodedGraph &G;
145
146 /// StateMgr - Object that manages the data for all created states.
147 ProgramStateManager StateMgr;
148
149 /// SymMgr - Object that manages the symbol information.
150 SymbolManager &SymMgr;
151
152 /// MRMgr - MemRegionManager object that creates memory regions.
153 MemRegionManager &MRMgr;
154
155 /// svalBuilder - SValBuilder object that creates SVals from expressions.
156 SValBuilder &svalBuilder;
157
158 unsigned int currStmtIdx = 0;
159
160 /// Pointer to a (so-called, somewhat misnamed) NodeBuilderContext object
161 /// which has three independent roles:
162 /// - It holds a pointer to the CFGBlock that is currently under analysis.
163 /// (This is the primary way to get the current block.)
164 /// - It holds a pointer to the current StackFrame. (This is rarely
165 /// used, the stack frame is usually queried from a recent
166 /// ExplodedNode. Unfortunately it seems that these two sources of truth
167 /// are not always consistent.)
168 /// - It can be used for constructing `NodeBuilder`s. Practically all
169 /// `NodeBuilder` objects are useless complications in the code, so I
170 /// intend to replace them with direct use of `CoreEngine::makeNode`.
171 /// TODO: Eventually `currBldrCtx` should be replaced by two separate fields:
172 /// `const CFGBlock *CurrBlock` & `const StackFrame *CurrStackFrame`
173 /// that are kept up-to-date and are almost always non-null during the
174 /// analysis. I will switch to this more natural representation when
175 /// `NodeBuilder`s are eliminated from the code.
176 const NodeBuilderContext *currBldrCtx = nullptr;
177 /// Historically `currBldrCtx` pointed to a local variable in some stack
178 /// frame. This field is introduced as a temporary measure to allow a gradual
179 /// transition. Only use this in {re,}setCurrStackFrameAndBlock!
180 /// TODO: Remove this temporary hack.
181 std::optional<NodeBuilderContext> OwnedCurrBldrCtx;
182
183 /// Helper object to determine if an Objective-C message expression
184 /// implicitly never returns.
185 ObjCNoReturn ObjCNoRet;
186
187 /// The BugReporter associated with this engine. It is important that
188 /// this object be placed at the very end of member variables so that its
189 /// destructor is called before the rest of the ExprEngine is destroyed.
191
192 /// The functions which have been analyzed through inlining. This is owned by
193 /// AnalysisConsumer. It can be null.
194 SetOfConstDecls *VisitedCallees;
195
196 /// The flag, which specifies the mode of inlining for the engine.
197 InliningModes HowToInline;
198
199public:
201 SetOfConstDecls *VisitedCalleesIn,
202 FunctionSummariesTy *FS, InliningModes HowToInlineIn);
203
204 virtual ~ExprEngine() = default;
205
206 /// Returns true if there is still simulation state on the worklist.
207 bool ExecuteWorkList(const StackFrame *SF, unsigned Steps = 150000) {
208 assert(SF->inTopFrame());
209 BR.setAnalysisEntryPoint(SF->getDecl());
210 return Engine.ExecuteWorkList(SF, Steps, nullptr);
211 }
212
213 /// getContext - Return the ASTContext associated with this analysis.
214 ASTContext &getContext() const { return AMgr.getASTContext(); }
215
217 const AnalysisManager &getAnalysisManager() const { return AMgr; }
218
220 return AMgr.getAnalysisDeclContextManager();
221 }
222
224 return *AMgr.getCheckerManager();
225 }
226
227 SValBuilder &getSValBuilder() { return svalBuilder; }
228 const SValBuilder &getSValBuilder() const { return svalBuilder; }
229
230 BugReporter &getBugReporter() { return BR; }
231 const BugReporter &getBugReporter() const { return BR; }
232
235 return &CTU;
236 }
237
238 // FIXME: Ideally the body of this method should look like
239 // CurrStackFrame = SF;
240 // CurrBlock = B;
241 // where CurrStackFrame and CurrBlock are new member variables that
242 // fulfill the roles of `currBldrCtx` in a more natural way.
243 // This implementation is a temporary measure to allow a gradual transition.
245 // The current StackFrame and Block is reset at the beginning of
246 // dispatchWorkItem. Ideally, this method should be called only once per
247 // dispatchWorkItem call (= elementary analysis step); so the following
248 // assertion is there to catch accidental repeated calls. If the current
249 // StackFrame and Block needs to change in the middle of a single step
250 // (which currently happens only once, in processCallExit), use an explicit
251 // call to resetCurrStackFrameAndBlock.
252 assert(!currBldrCtx && !OwnedCurrBldrCtx &&
253 "The current StackFrame and Block is already set");
254 OwnedCurrBldrCtx.emplace(Engine, B, SF);
255 currBldrCtx = &*OwnedCurrBldrCtx;
256 }
257
259 currBldrCtx = nullptr;
260 OwnedCurrBldrCtx = std::nullopt;
261 }
262
264 assert(currBldrCtx);
265 return *currBldrCtx;
266 }
267
269 assert(G.getRoot());
270 return G.getRoot()->getLocation().getStackFrame();
271 }
272
273 /// Get the 'current' stack frame corresponding to the current work item
274 /// (elementary analysis step handled by `dispatchWorkItem`).
275 /// FIXME: This sometimes (e.g. in some `BeginFunction` callbacks) differs
276 /// from the `StackFrame` that can be obtained from different sources
277 /// (e.g. a recent `ExplodedNode`). Traditionally this stack frame is
278 /// only used for block count calculations (`getNumVisited`); it is probably
279 /// wise to follow this tradition until the discrepancies are resolved.
281 return currBldrCtx ? currBldrCtx->getStackFrame() : nullptr;
282 }
283
284 /// Get the 'current' CFGBlock corresponding to the current work item
285 /// (elementary analysis step handled by `dispatchWorkItem`).
286 const CFGBlock *getCurrBlock() const {
287 return currBldrCtx ? currBldrCtx->getBlock() : nullptr;
288 }
289
291 return {getCurrBlock(), currStmtIdx};
292 }
293
294 unsigned getNumVisited(const StackFrame *SF, const CFGBlock *Block) const {
295 return Engine.WList->getBlockCounter().getNumVisited(SF,
296 Block->getBlockID());
297 }
298
299 unsigned getNumVisitedCurrent() const {
301 }
302
303 /// Dump graph to the specified filename.
304 /// If filename is empty, generate a temporary one.
305 /// \return The filename the graph is written into.
306 std::string DumpGraph(bool trim = false, StringRef Filename="");
307
308 /// Dump the graph consisting of the given nodes to a specified filename.
309 /// Generate a temporary filename if it's not provided.
310 /// \return The filename the graph is written into.
312 StringRef Filename = "");
313
314 /// Visualize the ExplodedGraph created by executing the simulation.
315 void ViewGraph(bool trim = false);
316
317 /// Visualize a trimmed ExplodedGraph that only contains paths to the given
318 /// nodes.
320
321 /// getInitialState - Return the initial state used for the root vertex
322 /// in the ExplodedGraph.
324
325 ExplodedGraph &getGraph() { return G; }
326 const ExplodedGraph &getGraph() const { return G; }
327
328 /// Run the analyzer's garbage collection - remove dead symbols and
329 /// bindings from the state.
330 ///
331 /// Checkers can participate in this process with two callbacks:
332 /// \c checkLiveSymbols and \c checkDeadSymbols. See the CheckerDocumentation
333 /// class for more information.
334 ///
335 /// \param Node The predecessor node, from which the processing should start.
336 /// \param Out The returned set of output nodes.
337 /// \param ReferenceStmt The statement which is about to be processed.
338 /// Everything needed for this statement should be considered live.
339 /// A null statement means that everything in child StackFrames
340 /// is dead.
341 /// \param SF The stack frame of the \p ReferenceStmt. A null stack frame
342 /// means that we have reached the end of analysis and that
343 /// all statements and local variables should be considered dead.
344 /// \param DiagnosticStmt Used as a location for any warnings that should
345 /// occur while removing the dead (e.g. leaks). By default, the
346 /// \p ReferenceStmt is used.
347 /// \param K Denotes whether this is a pre- or post-statement purge. This
348 /// must only be ProgramPoint::PostStmtPurgeDeadSymbolsKind if an
349 /// entire stack frame is being cleared, in which case the
350 /// \p ReferenceStmt must either be a ReturnStmt or \c NULL. Otherwise,
351 /// it must be ProgramPoint::PreStmtPurgeDeadSymbolsKind (the default)
352 /// and \p ReferenceStmt must be valid (non-null).
353 void
355 const Stmt *ReferenceStmt, const StackFrame *SF,
356 const Stmt *DiagnosticStmt = nullptr,
358
359 /// A tag to track convenience transitions, which can be removed at cleanup.
360 /// This tag applies to a node created after removeDead.
361 static const ProgramPointTag *cleanupNodeTag();
362
363 /// processCFGElement - Called by CoreEngine. Used to generate new successor
364 /// nodes by processing the 'effects' of a CFG element.
365 void processCFGElement(const CFGElement E, ExplodedNode *Pred,
366 unsigned StmtIdx);
367
368 void ProcessStmt(const Stmt *S, ExplodedNode *Pred);
369
370 void ProcessLoopExit(const Stmt* S, ExplodedNode *Pred);
371 void ProcessLifetimeEnd(const Stmt *S, const VarDecl *D, ExplodedNode *Pred);
372
374
376
377 void ProcessNewAllocator(const CXXNewExpr *NE, ExplodedNode *Pred);
378
380 ExplodedNode *Pred, ExplodedNodeSet &Dst);
381 void ProcessDeleteDtor(const CFGDeleteDtor D,
382 ExplodedNode *Pred, ExplodedNodeSet &Dst);
383 void ProcessBaseDtor(const CFGBaseDtor D,
384 ExplodedNode *Pred, ExplodedNodeSet &Dst);
385 void ProcessMemberDtor(const CFGMemberDtor D,
386 ExplodedNode *Pred, ExplodedNodeSet &Dst);
388 ExplodedNode *Pred, ExplodedNodeSet &Dst);
389
390 /// Called by CoreEngine when processing the entrance of a CFGBlock.
391 void processCFGBlockEntrance(const BlockEdge &L, const BlockEntrance &BE,
392 NodeBuilder &Builder, ExplodedNode *Pred);
393
394 void runCheckersForBlockEntrance(const BlockEntrance &Entrance,
395 ExplodedNode *Pred, ExplodedNodeSet &Dst);
396
397 /// ProcessBranch - Called by CoreEngine. Used to generate successor nodes by
398 /// processing the 'effects' of a branch condition. If the branch condition
399 /// is a loop condition, IterationsCompletedInLoop is the number of completed
400 /// iterations (otherwise it's std::nullopt).
401 void processBranch(const Stmt *Condition, ExplodedNode *Pred,
402 ExplodedNodeSet &Dst, const CFGBlock *DstT,
403 const CFGBlock *DstF,
404 std::optional<unsigned> IterationsCompletedInLoop);
405
406 /// Called by CoreEngine.
407 /// Used to generate successor nodes for temporary destructors depending
408 /// on whether the corresponding constructor was visited.
410 ExplodedNode *Pred, ExplodedNodeSet &Dst,
411 const CFGBlock *DstT,
412 const CFGBlock *DstF);
413
414 /// Called by CoreEngine. Used to processing branching behavior
415 /// at static initializers.
417 ExplodedNodeSet &Dst, const CFGBlock *DstT,
418 const CFGBlock *DstF);
419
420 /// processIndirectGoto - Called by CoreEngine. Used to generate successor
421 /// nodes by processing the 'effects' of a computed goto jump.
422 void processIndirectGoto(ExplodedNodeSet &Dst, const Expr *Tgt,
423 const CFGBlock *Dispatch, ExplodedNode *Pred);
424
425 /// ProcessSwitch - Called by CoreEngine. Used to generate successor
426 /// nodes by processing the 'effects' of a switch statement.
427 void processSwitch(const SwitchStmt *Switch, ExplodedNode *Pred,
428 ExplodedNodeSet &Dst);
429
430 /// Called by CoreEngine. Used to notify checkers that processing a
431 /// function has begun. Called for both inlined and top-level functions.
433 const BlockEdge &L);
434
435 /// Called by CoreEngine. Used to notify checkers that processing a
436 /// function has ended. Called for both inlined and top-level functions.
437 void processEndOfFunction(ExplodedNode *Pred, const ReturnStmt *RS = nullptr);
438
439 /// Remove dead bindings/symbols before exiting a function.
441
442 /// Generate the entry node of the callee.
444
445 /// Generate the sequence of nodes that simulate the call exit and the post
446 /// visit for CallExpr.
447 void processCallExit(ExplodedNode *Pred);
448
449 /// Called by CoreEngine when the analysis worklist has terminated.
450 void processEndWorklist();
451
452 /// evalAssume - Callback function invoked by the ConstraintManager when
453 /// making assumptions about state values.
455 bool assumption);
456
457 /// processRegionChanges - Called by ProgramStateManager whenever a change is made
458 /// to the store. Used to update checkers that track region values.
461 const InvalidatedSymbols *invalidated,
462 ArrayRef<const MemRegion *> ExplicitRegions,
464 const StackFrame *SF, const CallEvent *Call);
465
467 const MemRegion *MR,
468 const StackFrame *SF) {
469 return processRegionChanges(state, nullptr, MR, MR, SF, nullptr);
470 }
471
472 /// printJson - Called by ProgramStateManager to print checker-specific data.
473 void printJson(raw_ostream &Out, ProgramStateRef State, const StackFrame *SF,
474 const char *NL, unsigned int Space, bool IsDot) const;
475
476 ProgramStateManager &getStateManager() { return StateMgr; }
477 const ProgramStateManager &getStateManager() const { return StateMgr; }
478
479 StoreManager &getStoreManager() { return StateMgr.getStoreManager(); }
481 return StateMgr.getStoreManager();
482 }
483
485 return StateMgr.getConstraintManager();
486 }
488 return StateMgr.getConstraintManager();
489 }
490
491 // FIXME: Remove when we migrate over to just using SValBuilder.
493 return StateMgr.getBasicVals();
494 }
495
496 SymbolManager &getSymbolManager() { return SymMgr; }
497 const SymbolManager &getSymbolManager() const { return SymMgr; }
499
500 DataTag::Factory &getDataTags() { return Engine.getDataTags(); }
501
502 // Functions for external checking of whether we have unfinished work.
503 bool wasBlocksExhausted() const { return Engine.wasBlocksExhausted(); }
504 bool hasEmptyWorkList() const { return !Engine.getWorkList()->hasWork(); }
505 bool hasWorkRemaining() const { return Engine.hasWorkRemaining(); }
506
507 const CoreEngine &getCoreEngine() const { return Engine; }
508
509public:
510 /// Visit - Transfer function logic for all statements. Dispatches to
511 /// other functions that handle specific kinds of statements.
512 void Visit(const Stmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst);
513
514 /// VisitArrayInitLoopExpr - Transfer function for array init loop.
516 ExplodedNodeSet &Dst);
517
518 /// VisitArraySubscriptExpr - Transfer function for array accesses.
520 ExplodedNode *Pred,
521 ExplodedNodeSet &Dst);
522
523 /// VisitGCCAsmStmt - Transfer function logic for inline asm.
524 void VisitGCCAsmStmt(const GCCAsmStmt *A, ExplodedNode *Pred,
525 ExplodedNodeSet &Dst);
526
527 /// VisitMSAsmStmt - Transfer function logic for MS inline asm.
528 void VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred,
529 ExplodedNodeSet &Dst);
530
531 /// VisitBlockExpr - Transfer function logic for BlockExprs.
532 void VisitBlockExpr(const BlockExpr *BE, ExplodedNode *Pred,
533 ExplodedNodeSet &Dst);
534
535 /// VisitLambdaExpr - Transfer function logic for LambdaExprs.
536 void VisitLambdaExpr(const LambdaExpr *LE, ExplodedNode *Pred,
537 ExplodedNodeSet &Dst);
538
539 /// VisitBinaryOperator - Transfer function logic for binary operators.
541 ExplodedNodeSet &Dst);
542
543
544 /// VisitCall - Transfer function for function calls.
545 void VisitCallExpr(const CallExpr *CE, ExplodedNode *Pred,
546 ExplodedNodeSet &Dst);
547
548 /// VisitCast - Transfer function logic for all casts (implicit and explicit).
549 void VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNode *Pred,
550 ExplodedNodeSet &Dst);
551
552 /// VisitCompoundLiteralExpr - Transfer function logic for compound literals.
554 ExplodedNode *Pred, ExplodedNodeSet &Dst);
555
556 /// Transfer function logic for DeclRefExprs and BlockDeclRefExprs.
557 void VisitCommonDeclRefExpr(const Expr *DR, const NamedDecl *D,
558 ExplodedNode *Pred, ExplodedNodeSet &Dst);
559
560 /// VisitDeclStmt - Transfer function logic for DeclStmts.
561 void VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred,
562 ExplodedNodeSet &Dst);
563
564 /// VisitGuardedExpr - Transfer function logic for ?, __builtin_choose
565 void VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R,
566 ExplodedNode *Pred, ExplodedNodeSet &Dst);
567
568 /// VisitAttributedStmt - Transfer function logic for AttributedStmt.
570 ExplodedNodeSet &Dst);
571
572 /// VisitLogicalExpr - Transfer function logic for '&&', '||'.
573 void VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
574 ExplodedNodeSet &Dst);
575
576 /// VisitMemberExpr - Transfer function for member expressions.
577 void VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred,
578 ExplodedNodeSet &Dst);
579
580 /// VisitAtomicExpr - Transfer function for builtin atomic expressions.
581 void VisitAtomicExpr(const AtomicExpr *E, ExplodedNode *Pred,
582 ExplodedNodeSet &Dst);
583
584 /// Transfer function logic for ObjCAtSynchronizedStmts.
586 ExplodedNode *Pred, ExplodedNodeSet &Dst);
587
588 /// Transfer function logic for computing the lvalue of an Objective-C ivar.
590 ExplodedNodeSet &Dst);
591
592 /// VisitObjCForCollectionStmt - Transfer function logic for
593 /// ObjCForCollectionStmt.
595 ExplodedNode *Pred, ExplodedNodeSet &Dst);
596
597 void VisitObjCMessage(const ObjCMessageExpr *ME, ExplodedNode *Pred,
598 ExplodedNodeSet &Dst);
599
600 /// VisitReturnStmt - Transfer function logic for return statements.
601 void VisitReturnStmt(const ReturnStmt *R, ExplodedNode *Pred,
602 ExplodedNodeSet &Dst);
603
604 /// VisitOffsetOfExpr - Transfer function for offsetof.
605 void VisitOffsetOfExpr(const OffsetOfExpr *Ex, ExplodedNode *Pred,
606 ExplodedNodeSet &Dst);
607
608 /// VisitUnaryExprOrTypeTraitExpr - Transfer function for sizeof.
610 ExplodedNode *Pred, ExplodedNodeSet &Dst);
611
612 /// VisitUnaryOperator - Transfer function logic for unary operators.
613 void VisitUnaryOperator(const UnaryOperator* B, ExplodedNode *Pred,
614 ExplodedNodeSet &Dst);
615
616 /// Handle ++ and -- (both pre- and post-increment).
618 ExplodedNode *Pred,
619 ExplodedNodeSet &Dst);
620
622 ExplodedNodeSet &PreVisit,
623 ExplodedNodeSet &Dst);
624
625 void VisitCXXCatchStmt(const CXXCatchStmt *CS, ExplodedNode *Pred,
626 ExplodedNodeSet &Dst);
627
628 void VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred,
629 ExplodedNodeSet & Dst);
630
632 ExplodedNodeSet &Dst);
633
635 ExplodedNode *Pred, ExplodedNodeSet &Dst);
636
637 void VisitCXXDestructor(QualType ObjectType, const MemRegion *Dest,
638 const Stmt *S, bool IsBaseDtor,
639 ExplodedNode *Pred, ExplodedNodeSet &Dst,
640 EvalCallOptions &Options);
641
642 void VisitCXXNewAllocatorCall(const CXXNewExpr *CNE,
643 ExplodedNode *Pred,
644 ExplodedNodeSet &Dst);
645
646 void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
647 ExplodedNodeSet &Dst);
648
650 ExplodedNodeSet &Dst);
651
652 /// Create a C++ temporary object for an rvalue.
654 ExplodedNode *Pred,
655 ExplodedNodeSet &Dst);
656
657 void ConstructInitList(const Expr *Source, ArrayRef<Expr *> Args,
658 bool IsTransparent, ExplodedNode *Pred,
659 ExplodedNodeSet &Dst);
660
661 /// evalEagerlyAssumeBifurcation - Given the nodes in 'Src', eagerly assume
662 /// concrete boolean values for 'Ex', storing the resulting nodes in 'Dst'.
664 const Expr *Ex);
665
666 bool didEagerlyAssumeBifurcateAt(ProgramStateRef State, const Expr *Ex) const;
667
668 static std::pair<const ProgramPointTag *, const ProgramPointTag *>
670
672 const StackFrame *SF, QualType T,
673 QualType ExTy, const CastExpr *CastE,
674 NodeBuilder &Bldr, ExplodedNode *Pred);
675
677 NodeBuilder &Bldr);
678
679public:
681 SVal LHS, SVal RHS, QualType T) {
682 return svalBuilder.evalBinOp(ST, Op, LHS, RHS, T);
683 }
684
685 /// Retrieves which element is being constructed in a non-POD type array.
686 static std::optional<unsigned>
688 const StackFrame *SF);
689
690 /// Retrieves which element is being destructed in a non-POD type array.
691 static std::optional<unsigned>
693
694 /// Retrieves the size of the array in the pending ArrayInitLoopExpr.
695 static std::optional<unsigned> getPendingInitLoop(ProgramStateRef State,
696 const CXXConstructExpr *E,
697 const StackFrame *SF);
698
699 /// By looking at a certain item that may be potentially part of an object's
700 /// ConstructionContext, retrieve such object's location. A particular
701 /// statement can be transparently passed as \p Item in most cases.
702 static std::optional<SVal>
704 const ConstructionContextItem &Item,
705 const StackFrame *SF);
706
707 /// Call PointerEscape callback when a value escapes as a result of bind.
709 ProgramStateRef State, ArrayRef<std::pair<SVal, SVal>> LocAndVals,
710 const StackFrame *SF, PointerEscapeKind Kind, const CallEvent *Call);
711
712 /// Call PointerEscape callback when a value escapes as a result of
713 /// region invalidation.
714 /// \param[in] ITraits Specifies invalidation traits for regions/symbols.
716 ProgramStateRef State,
717 const InvalidatedSymbols *Invalidated,
718 ArrayRef<const MemRegion *> ExplicitRegions,
719 const CallEvent *Call,
721
722private:
723 /// evalBind - Handle the semantics of binding a value to a specific location.
724 /// This method is used by evalStore, VisitDeclStmt, and others.
725 void evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE, ExplodedNode *Pred,
726 SVal location, SVal Val, bool AtDeclInit = false,
727 const ProgramPoint *PP = nullptr);
728
730 SVal Val, const StackFrame *SF);
731
732public:
733 /// A simple wrapper when you only need to notify checkers of pointer-escape
734 /// of some values.
737 const CallEvent *Call = nullptr) const;
738
739 // FIXME: 'tag' should be removed, and a StackFrame should be used
740 // instead.
741 // FIXME: Comment on the meaning of the arguments, when 'St' may not
742 // be the same as Pred->state, and when 'location' may not be the
743 // same as state->getLValue(Ex).
744 /// Simulate a read of the result of Ex.
745 void evalLoad(ExplodedNodeSet &Dst,
746 const Expr *NodeEx, /* Eventually will be a CFGStmt */
747 const Expr *BoundExpr,
748 ExplodedNode *Pred,
750 SVal location,
751 const ProgramPointTag *tag = nullptr,
752 QualType LoadTy = QualType());
753
754 // FIXME: 'tag' should be removed, and a StackFrame should be used
755 // instead.
756 void evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, const Expr *StoreE,
757 ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val,
758 const ProgramPointTag *tag = nullptr);
759
760 /// Return the CFG element corresponding to the worklist element
761 /// that is currently being processed by ExprEngine.
762 CFGElement getCurrentCFGElement() { return (*getCurrBlock())[currStmtIdx]; }
763
764 /// Create a new state in which the call return value is binded to the
765 /// call origin expression.
767 ProgramStateRef State);
768
769 /// Evaluate a call, running pre- and post-call checkers and allowing checkers
770 /// to be responsible for handling the evaluation of the call itself.
771 void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred,
772 const CallEvent &Call);
773
774 /// Default implementation of call evaluation.
776 const CallEvent &Call,
777 const EvalCallOptions &CallOpts = {});
778
779 /// Find location of the object that is being constructed by a given
780 /// constructor. This should ideally always succeed but due to not being
781 /// fully implemented it sometimes indicates that it failed via its
782 /// out-parameter CallOpts; in such cases a fake temporary region is
783 /// returned, which is better than nothing but does not represent
784 /// the actual behavior of the program. The Idx parameter is used if we
785 /// construct an array of objects. In that case it points to the index
786 /// of the continuous memory region.
787 /// E.g.:
788 /// For `int arr[4]` this index can be 0,1,2,3.
789 /// For `int arr2[3][3]` this index can be 0,1,...,7,8.
790 /// A multi-dimensional array is also a continuous memory location in a
791 /// row major order, so for arr[0][0] Idx is 0 and for arr[3][3] Idx is 8.
793 unsigned NumVisitedCaller,
794 const StackFrame *SF,
795 const ConstructionContext *CC,
796 EvalCallOptions &CallOpts,
797 unsigned Idx = 0);
798
799 /// Update the program state with all the path-sensitive information
800 /// that's necessary to perform construction of an object with a given
801 /// syntactic construction context. V and CallOpts have to be obtained from
802 /// computeObjectUnderConstruction() invoked with the same set of
803 /// the remaining arguments (E, State, SF, CC).
805 SVal V, const Expr *E, ProgramStateRef State, const StackFrame *SF,
806 const ConstructionContext *CC, const EvalCallOptions &CallOpts);
807
808 /// A convenient wrapper around computeObjectUnderConstruction
809 /// and updateObjectsUnderConstruction.
810 std::pair<ProgramStateRef, SVal>
812 const NodeBuilderContext *BldrCtx,
813 const StackFrame *SF, const ConstructionContext *CC,
814 EvalCallOptions &CallOpts, unsigned Idx = 0) {
815
816 SVal V = computeObjectUnderConstruction(E, State, BldrCtx->blockCount(), SF,
817 CC, CallOpts, Idx);
818 State = updateObjectsUnderConstruction(V, E, State, SF, CC, CallOpts);
819
820 return std::make_pair(State, V);
821 }
822
823private:
824 ProgramStateRef finishArgumentConstruction(ProgramStateRef State,
825 const CallEvent &Call);
826 void finishArgumentConstruction(ExplodedNodeSet &Dst, ExplodedNode *Pred,
827 const CallEvent &Call);
828
829 void evalLocation(ExplodedNodeSet &Dst,
830 const Stmt *NodeEx, /* This will eventually be a CFGStmt */
831 const Stmt *BoundEx,
832 ExplodedNode *Pred,
834 SVal location,
835 bool isLoad);
836
837 /// Count the stack depth and determine if the call is recursive.
838 void examineStackFrames(const Decl *D, const StackFrame *SF,
839 bool &IsRecursive, unsigned &StackDepth);
840
841 enum CallInlinePolicy {
842 CIP_Allowed,
843 CIP_DisallowedOnce,
844 CIP_DisallowedAlways
845 };
846
847 /// See if a particular call should be inlined, by only looking
848 /// at the call event and the current state of analysis.
849 CallInlinePolicy mayInlineCallKind(const CallEvent &Call,
850 const ExplodedNode *Pred,
851 AnalyzerOptions &Opts,
852 const EvalCallOptions &CallOpts);
853
854 /// See if the given AnalysisDeclContext is built for a function that we
855 /// should always inline simply because it's small enough.
856 /// Apart from "small" functions, we also have "large" functions
857 /// (cf. isLarge()), some of which are huge (cf. isHuge()), and we classify
858 /// the remaining functions as "medium".
859 bool isSmall(AnalysisDeclContext *ADC) const;
860
861 /// See if the given AnalysisDeclContext is built for a function that we
862 /// should inline carefully because it looks pretty large.
863 bool isLarge(AnalysisDeclContext *ADC) const;
864
865 /// See if the given AnalysisDeclContext is built for a function that we
866 /// should never inline because it's legit gigantic.
867 bool isHuge(AnalysisDeclContext *ADC) const;
868
869 /// See if the given AnalysisDeclContext is built for a function that we
870 /// should inline, just by looking at the declaration of the function.
871 bool mayInlineDecl(AnalysisDeclContext *ADC) const;
872
873 /// Checks our policies and decides whether the given call should be inlined.
874 bool shouldInlineCall(const CallEvent &Call, const Decl *D,
875 const ExplodedNode *Pred,
876 const EvalCallOptions &CallOpts = {});
877
878 /// Checks whether our policies allow us to inline a non-POD type array
879 /// construction.
880 bool shouldInlineArrayConstruction(const ProgramStateRef State,
881 const CXXConstructExpr *CE,
882 const StackFrame *SF);
883
884 /// Checks whether our policies allow us to inline a non-POD type array
885 /// destruction.
886 /// \param Size The size of the array.
887 bool shouldInlineArrayDestruction(uint64_t Size);
888
889 /// Prepares the program state for array destruction. If no error happens
890 /// the function binds a 'PendingArrayDestruction' entry to the state, which
891 /// it returns along with the index. If any error happens (we fail to read
892 /// the size, the index would be -1, etc.) the function will return the
893 /// original state along with an index of 0. The actual element count of the
894 /// array can be accessed by the optional 'ElementCountVal' parameter. \param
895 /// State The program state. \param Region The memory region where the array
896 /// is stored. \param ElementTy The type an element in the array. \param SF
897 /// The stack frame. \param ElementCountVal A pointer to an optional SVal.
898 /// If specified, the size of the array will be returned in it. It can
899 /// be Unknown.
900 std::pair<ProgramStateRef, uint64_t> prepareStateForArrayDestruction(
901 const ProgramStateRef State, const MemRegion *Region,
902 const QualType &ElementTy, const StackFrame *SF,
903 SVal *ElementCountVal = nullptr);
904
905 /// Checks whether we construct an array of non-POD type, and decides if the
906 /// constructor should be invoked once again.
907 bool shouldRepeatCtorCall(ProgramStateRef State, const CXXConstructExpr *E,
908 const StackFrame *SF);
909
910 void inlineCall(WorkList *WList, const CallEvent &Call, const Decl *D,
911 NodeBuilder &Bldr, ExplodedNode *Pred, ProgramStateRef State);
912
913 void ctuBifurcate(const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
914 ExplodedNode *Pred, ProgramStateRef State);
915
916 /// Returns true if the CTU analysis is running its second phase.
917 bool isSecondPhaseCTU() { return IsCTUEnabled && !Engine.getCTUWorkList(); }
918
919 /// Conservatively evaluate call by invalidating regions and binding
920 /// a conjured return value.
921 void conservativeEvalCall(const CallEvent &Call, NodeBuilder &Bldr,
922 ExplodedNode *Pred, ProgramStateRef State);
923
924 /// Either inline or process the call conservatively (or both), based
925 /// on DynamicDispatchBifurcation data.
926 void BifurcateCall(const MemRegion *BifurReg,
927 const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
928 ExplodedNode *Pred);
929
930 bool replayWithoutInlining(ExplodedNode *P, const StackFrame *CalleeSF);
931
932 /// Models a trivial copy or move constructor or trivial assignment operator
933 /// call with a simple bind.
934 void performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
935 const CallEvent &Call);
936
937 /// If the value of the given expression \p InitWithAdjustments is a NonLoc,
938 /// copy it into a new temporary object region, and replace the value of the
939 /// expression with that.
940 ///
941 /// If \p Result is provided, the new region will be bound to this expression
942 /// instead of \p InitWithAdjustments.
943 ///
944 /// Returns the temporary region with adjustments into the optional
945 /// OutRegionWithAdjustments out-parameter if a new region was indeed needed,
946 /// otherwise sets it to nullptr.
947 ProgramStateRef createTemporaryRegionIfNeeded(
948 ProgramStateRef State, const StackFrame *SF,
949 const Expr *InitWithAdjustments, const Expr *Result = nullptr,
950 const SubRegion **OutRegionWithAdjustments = nullptr);
951
952 /// Returns a region representing the `Idx`th element of a (possibly
953 /// multi-dimensional) array, for the purposes of element construction or
954 /// destruction.
955 ///
956 /// On return, \p Ty will be set to the base type of the array.
957 ///
958 /// If the type is not an array type at all, the original value is returned.
959 /// Otherwise the "IsArray" flag is set.
960 static SVal makeElementRegion(ProgramStateRef State, SVal LValue,
961 QualType &Ty, bool &IsArray, unsigned Idx = 0);
962
963 /// Common code that handles either a CXXConstructExpr or a
964 /// CXXInheritedCtorInitExpr.
965 void handleConstructor(const Expr *E, ExplodedNode *Pred,
966 ExplodedNodeSet &Dst);
967
968public:
969 /// Note whether this loop has any more iterations to model. These methods
970 // are essentially an interface for a GDM trait. Further reading in
971 /// ExprEngine::VisitObjCForCollectionStmt().
972 [[nodiscard]] static ProgramStateRef
974 const ObjCForCollectionStmt *O,
975 const StackFrame *SF, bool HasMoreIteraton);
976
977 [[nodiscard]] static ProgramStateRef
978 removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O,
979 const StackFrame *SF);
980
981 [[nodiscard]] static bool hasMoreIteration(ProgramStateRef State,
982 const ObjCForCollectionStmt *O,
983 const StackFrame *SF);
984
985private:
986 /// Assuming we construct an array of non-POD types, this method allows us
987 /// to store which element is to be constructed next.
988 static ProgramStateRef setIndexOfElementToConstruct(ProgramStateRef State,
989 const CXXConstructExpr *E,
990 const StackFrame *SF,
991 unsigned Idx);
992
993 static ProgramStateRef removeIndexOfElementToConstruct(
994 ProgramStateRef State, const CXXConstructExpr *E, const StackFrame *SF);
995
996 /// Assuming we destruct an array of non-POD types, this method allows us
997 /// to store which element is to be destructed next.
998 static ProgramStateRef setPendingArrayDestruction(ProgramStateRef State,
999 const StackFrame *SF,
1000 unsigned Idx);
1001
1002 static ProgramStateRef removePendingArrayDestruction(ProgramStateRef State,
1003 const StackFrame *SF);
1004
1005 /// Sets the size of the array in a pending ArrayInitLoopExpr.
1006 static ProgramStateRef setPendingInitLoop(ProgramStateRef State,
1007 const CXXConstructExpr *E,
1008 const StackFrame *SF, unsigned Idx);
1009
1010 static ProgramStateRef removePendingInitLoop(ProgramStateRef State,
1011 const CXXConstructExpr *E,
1012 const StackFrame *SF);
1013
1014 static ProgramStateRef removeStateTraitsUsedForArrayEvaluation(
1015 ProgramStateRef State, const CXXConstructExpr *E, const StackFrame *SF);
1016
1017 /// Store the location of a C++ object corresponding to a statement
1018 /// until the statement is actually encountered. For example, if a DeclStmt
1019 /// has CXXConstructExpr as its initializer, the object would be considered
1020 /// to be "under construction" between CXXConstructExpr and DeclStmt.
1021 /// This allows, among other things, to keep bindings to variable's fields
1022 /// made within the constructor alive until its declaration actually
1023 /// goes into scope.
1024 static ProgramStateRef
1025 addObjectUnderConstruction(ProgramStateRef State,
1026 const ConstructionContextItem &Item,
1027 const StackFrame *SF, SVal V);
1028
1029 /// Mark the object as fully constructed, cleaning up the state trait
1030 /// that tracks objects under construction.
1031 static ProgramStateRef
1032 finishObjectConstruction(ProgramStateRef State,
1033 const ConstructionContextItem &Item,
1034 const StackFrame *SF);
1035
1036 /// If the given expression corresponds to a temporary that was used for
1037 /// passing into an elidable copy/move constructor and that constructor
1038 /// was actually elided, track that we also need to elide the destructor.
1039 static ProgramStateRef elideDestructor(ProgramStateRef State,
1040 const CXXBindTemporaryExpr *BTE,
1041 const StackFrame *SF);
1042
1043 /// Stop tracking the destructor that corresponds to an elided constructor.
1044 static ProgramStateRef
1045 cleanupElidedDestructor(ProgramStateRef State,
1046 const CXXBindTemporaryExpr *BTE,
1047 const StackFrame *SF);
1048
1049 /// Returns true if the given expression corresponds to a temporary that
1050 /// was constructed for passing into an elidable copy/move constructor
1051 /// and that constructor was actually elided.
1052 static bool isDestructorElided(ProgramStateRef State,
1053 const CXXBindTemporaryExpr *BTE,
1054 const StackFrame *SF);
1055
1056 /// Check if all objects under construction have been fully constructed
1057 /// for the given context range (including FromSF, not including ToSF).
1058 /// This is useful for assertions. Also checks if elided destructors
1059 /// were cleaned up.
1060 static bool areAllObjectsFullyConstructed(ProgramStateRef State,
1061 const StackFrame *FromSF,
1062 const StackFrame *ToSF);
1063};
1064
1065/// Traits for storing the call processing policy inside GDM.
1066/// The GDM stores the corresponding CallExpr pointer.
1067// FIXME: This does not use the nice trait macros because it must be accessible
1068// from multiple translation units.
1070template <>
1072 public ProgramStatePartialTrait<const void*> {
1073 static void *GDMIndex();
1074};
1075
1076} // namespace ento
1077
1078} // namespace clang
1079
1080#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_EXPRENGINE_H
#define V(N, I)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
AnalysisDeclContext contains the context data for the function, method or block under analysis.
Stores options for the analyzer from the command line.
Represents a loop initializing the elements of an array.
Definition Expr.h:5968
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2724
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6928
Represents an attribute applied to a statement.
Definition Stmt.h:2213
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4041
BinaryOperatorKind Opcode
Definition Expr.h:4046
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6672
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
Definition CFG.h:465
Represents C++ object destructor implicitly generated for base object in destructor.
Definition CFG.h:516
Represents a single basic block in a source-level CFG.
Definition CFG.h:652
Represents C++ object destructor generated from a call to delete.
Definition CFG.h:490
Represents a top-level expression in a basic block.
Definition CFG.h:55
Represents C++ object destructor implicitly generated by compiler on various occasions.
Definition CFG.h:414
Represents C++ base or member initializer from constructor's initialization list.
Definition CFG.h:232
Represents C++ object destructor implicitly generated for member object in destructor.
Definition CFG.h:537
Represents C++ object destructor implicitly generated at the end of full expression for temporary obj...
Definition CFG.h:558
Represents binding an expression to a temporary.
Definition ExprCXX.h:1497
CXXCatchStmt - This represents a C++ catch block.
Definition StmtCXX.h:28
Represents a call to a C++ constructor.
Definition ExprCXX.h:1552
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2630
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1755
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2359
Represents the this expression in C++.
Definition ExprCXX.h:1158
Represents a point when we begin processing an inlined call.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2946
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3679
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3608
Represents a single point (AST node) in the program that requires attention during construction of an...
ConstructionContext's subclasses describe different ways of constructing an object in C++.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1641
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
This represents one expression.
Definition Expr.h:112
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3456
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h:1972
This represents a Microsoft inline-assembly statement extension.
Definition Stmt.h:3675
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4920
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3367
This represents a decl that may have a name.
Definition Decl.h:274
Represents Objective-C's @synchronized statement.
Definition StmtObjC.h:303
Represents Objective-C's collection statement.
Definition StmtObjC.h:23
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition ExprObjC.h:580
An expression that sends a message to the given Objective-C object or class.
Definition ExprObjC.h:971
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2530
ProgramPoints can be "tagged" as representing points specific to a given analysis entity.
A (possibly-)qualified type.
Definition TypeBase.h:937
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.
const Decl * getDecl() const
Stmt - This represents one statement.
Definition Stmt.h:86
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2519
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2628
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2247
Represents a variable declaration or definition.
Definition Decl.h:924
This class is used for tools that requires cross translation unit capability.
BugReporter is a utility class for generating PathDiagnostics for analysis.
Represents an abstract call to a function or method along a particular path.
Definition CallEvent.h:152
CoreEngine - Implements the core logic of the graph-reachability analysis.
Definition CoreEngine.h:50
WorkList * getCTUWorkList() const
Definition CoreEngine.h:162
ExplodedNodeSet is a set of ExplodedNode * elements with the invariant that its elements cannot be nu...
void VisitBinaryOperator(const BinaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitBinaryOperator - Transfer function logic for binary operators.
const StackFrame * getRootStackFrame() const
Definition ExprEngine.h:268
ProgramStateManager & getStateManager()
Definition ExprEngine.h:476
void processCFGElement(const CFGElement E, ExplodedNode *Pred, unsigned StmtIdx)
processCFGElement - Called by CoreEngine.
void processBranch(const Stmt *Condition, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF, std::optional< unsigned > IterationsCompletedInLoop)
ProcessBranch - Called by CoreEngine.
void VisitArraySubscriptExpr(const ArraySubscriptExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitArraySubscriptExpr - Transfer function for array accesses.
void VisitCommonDeclRefExpr(const Expr *DR, const NamedDecl *D, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Transfer function logic for DeclRefExprs and BlockDeclRefExprs.
void ProcessInitializer(const CFGInitializer I, ExplodedNode *Pred)
void VisitObjCMessage(const ObjCMessageExpr *ME, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void ProcessTemporaryDtor(const CFGTemporaryDtor D, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void removeDead(ExplodedNode *Node, ExplodedNodeSet &Out, const Stmt *ReferenceStmt, const StackFrame *SF, const Stmt *DiagnosticStmt=nullptr, ProgramPoint::Kind K=ProgramPoint::PreStmtPurgeDeadSymbolsKind)
Run the analyzer's garbage collection - remove dead symbols and bindings from the state.
void VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitGuardedExpr - Transfer function logic for ?, __builtin_choose.
void runCheckersForBlockEntrance(const BlockEntrance &Entrance, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitCast - Transfer function logic for all casts (implicit and explicit).
BasicValueFactory & getBasicVals()
Definition ExprEngine.h:492
void VisitLogicalExpr(const BinaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitLogicalExpr - Transfer function logic for '&&', '||'.
void processEndOfFunction(ExplodedNode *Pred, const ReturnStmt *RS=nullptr)
Called by CoreEngine.
void VisitCXXDestructor(QualType ObjectType, const MemRegion *Dest, const Stmt *S, bool IsBaseDtor, ExplodedNode *Pred, ExplodedNodeSet &Dst, EvalCallOptions &Options)
void removeDeadOnEndOfFunction(ExplodedNode *Pred, ExplodedNodeSet &Dst)
Remove dead bindings/symbols before exiting a function.
void evalEagerlyAssumeBifurcation(ExplodedNodeSet &Dst, ExplodedNodeSet &Src, const Expr *Ex)
evalEagerlyAssumeBifurcation - Given the nodes in 'Src', eagerly assume concrete boolean values for '...
void VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Transfer function logic for ObjCAtSynchronizedStmts.
void VisitReturnStmt(const ReturnStmt *R, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitReturnStmt - Transfer function logic for return statements.
const CoreEngine & getCoreEngine() const
Definition ExprEngine.h:507
SVal evalBinOp(ProgramStateRef ST, BinaryOperator::Opcode Op, SVal LHS, SVal RHS, QualType T)
Definition ExprEngine.h:680
void processCallEnter(CallEnter CE, ExplodedNode *Pred)
Generate the entry node of the callee.
void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitLambdaExpr(const LambdaExpr *LE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitLambdaExpr - Transfer function logic for LambdaExprs.
void ProcessImplicitDtor(const CFGImplicitDtor D, ExplodedNode *Pred)
void VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitObjCForCollectionStmt - Transfer function logic for ObjCForCollectionStmt.
void VisitUnaryOperator(const UnaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitUnaryOperator - Transfer function logic for unary operators.
void VisitLvalObjCIvarRefExpr(const ObjCIvarRefExpr *DR, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Transfer function logic for computing the lvalue of an Objective-C ivar.
void VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitDeclStmt - Transfer function logic for DeclStmts.
void processCallExit(ExplodedNode *Pred)
Generate the sequence of nodes that simulate the call exit and the post visit for CallExpr.
void VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitMSAsmStmt - Transfer function logic for MS inline asm.
void processStaticInitializer(const DeclStmt *DS, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF)
Called by CoreEngine.
const SymbolManager & getSymbolManager() const
Definition ExprEngine.h:497
CFGElement getCurrentCFGElement()
Return the CFG element corresponding to the worklist element that is currently being processed by Exp...
Definition ExprEngine.h:762
static std::optional< unsigned > getIndexOfElementToConstruct(ProgramStateRef State, const CXXConstructExpr *E, const StackFrame *SF)
Retrieves which element is being constructed in a non-POD type array.
std::string DumpGraph(bool trim=false, StringRef Filename="")
Dump graph to the specified filename.
bool hasWorkRemaining() const
Definition ExprEngine.h:505
virtual ~ExprEngine()=default
ProgramStateRef processRegionChanges(ProgramStateRef state, const InvalidatedSymbols *invalidated, ArrayRef< const MemRegion * > ExplicitRegions, ArrayRef< const MemRegion * > Regions, const StackFrame *SF, const CallEvent *Call)
processRegionChanges - Called by ProgramStateManager whenever a change is made to the store.
InliningModes
The modes of inlining, which override the default analysis-wide settings.
Definition ExprEngine.h:125
@ Inline_Minimal
Do minimal inlining of callees.
Definition ExprEngine.h:130
@ Inline_Regular
Follow the default settings for inlining callees.
Definition ExprEngine.h:127
ProgramStateRef bindReturnValue(const CallEvent &Call, const StackFrame *SF, ProgramStateRef State)
Create a new state in which the call return value is binded to the call origin expression.
ProgramStateRef handleLValueBitCast(ProgramStateRef state, const Expr *Ex, const StackFrame *SF, QualType T, QualType ExTy, const CastExpr *CastE, NodeBuilder &Bldr, ExplodedNode *Pred)
void printJson(raw_ostream &Out, ProgramStateRef State, const StackFrame *SF, const char *NL, unsigned int Space, bool IsDot) const
printJson - Called by ProgramStateManager to print checker-specific data.
const ExplodedGraph & getGraph() const
Definition ExprEngine.h:326
void ProcessLifetimeEnd(const Stmt *S, const VarDecl *D, ExplodedNode *Pred)
static std::optional< unsigned > getPendingInitLoop(ProgramStateRef State, const CXXConstructExpr *E, const StackFrame *SF)
Retrieves the size of the array in the pending ArrayInitLoopExpr.
const StoreManager & getStoreManager() const
Definition ExprEngine.h:480
ProgramStateRef processAssume(ProgramStateRef state, SVal cond, bool assumption)
evalAssume - Callback function invoked by the ConstraintManager when making assumptions about state v...
AnalysisDeclContextManager & getAnalysisDeclContextManager()
Definition ExprEngine.h:219
const ProgramStateManager & getStateManager() const
Definition ExprEngine.h:477
static ProgramStateRef removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O, const StackFrame *SF)
void VisitBlockExpr(const BlockExpr *BE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitBlockExpr - Transfer function logic for BlockExprs.
void ProcessBaseDtor(const CFGBaseDtor D, ExplodedNode *Pred, ExplodedNodeSet &Dst)
static std::pair< const ProgramPointTag *, const ProgramPointTag * > getEagerlyAssumeBifurcationTags()
void VisitIncrementDecrementOperator(const UnaryOperator *U, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Handle ++ and – (both pre- and post-increment).
void setCurrStackFrameAndBlock(const StackFrame *SF, const CFGBlock *B)
Definition ExprEngine.h:244
void VisitCallExpr(const CallExpr *CE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitCall - Transfer function for function calls.
void processCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF)
Called by CoreEngine.
ProgramStateRef processRegionChange(ProgramStateRef state, const MemRegion *MR, const StackFrame *SF)
Definition ExprEngine.h:466
ASTContext & getContext() const
getContext - Return the ASTContext associated with this analysis.
Definition ExprEngine.h:214
StoreManager & getStoreManager()
Definition ExprEngine.h:479
const ConstraintManager & getConstraintManager() const
Definition ExprEngine.h:487
void VisitCXXNewAllocatorCall(const CXXNewExpr *CNE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Create a C++ temporary object for an rvalue.
void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred, const CallEvent &Call)
Evaluate a call, running pre- and post-call checkers and allowing checkers to be responsible for hand...
void VisitGCCAsmStmt(const GCCAsmStmt *A, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitGCCAsmStmt - Transfer function logic for inline asm.
BugReporter & getBugReporter()
Definition ExprEngine.h:230
bool hasEmptyWorkList() const
Definition ExprEngine.h:504
bool ExecuteWorkList(const StackFrame *SF, unsigned Steps=150000)
Returns true if there is still simulation state on the worklist.
Definition ExprEngine.h:207
ProgramStateRef updateObjectsUnderConstruction(SVal V, const Expr *E, ProgramStateRef State, const StackFrame *SF, const ConstructionContext *CC, const EvalCallOptions &CallOpts)
Update the program state with all the path-sensitive information that's necessary to perform construc...
void ProcessStmt(const Stmt *S, ExplodedNode *Pred)
ConstCFGElementRef getCFGElementRef() const
Definition ExprEngine.h:290
ExprEngine(cross_tu::CrossTranslationUnitContext &CTU, AnalysisManager &mgr, SetOfConstDecls *VisitedCalleesIn, FunctionSummariesTy *FS, InliningModes HowToInlineIn)
void ViewGraph(bool trim=false)
Visualize the ExplodedGraph created by executing the simulation.
ProgramStateRef notifyCheckersOfPointerEscape(ProgramStateRef State, const InvalidatedSymbols *Invalidated, ArrayRef< const MemRegion * > ExplicitRegions, const CallEvent *Call, RegionAndSymbolInvalidationTraits &ITraits)
Call PointerEscape callback when a value escapes as a result of region invalidation.
static const ProgramPointTag * cleanupNodeTag()
A tag to track convenience transitions, which can be removed at cleanup.
static ProgramStateRef setWhetherHasMoreIteration(ProgramStateRef State, const ObjCForCollectionStmt *O, const StackFrame *SF, bool HasMoreIteraton)
Note whether this loop has any more iterations to model. These methods.
static std::optional< unsigned > getPendingArrayDestruction(ProgramStateRef State, const StackFrame *SF)
Retrieves which element is being destructed in a non-POD type array.
ProgramStateRef processPointerEscapedOnBind(ProgramStateRef State, ArrayRef< std::pair< SVal, SVal > > LocAndVals, const StackFrame *SF, PointerEscapeKind Kind, const CallEvent *Call)
Call PointerEscape callback when a value escapes as a result of bind.
void ConstructInitList(const Expr *Source, ArrayRef< Expr * > Args, bool IsTransparent, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitUnaryExprOrTypeTraitExpr - Transfer function for sizeof.
cross_tu::CrossTranslationUnitContext * getCrossTranslationUnitContext()
Definition ExprEngine.h:234
ProgramStateRef escapeValues(ProgramStateRef State, ArrayRef< SVal > Vs, PointerEscapeKind K, const CallEvent *Call=nullptr) const
A simple wrapper when you only need to notify checkers of pointer-escape of some values.
void ProcessLoopExit(const Stmt *S, ExplodedNode *Pred)
void processEndWorklist()
Called by CoreEngine when the analysis worklist has terminated.
CheckerManager & getCheckerManager() const
Definition ExprEngine.h:223
static std::optional< SVal > getObjectUnderConstruction(ProgramStateRef State, const ConstructionContextItem &Item, const StackFrame *SF)
By looking at a certain item that may be potentially part of an object's ConstructionContext,...
SymbolManager & getSymbolManager()
Definition ExprEngine.h:496
void processBeginOfFunction(ExplodedNode *Pred, ExplodedNodeSet &Dst, const BlockEdge &L)
Called by CoreEngine.
void VisitAtomicExpr(const AtomicExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitAtomicExpr - Transfer function for builtin atomic expressions.
bool wasBlocksExhausted() const
Definition ExprEngine.h:503
MemRegionManager & getRegionManager()
Definition ExprEngine.h:498
const AnalysisManager & getAnalysisManager() const
Definition ExprEngine.h:217
SVal computeObjectUnderConstruction(const Expr *E, ProgramStateRef State, unsigned NumVisitedCaller, const StackFrame *SF, const ConstructionContext *CC, EvalCallOptions &CallOpts, unsigned Idx=0)
Find location of the object that is being constructed by a given constructor.
void ProcessMemberDtor(const CFGMemberDtor D, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitMemberExpr - Transfer function for member expressions.
void processSwitch(const SwitchStmt *Switch, ExplodedNode *Pred, ExplodedNodeSet &Dst)
ProcessSwitch - Called by CoreEngine.
void VisitCXXConstructExpr(const CXXConstructExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
static bool hasMoreIteration(ProgramStateRef State, const ObjCForCollectionStmt *O, const StackFrame *SF)
bool didEagerlyAssumeBifurcateAt(ProgramStateRef State, const Expr *Ex) const
ConstraintManager & getConstraintManager()
Definition ExprEngine.h:484
DataTag::Factory & getDataTags()
Definition ExprEngine.h:500
ProgramStateRef getInitialState(const StackFrame *InitSF)
getInitialState - Return the initial state used for the root vertex in the ExplodedGraph.
const NodeBuilderContext & getBuilderContext() const
Definition ExprEngine.h:263
void ProcessAutomaticObjDtor(const CFGAutomaticObjDtor D, ExplodedNode *Pred, ExplodedNodeSet &Dst)
unsigned getNumVisitedCurrent() const
Definition ExprEngine.h:299
void VisitOffsetOfExpr(const OffsetOfExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitOffsetOfExpr - Transfer function for offsetof.
void evalLoad(ExplodedNodeSet &Dst, const Expr *NodeEx, const Expr *BoundExpr, ExplodedNode *Pred, ProgramStateRef St, SVal location, const ProgramPointTag *tag=nullptr, QualType LoadTy=QualType())
Simulate a read of the result of Ex.
void Visit(const Stmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Visit - Transfer function logic for all statements.
void defaultEvalCall(NodeBuilder &B, ExplodedNode *Pred, const CallEvent &Call, const EvalCallOptions &CallOpts={})
Default implementation of call evaluation.
AnalysisManager & getAnalysisManager()
Definition ExprEngine.h:216
ExplodedGraph & getGraph()
Definition ExprEngine.h:325
void ProcessDeleteDtor(const CFGDeleteDtor D, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitCXXCatchStmt(const CXXCatchStmt *CS, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitCompoundLiteralExpr(const CompoundLiteralExpr *CL, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitCompoundLiteralExpr - Transfer function logic for compound literals.
const BugReporter & getBugReporter() const
Definition ExprEngine.h:231
std::pair< ProgramStateRef, SVal > handleConstructionContext(const Expr *E, ProgramStateRef State, const NodeBuilderContext *BldrCtx, const StackFrame *SF, const ConstructionContext *CC, EvalCallOptions &CallOpts, unsigned Idx=0)
A convenient wrapper around computeObjectUnderConstruction and updateObjectsUnderConstruction.
Definition ExprEngine.h:811
void handleUOExtension(ExplodedNode *N, const UnaryOperator *U, NodeBuilder &Bldr)
SValBuilder & getSValBuilder()
Definition ExprEngine.h:227
void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitArrayInitLoopExpr - Transfer function for array init loop.
void evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, const Expr *StoreE, ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val, const ProgramPointTag *tag=nullptr)
evalStore - Handle the semantics of a store via an assignment.
void processCFGBlockEntrance(const BlockEdge &L, const BlockEntrance &BE, NodeBuilder &Builder, ExplodedNode *Pred)
Called by CoreEngine when processing the entrance of a CFGBlock.
void VisitAttributedStmt(const AttributedStmt *A, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitAttributedStmt - Transfer function logic for AttributedStmt.
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE, ExplodedNodeSet &PreVisit, ExplodedNodeSet &Dst)
const StackFrame * getCurrStackFrame() const
Get the 'current' stack frame corresponding to the current work item (elementary analysis step handle...
Definition ExprEngine.h:280
const CFGBlock * getCurrBlock() const
Get the 'current' CFGBlock corresponding to the current work item (elementary analysis step handled b...
Definition ExprEngine.h:286
const SValBuilder & getSValBuilder() const
Definition ExprEngine.h:228
unsigned getNumVisited(const StackFrame *SF, const CFGBlock *Block) const
Definition ExprEngine.h:294
void processIndirectGoto(ExplodedNodeSet &Dst, const Expr *Tgt, const CFGBlock *Dispatch, ExplodedNode *Pred)
processIndirectGoto - Called by CoreEngine.
void ProcessNewAllocator(const CXXNewExpr *NE, ExplodedNode *Pred)
MemRegion - The root abstract class for all memory regions.
Definition MemRegion.h:97
unsigned blockCount() const
Returns the number of times the current basic block has been visited on the exploded graph path.
Definition CoreEngine.h:240
This is the simplest builder which generates nodes in the ExplodedGraph.
Definition CoreEngine.h:265
GRBugReporter is used for generating path-sensitive reports.
ProgramState - This class encapsulates:
Information about invalidation for a particular region/symbol.
Definition MemRegion.h:1656
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition SVals.h:56
Definition ARM.cpp:1102
Definition SPIR.cpp:35
PointerEscapeKind
Describes the different reasons a pointer escapes during analysis.
llvm::DenseSet< const Decl * > SetOfConstDecls
llvm::DenseSet< SymbolRef > InvalidatedSymbols
Definition Store.h:50
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
The JSON file list parser is used to communicate input to InstallAPI.
CFGBlock::ConstCFGElementRef ConstCFGElementRef
Definition CFG.h:1248
@ Result
The result type of a method or function.
Definition TypeBase.h:905
Hints for figuring out if a call should be inlined during evalCall().
Definition ExprEngine.h:93
bool IsTemporaryLifetimeExtendedViaAggregate
This call is a constructor for a temporary that is lifetime-extended by binding it to a reference-typ...
Definition ExprEngine.h:108
bool IsTemporaryCtorOrDtor
This call is a constructor or a destructor of a temporary value.
Definition ExprEngine.h:103
bool IsArrayCtorOrDtor
This call is a constructor or a destructor for a single element within an array, a part of array cons...
Definition ExprEngine.h:100
bool IsElidableCtorThatHasNotBeenElided
This call is a pre-C++17 elidable constructor that we failed to elide because we failed to compute th...
Definition ExprEngine.h:115
bool IsCtorOrDtorWithImproperlyModeledTargetRegion
This call is a constructor or a destructor for which we do not currently compute the this-region corr...
Definition ExprEngine.h:96
Traits for storing the call processing policy inside GDM.