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