clang 20.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
44class AnalysisDeclContextManager;
45class AnalyzerOptions;
46class ASTContext;
47class CFGBlock;
48class CFGElement;
49class ConstructionContext;
50class CXXBindTemporaryExpr;
51class CXXCatchStmt;
52class CXXConstructExpr;
53class CXXDeleteExpr;
54class CXXNewExpr;
55class CXXThisExpr;
56class Decl;
57class DeclStmt;
58class GCCAsmStmt;
59class LambdaExpr;
60class LocationContext;
61class MaterializeTemporaryExpr;
62class MSAsmStmt;
63class NamedDecl;
64class ObjCAtSynchronizedStmt;
65class ObjCForCollectionStmt;
66class ObjCIvarRefExpr;
67class ObjCMessageExpr;
68class ReturnStmt;
69class Stmt;
70
71namespace cross_tu {
72
73class CrossTranslationUnitContext;
74
75} // namespace cross_tu
76
77namespace ento {
78
79class AnalysisManager;
80class BasicValueFactory;
81class CallEvent;
82class CheckerManager;
83class ConstraintManager;
84class ExplodedNodeSet;
85class ExplodedNode;
86class IndirectGotoNodeBuilder;
87class MemRegion;
88class NodeBuilderContext;
89class NodeBuilderWithSinks;
90class ProgramState;
91class ProgramStateManager;
92class RegionAndSymbolInvalidationTraits;
93class SymbolManager;
94class SwitchNodeBuilder;
95
96/// Hints for figuring out of a call should be inlined during evalCall().
98 /// This call is a constructor or a destructor for which we do not currently
99 /// compute the this-region correctly.
101
102 /// This call is a constructor or a destructor for a single element within
103 /// an array, a part of array construction or destruction.
104 bool IsArrayCtorOrDtor = false;
105
106 /// This call is a constructor or a destructor of a temporary value.
108
109 /// This call is a constructor for a temporary that is lifetime-extended
110 /// by binding it to a reference-type field within an aggregate,
111 /// for example 'A { const C &c; }; A a = { C() };'
113
114 /// This call is a pre-C++17 elidable constructor that we failed to elide
115 /// because we failed to compute the target region into which
116 /// this constructor would have been ultimately elided. Analysis that
117 /// we perform in this case is still correct but it behaves differently,
118 /// as if copy elision is disabled.
120
122};
123
125 void anchor();
126
127public:
128 /// The modes of inlining, which override the default analysis-wide settings.
130 /// Follow the default settings for inlining callees.
132
133 /// Do minimal inlining of callees.
134 Inline_Minimal = 0x1
135 };
136
137private:
139 bool IsCTUEnabled;
140
141 AnalysisManager &AMgr;
142
143 AnalysisDeclContextManager &AnalysisDeclContexts;
144
145 CoreEngine Engine;
146
147 /// G - the simulation graph.
148 ExplodedGraph &G;
149
150 /// StateMgr - Object that manages the data for all created states.
151 ProgramStateManager StateMgr;
152
153 /// SymMgr - Object that manages the symbol information.
154 SymbolManager &SymMgr;
155
156 /// MRMgr - MemRegionManager object that creates memory regions.
157 MemRegionManager &MRMgr;
158
159 /// svalBuilder - SValBuilder object that creates SVals from expressions.
160 SValBuilder &svalBuilder;
161
162 unsigned int currStmtIdx = 0;
163 const NodeBuilderContext *currBldrCtx = nullptr;
164
165 /// Helper object to determine if an Objective-C message expression
166 /// implicitly never returns.
167 ObjCNoReturn ObjCNoRet;
168
169 /// The BugReporter associated with this engine. It is important that
170 /// this object be placed at the very end of member variables so that its
171 /// destructor is called before the rest of the ExprEngine is destroyed.
173
174 /// The functions which have been analyzed through inlining. This is owned by
175 /// AnalysisConsumer. It can be null.
176 SetOfConstDecls *VisitedCallees;
177
178 /// The flag, which specifies the mode of inlining for the engine.
179 InliningModes HowToInline;
180
181public:
183 SetOfConstDecls *VisitedCalleesIn,
184 FunctionSummariesTy *FS, InliningModes HowToInlineIn);
185
186 virtual ~ExprEngine() = default;
187
188 /// Returns true if there is still simulation state on the worklist.
189 bool ExecuteWorkList(const LocationContext *L, unsigned Steps = 150000) {
190 assert(L->inTopFrame());
192 return Engine.ExecuteWorkList(L, Steps, nullptr);
193 }
194
195 /// getContext - Return the ASTContext associated with this analysis.
196 ASTContext &getContext() const { return AMgr.getASTContext(); }
197
199
201 return AMgr.getAnalysisDeclContextManager();
202 }
203
205 return *AMgr.getCheckerManager();
206 }
207
208 SValBuilder &getSValBuilder() { return svalBuilder; }
209
210 BugReporter &getBugReporter() { return BR; }
211
214 return &CTU;
215 }
216
218 assert(currBldrCtx);
219 return *currBldrCtx;
220 }
221
222 const Stmt *getStmt() const;
223
225 assert(G.roots_begin() != G.roots_end());
226 return (*G.roots_begin())->getLocation().getLocationContext();
227 }
228
230 const CFGBlock *blockPtr = currBldrCtx ? currBldrCtx->getBlock() : nullptr;
231 return {blockPtr, currStmtIdx};
232 }
233
234 /// Dump graph to the specified filename.
235 /// If filename is empty, generate a temporary one.
236 /// \return The filename the graph is written into.
237 std::string DumpGraph(bool trim = false, StringRef Filename="");
238
239 /// Dump the graph consisting of the given nodes to a specified filename.
240 /// Generate a temporary filename if it's not provided.
241 /// \return The filename the graph is written into.
243 StringRef Filename = "");
244
245 /// Visualize the ExplodedGraph created by executing the simulation.
246 void ViewGraph(bool trim = false);
247
248 /// Visualize a trimmed ExplodedGraph that only contains paths to the given
249 /// nodes.
251
252 /// getInitialState - Return the initial state used for the root vertex
253 /// in the ExplodedGraph.
255
256 ExplodedGraph &getGraph() { return G; }
257 const ExplodedGraph &getGraph() const { return G; }
258
259 /// Run the analyzer's garbage collection - remove dead symbols and
260 /// bindings from the state.
261 ///
262 /// Checkers can participate in this process with two callbacks:
263 /// \c checkLiveSymbols and \c checkDeadSymbols. See the CheckerDocumentation
264 /// class for more information.
265 ///
266 /// \param Node The predecessor node, from which the processing should start.
267 /// \param Out The returned set of output nodes.
268 /// \param ReferenceStmt The statement which is about to be processed.
269 /// Everything needed for this statement should be considered live.
270 /// A null statement means that everything in child LocationContexts
271 /// is dead.
272 /// \param LC The location context of the \p ReferenceStmt. A null location
273 /// context means that we have reached the end of analysis and that
274 /// all statements and local variables should be considered dead.
275 /// \param DiagnosticStmt Used as a location for any warnings that should
276 /// occur while removing the dead (e.g. leaks). By default, the
277 /// \p ReferenceStmt is used.
278 /// \param K Denotes whether this is a pre- or post-statement purge. This
279 /// must only be ProgramPoint::PostStmtPurgeDeadSymbolsKind if an
280 /// entire location context is being cleared, in which case the
281 /// \p ReferenceStmt must either be a ReturnStmt or \c NULL. Otherwise,
282 /// it must be ProgramPoint::PreStmtPurgeDeadSymbolsKind (the default)
283 /// and \p ReferenceStmt must be valid (non-null).
285 const Stmt *ReferenceStmt, const LocationContext *LC,
286 const Stmt *DiagnosticStmt = nullptr,
288
289 /// A tag to track convenience transitions, which can be removed at cleanup.
290 /// This tag applies to a node created after removeDead.
291 static const ProgramPointTag *cleanupNodeTag();
292
293 /// processCFGElement - Called by CoreEngine. Used to generate new successor
294 /// nodes by processing the 'effects' of a CFG element.
295 void processCFGElement(const CFGElement E, ExplodedNode *Pred,
296 unsigned StmtIdx, NodeBuilderContext *Ctx);
297
298 void ProcessStmt(const Stmt *S, ExplodedNode *Pred);
299
300 void ProcessLoopExit(const Stmt* S, ExplodedNode *Pred);
301
303
305
306 void ProcessNewAllocator(const CXXNewExpr *NE, ExplodedNode *Pred);
307
309 ExplodedNode *Pred, ExplodedNodeSet &Dst);
311 ExplodedNode *Pred, ExplodedNodeSet &Dst);
312 void ProcessBaseDtor(const CFGBaseDtor D,
313 ExplodedNode *Pred, ExplodedNodeSet &Dst);
315 ExplodedNode *Pred, ExplodedNodeSet &Dst);
317 ExplodedNode *Pred, ExplodedNodeSet &Dst);
318
319 /// Called by CoreEngine when processing the entrance of a CFGBlock.
321 NodeBuilderWithSinks &nodeBuilder,
322 ExplodedNode *Pred);
323
324 /// ProcessBranch - Called by CoreEngine. Used to generate successor
325 /// nodes by processing the 'effects' of a branch condition.
326 void processBranch(const Stmt *Condition,
327 NodeBuilderContext& BuilderCtx,
328 ExplodedNode *Pred,
329 ExplodedNodeSet &Dst,
330 const CFGBlock *DstT,
331 const CFGBlock *DstF);
332
333 /// Called by CoreEngine.
334 /// Used to generate successor nodes for temporary destructors depending
335 /// on whether the corresponding constructor was visited.
337 NodeBuilderContext &BldCtx,
338 ExplodedNode *Pred, ExplodedNodeSet &Dst,
339 const CFGBlock *DstT,
340 const CFGBlock *DstF);
341
342 /// Called by CoreEngine. Used to processing branching behavior
343 /// at static initializers.
345 NodeBuilderContext& BuilderCtx,
346 ExplodedNode *Pred,
347 ExplodedNodeSet &Dst,
348 const CFGBlock *DstT,
349 const CFGBlock *DstF);
350
351 /// processIndirectGoto - Called by CoreEngine. Used to generate successor
352 /// nodes by processing the 'effects' of a computed goto jump.
354
355 /// ProcessSwitch - Called by CoreEngine. Used to generate successor
356 /// nodes by processing the 'effects' of a switch statement.
357 void processSwitch(SwitchNodeBuilder& builder);
358
359 /// Called by CoreEngine. Used to notify checkers that processing a
360 /// function has begun. Called for both inlined and top-level functions.
362 ExplodedNode *Pred, ExplodedNodeSet &Dst,
363 const BlockEdge &L);
364
365 /// Called by CoreEngine. Used to notify checkers that processing a
366 /// function has ended. Called for both inlined and top-level functions.
368 ExplodedNode *Pred,
369 const ReturnStmt *RS = nullptr);
370
371 /// Remove dead bindings/symbols before exiting a function.
373 ExplodedNode *Pred,
374 ExplodedNodeSet &Dst);
375
376 /// Generate the entry node of the callee.
378 ExplodedNode *Pred);
379
380 /// Generate the sequence of nodes that simulate the call exit and the post
381 /// visit for CallExpr.
382 void processCallExit(ExplodedNode *Pred);
383
384 /// Called by CoreEngine when the analysis worklist has terminated.
385 void processEndWorklist();
386
387 /// evalAssume - Callback function invoked by the ConstraintManager when
388 /// making assumptions about state values.
390 bool assumption);
391
392 /// processRegionChanges - Called by ProgramStateManager whenever a change is made
393 /// to the store. Used to update checkers that track region values.
396 const InvalidatedSymbols *invalidated,
397 ArrayRef<const MemRegion *> ExplicitRegions,
399 const LocationContext *LCtx,
400 const CallEvent *Call);
401
402 inline ProgramStateRef
404 const MemRegion* MR,
405 const LocationContext *LCtx) {
406 return processRegionChanges(state, nullptr, MR, MR, LCtx, nullptr);
407 }
408
409 /// printJson - Called by ProgramStateManager to print checker-specific data.
410 void printJson(raw_ostream &Out, ProgramStateRef State,
411 const LocationContext *LCtx, const char *NL,
412 unsigned int Space, bool IsDot) const;
413
414 ProgramStateManager &getStateManager() { return StateMgr; }
415
417
419 return StateMgr.getConstraintManager();
420 }
421
422 // FIXME: Remove when we migrate over to just using SValBuilder.
424 return StateMgr.getBasicVals();
425 }
426
427 SymbolManager &getSymbolManager() { return SymMgr; }
429
431
432 // Functions for external checking of whether we have unfinished work
433 bool wasBlocksExhausted() const { return Engine.wasBlocksExhausted(); }
434 bool hasEmptyWorkList() const { return !Engine.getWorkList()->hasWork(); }
435 bool hasWorkRemaining() const { return Engine.hasWorkRemaining(); }
436
437 const CoreEngine &getCoreEngine() const { return Engine; }
438
439public:
440 /// Visit - Transfer function logic for all statements. Dispatches to
441 /// other functions that handle specific kinds of statements.
442 void Visit(const Stmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst);
443
444 /// VisitArrayInitLoopExpr - Transfer function for array init loop.
446 ExplodedNodeSet &Dst);
447
448 /// VisitArraySubscriptExpr - Transfer function for array accesses.
450 ExplodedNode *Pred,
451 ExplodedNodeSet &Dst);
452
453 /// VisitGCCAsmStmt - Transfer function logic for inline asm.
454 void VisitGCCAsmStmt(const GCCAsmStmt *A, ExplodedNode *Pred,
455 ExplodedNodeSet &Dst);
456
457 /// VisitMSAsmStmt - Transfer function logic for MS inline asm.
458 void VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred,
459 ExplodedNodeSet &Dst);
460
461 /// VisitBlockExpr - Transfer function logic for BlockExprs.
462 void VisitBlockExpr(const BlockExpr *BE, ExplodedNode *Pred,
463 ExplodedNodeSet &Dst);
464
465 /// VisitLambdaExpr - Transfer function logic for LambdaExprs.
466 void VisitLambdaExpr(const LambdaExpr *LE, ExplodedNode *Pred,
467 ExplodedNodeSet &Dst);
468
469 /// VisitBinaryOperator - Transfer function logic for binary operators.
471 ExplodedNodeSet &Dst);
472
473
474 /// VisitCall - Transfer function for function calls.
475 void VisitCallExpr(const CallExpr *CE, ExplodedNode *Pred,
476 ExplodedNodeSet &Dst);
477
478 /// VisitCast - Transfer function logic for all casts (implicit and explicit).
479 void VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNode *Pred,
480 ExplodedNodeSet &Dst);
481
482 /// VisitCompoundLiteralExpr - Transfer function logic for compound literals.
484 ExplodedNode *Pred, ExplodedNodeSet &Dst);
485
486 /// Transfer function logic for DeclRefExprs and BlockDeclRefExprs.
487 void VisitCommonDeclRefExpr(const Expr *DR, const NamedDecl *D,
488 ExplodedNode *Pred, ExplodedNodeSet &Dst);
489
490 /// VisitDeclStmt - Transfer function logic for DeclStmts.
491 void VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred,
492 ExplodedNodeSet &Dst);
493
494 /// VisitGuardedExpr - Transfer function logic for ?, __builtin_choose
495 void VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R,
496 ExplodedNode *Pred, ExplodedNodeSet &Dst);
497
498 void VisitInitListExpr(const InitListExpr *E, ExplodedNode *Pred,
499 ExplodedNodeSet &Dst);
500
501 /// VisitLogicalExpr - Transfer function logic for '&&', '||'
502 void VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
503 ExplodedNodeSet &Dst);
504
505 /// VisitMemberExpr - Transfer function for member expressions.
506 void VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred,
507 ExplodedNodeSet &Dst);
508
509 /// VisitAtomicExpr - Transfer function for builtin atomic expressions
510 void VisitAtomicExpr(const AtomicExpr *E, ExplodedNode *Pred,
511 ExplodedNodeSet &Dst);
512
513 /// Transfer function logic for ObjCAtSynchronizedStmts.
515 ExplodedNode *Pred, ExplodedNodeSet &Dst);
516
517 /// Transfer function logic for computing the lvalue of an Objective-C ivar.
519 ExplodedNodeSet &Dst);
520
521 /// VisitObjCForCollectionStmt - Transfer function logic for
522 /// ObjCForCollectionStmt.
524 ExplodedNode *Pred, ExplodedNodeSet &Dst);
525
526 void VisitObjCMessage(const ObjCMessageExpr *ME, ExplodedNode *Pred,
527 ExplodedNodeSet &Dst);
528
529 /// VisitReturnStmt - Transfer function logic for return statements.
530 void VisitReturnStmt(const ReturnStmt *R, ExplodedNode *Pred,
531 ExplodedNodeSet &Dst);
532
533 /// VisitOffsetOfExpr - Transfer function for offsetof.
534 void VisitOffsetOfExpr(const OffsetOfExpr *Ex, ExplodedNode *Pred,
535 ExplodedNodeSet &Dst);
536
537 /// VisitUnaryExprOrTypeTraitExpr - Transfer function for sizeof.
539 ExplodedNode *Pred, ExplodedNodeSet &Dst);
540
541 /// VisitUnaryOperator - Transfer function logic for unary operators.
542 void VisitUnaryOperator(const UnaryOperator* B, ExplodedNode *Pred,
543 ExplodedNodeSet &Dst);
544
545 /// Handle ++ and -- (both pre- and post-increment).
547 ExplodedNode *Pred,
548 ExplodedNodeSet &Dst);
549
551 ExplodedNodeSet &PreVisit,
552 ExplodedNodeSet &Dst);
553
554 void VisitCXXCatchStmt(const CXXCatchStmt *CS, ExplodedNode *Pred,
555 ExplodedNodeSet &Dst);
556
557 void VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred,
558 ExplodedNodeSet & Dst);
559
561 ExplodedNodeSet &Dst);
562
564 ExplodedNode *Pred, ExplodedNodeSet &Dst);
565
566 void VisitCXXDestructor(QualType ObjectType, const MemRegion *Dest,
567 const Stmt *S, bool IsBaseDtor,
568 ExplodedNode *Pred, ExplodedNodeSet &Dst,
569 EvalCallOptions &Options);
570
571 void VisitCXXNewAllocatorCall(const CXXNewExpr *CNE,
572 ExplodedNode *Pred,
573 ExplodedNodeSet &Dst);
574
575 void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
576 ExplodedNodeSet &Dst);
577
578 void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE, ExplodedNode *Pred,
579 ExplodedNodeSet &Dst);
580
581 /// Create a C++ temporary object for an rvalue.
583 ExplodedNode *Pred,
584 ExplodedNodeSet &Dst);
585
586 /// evalEagerlyAssumeBifurcation - Given the nodes in 'Src', eagerly assume
587 /// concrete boolean values for 'Ex', storing the resulting nodes in 'Dst'.
589 const Expr *Ex);
590
591 static std::pair<const ProgramPointTag *, const ProgramPointTag *>
593
595 const LocationContext *LCtx, QualType T,
596 QualType ExTy, const CastExpr *CastE,
597 StmtNodeBuilder &Bldr,
598 ExplodedNode *Pred);
599
601 StmtNodeBuilder &Bldr);
602
603public:
605 SVal LHS, SVal RHS, QualType T) {
606 return svalBuilder.evalBinOp(ST, Op, LHS, RHS, T);
607 }
608
609 /// Retreives which element is being constructed in a non-POD type array.
610 static std::optional<unsigned>
612 const LocationContext *LCtx);
613
614 /// Retreives which element is being destructed in a non-POD type array.
615 static std::optional<unsigned>
617 const LocationContext *LCtx);
618
619 /// Retreives the size of the array in the pending ArrayInitLoopExpr.
620 static std::optional<unsigned>
622 const LocationContext *LCtx);
623
624 /// By looking at a certain item that may be potentially part of an object's
625 /// ConstructionContext, retrieve such object's location. A particular
626 /// statement can be transparently passed as \p Item in most cases.
627 static std::optional<SVal>
629 const ConstructionContextItem &Item,
630 const LocationContext *LC);
631
632 /// Call PointerEscape callback when a value escapes as a result of bind.
634 ProgramStateRef State, ArrayRef<std::pair<SVal, SVal>> LocAndVals,
636 const CallEvent *Call);
637
638 /// Call PointerEscape callback when a value escapes as a result of
639 /// region invalidation.
640 /// \param[in] ITraits Specifies invalidation traits for regions/symbols.
642 ProgramStateRef State,
643 const InvalidatedSymbols *Invalidated,
644 ArrayRef<const MemRegion *> ExplicitRegions,
645 const CallEvent *Call,
647
648private:
649 /// evalBind - Handle the semantics of binding a value to a specific location.
650 /// This method is used by evalStore, VisitDeclStmt, and others.
651 void evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE, ExplodedNode *Pred,
652 SVal location, SVal Val, bool atDeclInit = false,
653 const ProgramPoint *PP = nullptr);
654
657 SVal Loc, SVal Val,
658 const LocationContext *LCtx);
659
660 /// A simple wrapper when you only need to notify checkers of pointer-escape
661 /// of some values.
662 ProgramStateRef escapeValues(ProgramStateRef State, ArrayRef<SVal> Vs,
664 const CallEvent *Call = nullptr) const;
665
666public:
667 // FIXME: 'tag' should be removed, and a LocationContext should be used
668 // instead.
669 // FIXME: Comment on the meaning of the arguments, when 'St' may not
670 // be the same as Pred->state, and when 'location' may not be the
671 // same as state->getLValue(Ex).
672 /// Simulate a read of the result of Ex.
673 void evalLoad(ExplodedNodeSet &Dst,
674 const Expr *NodeEx, /* Eventually will be a CFGStmt */
675 const Expr *BoundExpr,
676 ExplodedNode *Pred,
678 SVal location,
679 const ProgramPointTag *tag = nullptr,
680 QualType LoadTy = QualType());
681
682 // FIXME: 'tag' should be removed, and a LocationContext should be used
683 // instead.
684 void evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, const Expr *StoreE,
685 ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val,
686 const ProgramPointTag *tag = nullptr);
687
688 /// Return the CFG element corresponding to the worklist element
689 /// that is currently being processed by ExprEngine.
691 return (*currBldrCtx->getBlock())[currStmtIdx];
692 }
693
694 /// Create a new state in which the call return value is binded to the
695 /// call origin expression.
697 const LocationContext *LCtx,
698 ProgramStateRef State);
699
700 /// Evaluate a call, running pre- and post-call checkers and allowing checkers
701 /// to be responsible for handling the evaluation of the call itself.
702 void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred,
703 const CallEvent &Call);
704
705 /// Default implementation of call evaluation.
707 const CallEvent &Call,
708 const EvalCallOptions &CallOpts = {});
709
710 /// Find location of the object that is being constructed by a given
711 /// constructor. This should ideally always succeed but due to not being
712 /// fully implemented it sometimes indicates that it failed via its
713 /// out-parameter CallOpts; in such cases a fake temporary region is
714 /// returned, which is better than nothing but does not represent
715 /// the actual behavior of the program. The Idx parameter is used if we
716 /// construct an array of objects. In that case it points to the index
717 /// of the continuous memory region.
718 /// E.g.:
719 /// For `int arr[4]` this index can be 0,1,2,3.
720 /// For `int arr2[3][3]` this index can be 0,1,...,7,8.
721 /// A multi-dimensional array is also a continuous memory location in a
722 /// row major order, so for arr[0][0] Idx is 0 and for arr[2][2] Idx is 8.
724 const NodeBuilderContext *BldrCtx,
725 const LocationContext *LCtx,
726 const ConstructionContext *CC,
727 EvalCallOptions &CallOpts,
728 unsigned Idx = 0);
729
730 /// Update the program state with all the path-sensitive information
731 /// that's necessary to perform construction of an object with a given
732 /// syntactic construction context. V and CallOpts have to be obtained from
733 /// computeObjectUnderConstruction() invoked with the same set of
734 /// the remaining arguments (E, State, LCtx, CC).
736 SVal V, const Expr *E, ProgramStateRef State, const LocationContext *LCtx,
737 const ConstructionContext *CC, const EvalCallOptions &CallOpts);
738
739 /// A convenient wrapper around computeObjectUnderConstruction
740 /// and updateObjectsUnderConstruction.
741 std::pair<ProgramStateRef, SVal> handleConstructionContext(
742 const Expr *E, ProgramStateRef State, const NodeBuilderContext *BldrCtx,
743 const LocationContext *LCtx, const ConstructionContext *CC,
744 EvalCallOptions &CallOpts, unsigned Idx = 0) {
745
746 SVal V = computeObjectUnderConstruction(E, State, BldrCtx, LCtx, CC,
747 CallOpts, Idx);
748 State = updateObjectsUnderConstruction(V, E, State, LCtx, CC, CallOpts);
749
750 return std::make_pair(State, V);
751 }
752
753private:
754 ProgramStateRef finishArgumentConstruction(ProgramStateRef State,
755 const CallEvent &Call);
756 void finishArgumentConstruction(ExplodedNodeSet &Dst, ExplodedNode *Pred,
757 const CallEvent &Call);
758
759 void evalLocation(ExplodedNodeSet &Dst,
760 const Stmt *NodeEx, /* This will eventually be a CFGStmt */
761 const Stmt *BoundEx,
762 ExplodedNode *Pred,
764 SVal location,
765 bool isLoad);
766
767 /// Count the stack depth and determine if the call is recursive.
768 void examineStackFrames(const Decl *D, const LocationContext *LCtx,
769 bool &IsRecursive, unsigned &StackDepth);
770
771 enum CallInlinePolicy {
772 CIP_Allowed,
773 CIP_DisallowedOnce,
774 CIP_DisallowedAlways
775 };
776
777 /// See if a particular call should be inlined, by only looking
778 /// at the call event and the current state of analysis.
779 CallInlinePolicy mayInlineCallKind(const CallEvent &Call,
780 const ExplodedNode *Pred,
781 AnalyzerOptions &Opts,
782 const EvalCallOptions &CallOpts);
783
784 /// See if the given AnalysisDeclContext is built for a function that we
785 /// should always inline simply because it's small enough.
786 /// Apart from "small" functions, we also have "large" functions
787 /// (cf. isLarge()), some of which are huge (cf. isHuge()), and we classify
788 /// the remaining functions as "medium".
789 bool isSmall(AnalysisDeclContext *ADC) const;
790
791 /// See if the given AnalysisDeclContext is built for a function that we
792 /// should inline carefully because it looks pretty large.
793 bool isLarge(AnalysisDeclContext *ADC) const;
794
795 /// See if the given AnalysisDeclContext is built for a function that we
796 /// should never inline because it's legit gigantic.
797 bool isHuge(AnalysisDeclContext *ADC) const;
798
799 /// See if the given AnalysisDeclContext is built for a function that we
800 /// should inline, just by looking at the declaration of the function.
801 bool mayInlineDecl(AnalysisDeclContext *ADC) const;
802
803 /// Checks our policies and decides weither the given call should be inlined.
804 bool shouldInlineCall(const CallEvent &Call, const Decl *D,
805 const ExplodedNode *Pred,
806 const EvalCallOptions &CallOpts = {});
807
808 /// Checks whether our policies allow us to inline a non-POD type array
809 /// construction.
810 bool shouldInlineArrayConstruction(const ProgramStateRef State,
811 const CXXConstructExpr *CE,
812 const LocationContext *LCtx);
813
814 /// Checks whether our policies allow us to inline a non-POD type array
815 /// destruction.
816 /// \param Size The size of the array.
817 bool shouldInlineArrayDestruction(uint64_t Size);
818
819 /// Prepares the program state for array destruction. If no error happens
820 /// the function binds a 'PendingArrayDestruction' entry to the state, which
821 /// it returns along with the index. If any error happens (we fail to read
822 /// the size, the index would be -1, etc.) the function will return the
823 /// original state along with an index of 0. The actual element count of the
824 /// array can be accessed by the optional 'ElementCountVal' parameter. \param
825 /// State The program state. \param Region The memory region where the array
826 /// is stored. \param ElementTy The type an element in the array. \param LCty
827 /// The location context. \param ElementCountVal A pointer to an optional
828 /// SVal. If specified, the size of the array will be returned in it. It can
829 /// be Unknown.
830 std::pair<ProgramStateRef, uint64_t> prepareStateForArrayDestruction(
831 const ProgramStateRef State, const MemRegion *Region,
832 const QualType &ElementTy, const LocationContext *LCtx,
833 SVal *ElementCountVal = nullptr);
834
835 /// Checks whether we construct an array of non-POD type, and decides if the
836 /// constructor should be inkoved once again.
837 bool shouldRepeatCtorCall(ProgramStateRef State, const CXXConstructExpr *E,
838 const LocationContext *LCtx);
839
840 void inlineCall(WorkList *WList, const CallEvent &Call, const Decl *D,
841 NodeBuilder &Bldr, ExplodedNode *Pred, ProgramStateRef State);
842
843 void ctuBifurcate(const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
844 ExplodedNode *Pred, ProgramStateRef State);
845
846 /// Returns true if the CTU analysis is running its second phase.
847 bool isSecondPhaseCTU() { return IsCTUEnabled && !Engine.getCTUWorkList(); }
848
849 /// Conservatively evaluate call by invalidating regions and binding
850 /// a conjured return value.
851 void conservativeEvalCall(const CallEvent &Call, NodeBuilder &Bldr,
852 ExplodedNode *Pred, ProgramStateRef State);
853
854 /// Either inline or process the call conservatively (or both), based
855 /// on DynamicDispatchBifurcation data.
856 void BifurcateCall(const MemRegion *BifurReg,
857 const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
858 ExplodedNode *Pred);
859
860 bool replayWithoutInlining(ExplodedNode *P, const LocationContext *CalleeLC);
861
862 /// Models a trivial copy or move constructor or trivial assignment operator
863 /// call with a simple bind.
864 void performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
865 const CallEvent &Call);
866
867 /// If the value of the given expression \p InitWithAdjustments is a NonLoc,
868 /// copy it into a new temporary object region, and replace the value of the
869 /// expression with that.
870 ///
871 /// If \p Result is provided, the new region will be bound to this expression
872 /// instead of \p InitWithAdjustments.
873 ///
874 /// Returns the temporary region with adjustments into the optional
875 /// OutRegionWithAdjustments out-parameter if a new region was indeed needed,
876 /// otherwise sets it to nullptr.
877 ProgramStateRef createTemporaryRegionIfNeeded(
878 ProgramStateRef State, const LocationContext *LC,
879 const Expr *InitWithAdjustments, const Expr *Result = nullptr,
880 const SubRegion **OutRegionWithAdjustments = nullptr);
881
882 /// Returns a region representing the `Idx`th element of a (possibly
883 /// multi-dimensional) array, for the purposes of element construction or
884 /// destruction.
885 ///
886 /// On return, \p Ty will be set to the base type of the array.
887 ///
888 /// If the type is not an array type at all, the original value is returned.
889 /// Otherwise the "IsArray" flag is set.
890 static SVal makeElementRegion(ProgramStateRef State, SVal LValue,
891 QualType &Ty, bool &IsArray, unsigned Idx = 0);
892
893 /// Common code that handles either a CXXConstructExpr or a
894 /// CXXInheritedCtorInitExpr.
895 void handleConstructor(const Expr *E, ExplodedNode *Pred,
896 ExplodedNodeSet &Dst);
897
898public:
899 /// Note whether this loop has any more iteratios to model. These methods are
900 /// essentially an interface for a GDM trait. Further reading in
901 /// ExprEngine::VisitObjCForCollectionStmt().
902 [[nodiscard]] static ProgramStateRef
904 const ObjCForCollectionStmt *O,
905 const LocationContext *LC, bool HasMoreIteraton);
906
907 [[nodiscard]] static ProgramStateRef
908 removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O,
909 const LocationContext *LC);
910
911 [[nodiscard]] static bool hasMoreIteration(ProgramStateRef State,
912 const ObjCForCollectionStmt *O,
913 const LocationContext *LC);
914
915private:
916 /// Assuming we construct an array of non-POD types, this method allows us
917 /// to store which element is to be constructed next.
918 static ProgramStateRef
919 setIndexOfElementToConstruct(ProgramStateRef State, const CXXConstructExpr *E,
920 const LocationContext *LCtx, unsigned Idx);
921
922 static ProgramStateRef
923 removeIndexOfElementToConstruct(ProgramStateRef State,
924 const CXXConstructExpr *E,
925 const LocationContext *LCtx);
926
927 /// Assuming we destruct an array of non-POD types, this method allows us
928 /// to store which element is to be destructed next.
929 static ProgramStateRef setPendingArrayDestruction(ProgramStateRef State,
930 const LocationContext *LCtx,
931 unsigned Idx);
932
933 static ProgramStateRef
934 removePendingArrayDestruction(ProgramStateRef State,
935 const LocationContext *LCtx);
936
937 /// Sets the size of the array in a pending ArrayInitLoopExpr.
938 static ProgramStateRef setPendingInitLoop(ProgramStateRef State,
939 const CXXConstructExpr *E,
940 const LocationContext *LCtx,
941 unsigned Idx);
942
943 static ProgramStateRef removePendingInitLoop(ProgramStateRef State,
944 const CXXConstructExpr *E,
945 const LocationContext *LCtx);
946
947 static ProgramStateRef
948 removeStateTraitsUsedForArrayEvaluation(ProgramStateRef State,
949 const CXXConstructExpr *E,
950 const LocationContext *LCtx);
951
952 /// Store the location of a C++ object corresponding to a statement
953 /// until the statement is actually encountered. For example, if a DeclStmt
954 /// has CXXConstructExpr as its initializer, the object would be considered
955 /// to be "under construction" between CXXConstructExpr and DeclStmt.
956 /// This allows, among other things, to keep bindings to variable's fields
957 /// made within the constructor alive until its declaration actually
958 /// goes into scope.
959 static ProgramStateRef
960 addObjectUnderConstruction(ProgramStateRef State,
961 const ConstructionContextItem &Item,
962 const LocationContext *LC, SVal V);
963
964 /// Mark the object sa fully constructed, cleaning up the state trait
965 /// that tracks objects under construction.
966 static ProgramStateRef
967 finishObjectConstruction(ProgramStateRef State,
968 const ConstructionContextItem &Item,
969 const LocationContext *LC);
970
971 /// If the given expression corresponds to a temporary that was used for
972 /// passing into an elidable copy/move constructor and that constructor
973 /// was actually elided, track that we also need to elide the destructor.
974 static ProgramStateRef elideDestructor(ProgramStateRef State,
975 const CXXBindTemporaryExpr *BTE,
976 const LocationContext *LC);
977
978 /// Stop tracking the destructor that corresponds to an elided constructor.
979 static ProgramStateRef
980 cleanupElidedDestructor(ProgramStateRef State,
981 const CXXBindTemporaryExpr *BTE,
982 const LocationContext *LC);
983
984 /// Returns true if the given expression corresponds to a temporary that
985 /// was constructed for passing into an elidable copy/move constructor
986 /// and that constructor was actually elided.
987 static bool isDestructorElided(ProgramStateRef State,
988 const CXXBindTemporaryExpr *BTE,
989 const LocationContext *LC);
990
991 /// Check if all objects under construction have been fully constructed
992 /// for the given context range (including FromLC, not including ToLC).
993 /// This is useful for assertions. Also checks if elided destructors
994 /// were cleaned up.
995 static bool areAllObjectsFullyConstructed(ProgramStateRef State,
996 const LocationContext *FromLC,
997 const LocationContext *ToLC);
998};
999
1000/// Traits for storing the call processing policy inside GDM.
1001/// The GDM stores the corresponding CallExpr pointer.
1002// FIXME: This does not use the nice trait macros because it must be accessible
1003// from multiple translation units.
1005template <>
1007 public ProgramStatePartialTrait<const void*> {
1008 static void *GDMIndex();
1009};
1010
1011} // namespace ento
1012
1013} // namespace clang
1014
1015#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_EXPRENGINE_H
#define V(N, I)
Definition: ASTContext.h:3443
BoundNodesTreeBuilder Nodes
DynTypedNode Node
StringRef P
const Decl * D
Expr * E
enum clang::sema::@1718::IndirectLocalPathEntry::EntryKind Kind
StringRef Filename
Definition: Format.cpp:3032
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:188
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:5752
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2718
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6678
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3909
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:6414
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
Definition: CFG.h:417
Represents C++ object destructor implicitly generated for base object in destructor.
Definition: CFG.h:468
Represents a single basic block in a source-level CFG.
Definition: CFG.h:604
ElementRefImpl< true > ConstCFGElementRef
Definition: CFG.h:915
Represents C++ object destructor generated from a call to delete.
Definition: CFG.h:442
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:366
Represents C++ base or member initializer from constructor's initialization list.
Definition: CFG.h:227
Represents C++ object destructor implicitly generated for member object in destructor.
Definition: CFG.h:489
Represents C++ object destructor implicitly generated at the end of full expression for temporary obj...
Definition: CFG.h:510
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1491
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1546
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2498
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1737
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2241
Represents the this expression in C++.
Definition: ExprCXX.h:1152
Represents a point when we begin processing an inlined call.
Definition: ProgramPoint.h:628
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2874
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3547
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3477
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:1519
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
This represents one expression.
Definition: Expr.h:110
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:3286
Describes an C or C++ initializer list.
Definition: Expr.h:5088
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1954
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
const Decl * getDecl() const
virtual bool inTopFrame() const
This represents a Microsoft inline-assembly statement extension.
Definition: Stmt.h:3509
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4734
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3236
This represents a decl that may have a name.
Definition: Decl.h:253
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:549
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:941
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2519
ProgramPoints can be "tagged" as representing points specific to a given analysis entity.
Definition: ProgramPoint.h:38
A (possibly-)qualified type.
Definition: Type.h:929
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3046
Stmt - This represents one statement.
Definition: Stmt.h:84
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2622
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2232
This class is used for tools that requires cross translation unit capability.
ASTContext & getASTContext() override
AnalysisDeclContextManager & getAnalysisDeclContextManager()
CheckerManager * getCheckerManager() const
BugReporter is a utility class for generating PathDiagnostics for analysis.
Definition: BugReporter.h:585
void setAnalysisEntryPoint(const Decl *EntryPoint)
Definition: BugReporter.h:632
Represents an abstract call to a function or method along a particular path.
Definition: CallEvent.h:153
CoreEngine - Implements the core logic of the graph-reachability analysis.
Definition: CoreEngine.h:50
DataTag::Factory & getDataTags()
Definition: CoreEngine.h:187
WorkList * getCTUWorkList() const
Definition: CoreEngine.h:165
bool wasBlocksExhausted() const
Definition: CoreEngine.h:153
WorkList * getWorkList() const
Definition: CoreEngine.h:164
bool ExecuteWorkList(const LocationContext *L, unsigned Steps, ProgramStateRef InitState)
ExecuteWorkList - Run the worklist algorithm for a maximum number of steps.
Definition: CoreEngine.cpp:88
bool hasWorkRemaining() const
Definition: CoreEngine.h:154
roots_iterator roots_end()
roots_iterator roots_begin()
void processEndOfFunction(NodeBuilderContext &BC, ExplodedNode *Pred, const ReturnStmt *RS=nullptr)
Called by CoreEngine.
void VisitBinaryOperator(const BinaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitBinaryOperator - Transfer function logic for binary operators.
Definition: ExprEngineC.cpp:40
ProgramStateManager & getStateManager()
Definition: ExprEngine.h:414
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 VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitGuardedExpr - Transfer function logic for ?, __builtin_choose.
void processCallEnter(NodeBuilderContext &BC, CallEnter CE, ExplodedNode *Pred)
Generate the entry node of the callee.
void processBeginOfFunction(NodeBuilderContext &BC, ExplodedNode *Pred, ExplodedNodeSet &Dst, const BlockEdge &L)
Called by CoreEngine.
void VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitCast - Transfer function logic for all casts (implicit and explicit).
void removeDead(ExplodedNode *Node, ExplodedNodeSet &Out, const Stmt *ReferenceStmt, const LocationContext *LC, const Stmt *DiagnosticStmt=nullptr, ProgramPoint::Kind K=ProgramPoint::PreStmtPurgeDeadSymbolsKind)
Run the analyzer's garbage collection - remove dead symbols and bindings from the state.
BasicValueFactory & getBasicVals()
Definition: ExprEngine.h:423
void VisitLogicalExpr(const BinaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitLogicalExpr - Transfer function logic for '&&', '||'.
std::pair< ProgramStateRef, SVal > handleConstructionContext(const Expr *E, ProgramStateRef State, const NodeBuilderContext *BldrCtx, const LocationContext *LCtx, const ConstructionContext *CC, EvalCallOptions &CallOpts, unsigned Idx=0)
A convenient wrapper around computeObjectUnderConstruction and updateObjectsUnderConstruction.
Definition: ExprEngine.h:741
void VisitCXXDestructor(QualType ObjectType, const MemRegion *Dest, const Stmt *S, bool IsBaseDtor, ExplodedNode *Pred, ExplodedNodeSet &Dst, EvalCallOptions &Options)
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:437
SVal evalBinOp(ProgramStateRef ST, BinaryOperator::Opcode Op, SVal LHS, SVal RHS, QualType T)
Definition: ExprEngine.h:604
void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
ProgramStateRef processRegionChange(ProgramStateRef state, const MemRegion *MR, const LocationContext *LCtx)
Definition: ExprEngine.h:403
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.
ProgramStateRef getInitialState(const LocationContext *InitLoc)
getInitialState - Return the initial state used for the root vertex in the ExplodedGraph.
Definition: ExprEngine.cpp:244
void VisitLvalObjCIvarRefExpr(const ObjCIvarRefExpr *DR, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Transfer function logic for computing the lvalue of an Objective-C ivar.
static bool hasMoreIteration(ProgramStateRef State, const ObjCForCollectionStmt *O, const LocationContext *LC)
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.
ProgramStateRef handleLValueBitCast(ProgramStateRef state, const Expr *Ex, const LocationContext *LCtx, QualType T, QualType ExTy, const CastExpr *CastE, StmtNodeBuilder &Bldr, ExplodedNode *Pred)
void VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitMSAsmStmt - Transfer function logic for MS inline asm.
static std::optional< SVal > getObjectUnderConstruction(ProgramStateRef State, const ConstructionContextItem &Item, const LocationContext *LC)
By looking at a certain item that may be potentially part of an object's ConstructionContext,...
Definition: ExprEngine.cpp:603
CFGElement getCurrentCFGElement()
Return the CFG element corresponding to the worklist element that is currently being processed by Exp...
Definition: ExprEngine.h:690
std::string DumpGraph(bool trim=false, StringRef Filename="")
Dump graph to the specified filename.
bool hasWorkRemaining() const
Definition: ExprEngine.h:435
void printJson(raw_ostream &Out, ProgramStateRef State, const LocationContext *LCtx, const char *NL, unsigned int Space, bool IsDot) const
printJson - Called by ProgramStateManager to print checker-specific data.
Definition: ExprEngine.cpp:939
virtual ~ExprEngine()=default
InliningModes
The modes of inlining, which override the default analysis-wide settings.
Definition: ExprEngine.h:129
@ Inline_Minimal
Do minimal inlining of callees.
Definition: ExprEngine.h:134
@ Inline_Regular
Follow the default settings for inlining callees.
Definition: ExprEngine.h:131
ProgramStateRef processPointerEscapedOnBind(ProgramStateRef State, ArrayRef< std::pair< SVal, SVal > > LocAndVals, const LocationContext *LCtx, PointerEscapeKind Kind, const CallEvent *Call)
Call PointerEscape callback when a value escapes as a result of bind.
SVal computeObjectUnderConstruction(const Expr *E, ProgramStateRef State, const NodeBuilderContext *BldrCtx, const LocationContext *LCtx, const ConstructionContext *CC, EvalCallOptions &CallOpts, unsigned Idx=0)
Find location of the object that is being constructed by a given constructor.
const LocationContext * getRootLocationContext() const
Definition: ExprEngine.h:224
static ProgramStateRef removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O, const LocationContext *LC)
const ExplodedGraph & getGraph() const
Definition: ExprEngine.h:257
ProgramStateRef processAssume(ProgramStateRef state, SVal cond, bool assumption)
evalAssume - Callback function invoked by the ConstraintManager when making assumptions about state v...
Definition: ExprEngine.cpp:667
AnalysisDeclContextManager & getAnalysisDeclContextManager()
Definition: ExprEngine.h:200
void evalEagerlyAssumeBifurcation(ExplodedNodeSet &Dst, ExplodedNodeSet &Src, const Expr *Ex)
evalEagerlyAssumeBifurcation - Given the nodes in 'Src', eagerly assume concrete boolean values for '...
static std::optional< unsigned > getIndexOfElementToConstruct(ProgramStateRef State, const CXXConstructExpr *E, const LocationContext *LCtx)
Retreives which element is being constructed in a non-POD type array.
Definition: ExprEngine.cpp:513
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 VisitCallExpr(const CallExpr *CE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitCall - Transfer function for function calls.
ASTContext & getContext() const
getContext - Return the ASTContext associated with this analysis.
Definition: ExprEngine.h:196
StoreManager & getStoreManager()
Definition: ExprEngine.h:416
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.
CFGBlock::ConstCFGElementRef getCFGElementRef() const
Definition: ExprEngine.h:229
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:210
void processCFGBlockEntrance(const BlockEdge &L, NodeBuilderWithSinks &nodeBuilder, ExplodedNode *Pred)
Called by CoreEngine when processing the entrance of a CFGBlock.
void VisitInitListExpr(const InitListExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
bool hasEmptyWorkList() const
Definition: ExprEngine.h:434
void processBranch(const Stmt *Condition, NodeBuilderContext &BuilderCtx, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF)
ProcessBranch - Called by CoreEngine.
ProgramStateRef processRegionChanges(ProgramStateRef state, const InvalidatedSymbols *invalidated, ArrayRef< const MemRegion * > ExplicitRegions, ArrayRef< const MemRegion * > Regions, const LocationContext *LCtx, const CallEvent *Call)
processRegionChanges - Called by ProgramStateManager whenever a change is made to the store.
Definition: ExprEngine.cpp:673
void ProcessStmt(const Stmt *S, ExplodedNode *Pred)
void ViewGraph(bool trim=false)
Visualize the ExplodedGraph created by executing the simulation.
static std::optional< unsigned > getPendingArrayDestruction(ProgramStateRef State, const LocationContext *LCtx)
Retreives which element is being destructed in a non-POD type array.
Definition: ExprEngine.cpp:532
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.
void processCFGElement(const CFGElement E, ExplodedNode *Pred, unsigned StmtIdx, NodeBuilderContext *Ctx)
processCFGElement - Called by CoreEngine.
Definition: ExprEngine.cpp:966
void processStaticInitializer(const DeclStmt *DS, NodeBuilderContext &BuilderCtx, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF)
Called by CoreEngine.
void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitUnaryExprOrTypeTraitExpr - Transfer function for sizeof.
cross_tu::CrossTranslationUnitContext * getCrossTranslationUnitContext()
Definition: ExprEngine.h:213
void ProcessLoopExit(const Stmt *S, ExplodedNode *Pred)
void processSwitch(SwitchNodeBuilder &builder)
ProcessSwitch - Called by CoreEngine.
void processEndWorklist()
Called by CoreEngine when the analysis worklist has terminated.
Definition: ExprEngine.cpp:960
CheckerManager & getCheckerManager() const
Definition: ExprEngine.h:204
SymbolManager & getSymbolManager()
Definition: ExprEngine.h:427
void VisitAtomicExpr(const AtomicExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitAtomicExpr - Transfer function for builtin atomic expressions.
bool wasBlocksExhausted() const
Definition: ExprEngine.h:433
MemRegionManager & getRegionManager()
Definition: ExprEngine.h:428
ProgramStateRef bindReturnValue(const CallEvent &Call, const LocationContext *LCtx, ProgramStateRef State)
Create a new state in which the call return value is binded to the call origin expression.
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 VisitCXXConstructExpr(const CXXConstructExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
ConstraintManager & getConstraintManager()
Definition: ExprEngine.h:418
DataTag::Factory & getDataTags()
Definition: ExprEngine.h:430
void processCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE, NodeBuilderContext &BldCtx, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF)
Called by CoreEngine.
void ProcessAutomaticObjDtor(const CFGAutomaticObjDtor D, ExplodedNode *Pred, ExplodedNodeSet &Dst)
const Stmt * getStmt() const
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 handleUOExtension(ExplodedNode *N, const UnaryOperator *U, StmtNodeBuilder &Bldr)
void removeDeadOnEndOfFunction(NodeBuilderContext &BC, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Remove dead bindings/symbols before exiting a function.
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:198
ExplodedGraph & getGraph()
Definition: ExprEngine.h:256
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.
SValBuilder & getSValBuilder()
Definition: ExprEngine.h:208
void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitArrayInitLoopExpr - Transfer function for array init loop.
ProgramStateRef updateObjectsUnderConstruction(SVal V, const Expr *E, ProgramStateRef State, const LocationContext *LCtx, const ConstructionContext *CC, const EvalCallOptions &CallOpts)
Update the program state with all the path-sensitive information that's necessary to perform construc...
bool ExecuteWorkList(const LocationContext *L, unsigned Steps=150000)
Returns true if there is still simulation state on the worklist.
Definition: ExprEngine.h:189
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 VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE, ExplodedNodeSet &PreVisit, ExplodedNodeSet &Dst)
void processIndirectGoto(IndirectGotoNodeBuilder &builder)
processIndirectGoto - Called by CoreEngine.
const NodeBuilderContext & getBuilderContext()
Definition: ExprEngine.h:217
static ProgramStateRef setWhetherHasMoreIteration(ProgramStateRef State, const ObjCForCollectionStmt *O, const LocationContext *LC, bool HasMoreIteraton)
Note whether this loop has any more iteratios to model.
static std::optional< unsigned > getPendingInitLoop(ProgramStateRef State, const CXXConstructExpr *E, const LocationContext *LCtx)
Retreives the size of the array in the pending ArrayInitLoopExpr.
Definition: ExprEngine.cpp:486
void ProcessNewAllocator(const CXXNewExpr *NE, ExplodedNode *Pred)
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:97
const CFGBlock * getBlock() const
Return the CFGBlock associated with this builder.
Definition: CoreEngine.h:209
This node builder keeps track of the generated sink nodes.
Definition: CoreEngine.h:339
This is the simplest builder which generates nodes in the ExplodedGraph.
Definition: CoreEngine.h:232
GRBugReporter is used for generating path-sensitive reports.
Definition: BugReporter.h:679
BasicValueFactory & getBasicVals()
Definition: ProgramState.h:543
ConstraintManager & getConstraintManager()
Definition: ProgramState.h:574
Information about invalidation for a particular region/symbol.
Definition: MemRegion.h:1629
SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, SVal lhs, SVal rhs, QualType type)
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition: SVals.h:56
This builder class is useful for generating nodes that resulted from visiting a statement.
Definition: CoreEngine.h:376
virtual bool hasWork() const =0
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
llvm::DenseSet< const Decl * > SetOfConstDecls
PointerEscapeKind
Describes the different reasons a pointer escapes during analysis.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
llvm::DenseSet< SymbolRef > InvalidatedSymbols
Definition: Store.h:51
The JSON file list parser is used to communicate input to InstallAPI.
BinaryOperatorKind
@ Result
The result type of a method or function.
const FunctionProtoType * T
Hints for figuring out of a call should be inlined during evalCall().
Definition: ExprEngine.h:97
bool IsTemporaryLifetimeExtendedViaAggregate
This call is a constructor for a temporary that is lifetime-extended by binding it to a reference-typ...
Definition: ExprEngine.h:112
bool IsTemporaryCtorOrDtor
This call is a constructor or a destructor of a temporary value.
Definition: ExprEngine.h:107
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:104
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:119
bool IsCtorOrDtorWithImproperlyModeledTargetRegion
This call is a constructor or a destructor for which we do not currently compute the this-region corr...
Definition: ExprEngine.h:100
Traits for storing the call processing policy inside GDM.
Definition: ExprEngine.h:1004