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
225 assert(G.getRoot());
226 return G.getRoot()->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).
284 void removeDead(ExplodedNode *Node, ExplodedNodeSet &Out,
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);
310 void ProcessDeleteDtor(const CFGDeleteDtor D,
311 ExplodedNode *Pred, ExplodedNodeSet &Dst);
312 void ProcessBaseDtor(const CFGBaseDtor D,
313 ExplodedNode *Pred, ExplodedNodeSet &Dst);
314 void ProcessMemberDtor(const CFGMemberDtor D,
315 ExplodedNode *Pred, ExplodedNodeSet &Dst);
317 ExplodedNode *Pred, ExplodedNodeSet &Dst);
318
319 /// Called by CoreEngine when processing the entrance of a CFGBlock.
320 void processCFGBlockEntrance(const BlockEdge &L, const BlockEntrance &BE,
321 NodeBuilder &Builder, ExplodedNode *Pred);
322
324 const BlockEntrance &Entrance,
325 ExplodedNode *Pred, ExplodedNodeSet &Dst);
326
327 /// ProcessBranch - Called by CoreEngine. Used to generate successor nodes by
328 /// processing the 'effects' of a branch condition. If the branch condition
329 /// is a loop condition, IterationsCompletedInLoop is the number of completed
330 /// iterations (otherwise it's std::nullopt).
331 void processBranch(const Stmt *Condition, NodeBuilderContext &BuilderCtx,
332 ExplodedNode *Pred, ExplodedNodeSet &Dst,
333 const CFGBlock *DstT, const CFGBlock *DstF,
334 std::optional<unsigned> IterationsCompletedInLoop);
335
336 /// Called by CoreEngine.
337 /// Used to generate successor nodes for temporary destructors depending
338 /// on whether the corresponding constructor was visited.
340 NodeBuilderContext &BldCtx,
341 ExplodedNode *Pred, ExplodedNodeSet &Dst,
342 const CFGBlock *DstT,
343 const CFGBlock *DstF);
344
345 /// Called by CoreEngine. Used to processing branching behavior
346 /// at static initializers.
348 NodeBuilderContext& BuilderCtx,
349 ExplodedNode *Pred,
350 ExplodedNodeSet &Dst,
351 const CFGBlock *DstT,
352 const CFGBlock *DstF);
353
354 /// processIndirectGoto - Called by CoreEngine. Used to generate successor
355 /// nodes by processing the 'effects' of a computed goto jump.
357 ExplodedNode *Pred);
358
359 /// ProcessSwitch - Called by CoreEngine. Used to generate successor
360 /// nodes by processing the 'effects' of a switch statement.
362 ExplodedNode *Pred, ExplodedNodeSet &Dst);
363
364 /// Called by CoreEngine. Used to notify checkers that processing a
365 /// function has begun. Called for both inlined and top-level functions.
367 ExplodedNode *Pred, ExplodedNodeSet &Dst,
368 const BlockEdge &L);
369
370 /// Called by CoreEngine. Used to notify checkers that processing a
371 /// function has ended. Called for both inlined and top-level functions.
373 ExplodedNode *Pred,
374 const ReturnStmt *RS = nullptr);
375
376 /// Remove dead bindings/symbols before exiting a function.
378 ExplodedNode *Pred,
379 ExplodedNodeSet &Dst);
380
381 /// Generate the entry node of the callee.
383 ExplodedNode *Pred);
384
385 /// Generate the sequence of nodes that simulate the call exit and the post
386 /// visit for CallExpr.
387 void processCallExit(ExplodedNode *Pred);
388
389 /// Called by CoreEngine when the analysis worklist has terminated.
390 void processEndWorklist();
391
392 /// evalAssume - Callback function invoked by the ConstraintManager when
393 /// making assumptions about state values.
395 bool assumption);
396
397 /// processRegionChanges - Called by ProgramStateManager whenever a change is made
398 /// to the store. Used to update checkers that track region values.
401 const InvalidatedSymbols *invalidated,
402 ArrayRef<const MemRegion *> ExplicitRegions,
404 const LocationContext *LCtx,
405 const CallEvent *Call);
406
407 inline ProgramStateRef
409 const MemRegion* MR,
410 const LocationContext *LCtx) {
411 return processRegionChanges(state, nullptr, MR, MR, LCtx, nullptr);
412 }
413
414 /// printJson - Called by ProgramStateManager to print checker-specific data.
415 void printJson(raw_ostream &Out, ProgramStateRef State,
416 const LocationContext *LCtx, const char *NL,
417 unsigned int Space, bool IsDot) const;
418
419 ProgramStateManager &getStateManager() { return StateMgr; }
420 const ProgramStateManager &getStateManager() const { return StateMgr; }
421
422 StoreManager &getStoreManager() { return StateMgr.getStoreManager(); }
424 return StateMgr.getStoreManager();
425 }
426
428 return StateMgr.getConstraintManager();
429 }
431 return StateMgr.getConstraintManager();
432 }
433
434 // FIXME: Remove when we migrate over to just using SValBuilder.
436 return StateMgr.getBasicVals();
437 }
438
439 SymbolManager &getSymbolManager() { return SymMgr; }
440 const SymbolManager &getSymbolManager() const { return SymMgr; }
442
443 DataTag::Factory &getDataTags() { return Engine.getDataTags(); }
444
445 // Functions for external checking of whether we have unfinished work.
446 bool wasBlocksExhausted() const { return Engine.wasBlocksExhausted(); }
447 bool hasEmptyWorkList() const { return !Engine.getWorkList()->hasWork(); }
448 bool hasWorkRemaining() const { return Engine.hasWorkRemaining(); }
449
450 const CoreEngine &getCoreEngine() const { return Engine; }
451
452public:
453 /// Visit - Transfer function logic for all statements. Dispatches to
454 /// other functions that handle specific kinds of statements.
455 void Visit(const Stmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst);
456
457 /// VisitArrayInitLoopExpr - Transfer function for array init loop.
459 ExplodedNodeSet &Dst);
460
461 /// VisitArraySubscriptExpr - Transfer function for array accesses.
463 ExplodedNode *Pred,
464 ExplodedNodeSet &Dst);
465
466 /// VisitGCCAsmStmt - Transfer function logic for inline asm.
467 void VisitGCCAsmStmt(const GCCAsmStmt *A, ExplodedNode *Pred,
468 ExplodedNodeSet &Dst);
469
470 /// VisitMSAsmStmt - Transfer function logic for MS inline asm.
471 void VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred,
472 ExplodedNodeSet &Dst);
473
474 /// VisitBlockExpr - Transfer function logic for BlockExprs.
475 void VisitBlockExpr(const BlockExpr *BE, ExplodedNode *Pred,
476 ExplodedNodeSet &Dst);
477
478 /// VisitLambdaExpr - Transfer function logic for LambdaExprs.
479 void VisitLambdaExpr(const LambdaExpr *LE, ExplodedNode *Pred,
480 ExplodedNodeSet &Dst);
481
482 /// VisitBinaryOperator - Transfer function logic for binary operators.
484 ExplodedNodeSet &Dst);
485
486
487 /// VisitCall - Transfer function for function calls.
488 void VisitCallExpr(const CallExpr *CE, ExplodedNode *Pred,
489 ExplodedNodeSet &Dst);
490
491 /// VisitCast - Transfer function logic for all casts (implicit and explicit).
492 void VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNode *Pred,
493 ExplodedNodeSet &Dst);
494
495 /// VisitCompoundLiteralExpr - Transfer function logic for compound literals.
497 ExplodedNode *Pred, ExplodedNodeSet &Dst);
498
499 /// Transfer function logic for DeclRefExprs and BlockDeclRefExprs.
500 void VisitCommonDeclRefExpr(const Expr *DR, const NamedDecl *D,
501 ExplodedNode *Pred, ExplodedNodeSet &Dst);
502
503 /// VisitDeclStmt - Transfer function logic for DeclStmts.
504 void VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred,
505 ExplodedNodeSet &Dst);
506
507 /// VisitGuardedExpr - Transfer function logic for ?, __builtin_choose
508 void VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R,
509 ExplodedNode *Pred, ExplodedNodeSet &Dst);
510
511 /// VisitAttributedStmt - Transfer function logic for AttributedStmt.
513 ExplodedNodeSet &Dst);
514
515 /// VisitLogicalExpr - Transfer function logic for '&&', '||'.
516 void VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
517 ExplodedNodeSet &Dst);
518
519 /// VisitMemberExpr - Transfer function for member expressions.
520 void VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred,
521 ExplodedNodeSet &Dst);
522
523 /// VisitAtomicExpr - Transfer function for builtin atomic expressions.
524 void VisitAtomicExpr(const AtomicExpr *E, ExplodedNode *Pred,
525 ExplodedNodeSet &Dst);
526
527 /// Transfer function logic for ObjCAtSynchronizedStmts.
529 ExplodedNode *Pred, ExplodedNodeSet &Dst);
530
531 /// Transfer function logic for computing the lvalue of an Objective-C ivar.
533 ExplodedNodeSet &Dst);
534
535 /// VisitObjCForCollectionStmt - Transfer function logic for
536 /// ObjCForCollectionStmt.
538 ExplodedNode *Pred, ExplodedNodeSet &Dst);
539
540 void VisitObjCMessage(const ObjCMessageExpr *ME, ExplodedNode *Pred,
541 ExplodedNodeSet &Dst);
542
543 /// VisitReturnStmt - Transfer function logic for return statements.
544 void VisitReturnStmt(const ReturnStmt *R, ExplodedNode *Pred,
545 ExplodedNodeSet &Dst);
546
547 /// VisitOffsetOfExpr - Transfer function for offsetof.
548 void VisitOffsetOfExpr(const OffsetOfExpr *Ex, ExplodedNode *Pred,
549 ExplodedNodeSet &Dst);
550
551 /// VisitUnaryExprOrTypeTraitExpr - Transfer function for sizeof.
553 ExplodedNode *Pred, ExplodedNodeSet &Dst);
554
555 /// VisitUnaryOperator - Transfer function logic for unary operators.
556 void VisitUnaryOperator(const UnaryOperator* B, ExplodedNode *Pred,
557 ExplodedNodeSet &Dst);
558
559 /// Handle ++ and -- (both pre- and post-increment).
561 ExplodedNode *Pred,
562 ExplodedNodeSet &Dst);
563
565 ExplodedNodeSet &PreVisit,
566 ExplodedNodeSet &Dst);
567
568 void VisitCXXCatchStmt(const CXXCatchStmt *CS, ExplodedNode *Pred,
569 ExplodedNodeSet &Dst);
570
571 void VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred,
572 ExplodedNodeSet & Dst);
573
575 ExplodedNodeSet &Dst);
576
578 ExplodedNode *Pred, ExplodedNodeSet &Dst);
579
580 void VisitCXXDestructor(QualType ObjectType, const MemRegion *Dest,
581 const Stmt *S, bool IsBaseDtor,
582 ExplodedNode *Pred, ExplodedNodeSet &Dst,
583 EvalCallOptions &Options);
584
585 void VisitCXXNewAllocatorCall(const CXXNewExpr *CNE,
586 ExplodedNode *Pred,
587 ExplodedNodeSet &Dst);
588
589 void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
590 ExplodedNodeSet &Dst);
591
593 ExplodedNodeSet &Dst);
594
595 /// Create a C++ temporary object for an rvalue.
597 ExplodedNode *Pred,
598 ExplodedNodeSet &Dst);
599
600 void ConstructInitList(const Expr *Source, ArrayRef<Expr *> Args,
601 bool IsTransparent, ExplodedNode *Pred,
602 ExplodedNodeSet &Dst);
603
604 /// evalEagerlyAssumeBifurcation - Given the nodes in 'Src', eagerly assume
605 /// concrete boolean values for 'Ex', storing the resulting nodes in 'Dst'.
607 const Expr *Ex);
608
609 bool didEagerlyAssumeBifurcateAt(ProgramStateRef State, const Expr *Ex) const;
610
611 static std::pair<const ProgramPointTag *, const ProgramPointTag *>
613
615 const LocationContext *LCtx, QualType T,
616 QualType ExTy, const CastExpr *CastE,
617 NodeBuilder &Bldr, ExplodedNode *Pred);
618
620 NodeBuilder &Bldr);
621
622public:
624 SVal LHS, SVal RHS, QualType T) {
625 return svalBuilder.evalBinOp(ST, Op, LHS, RHS, T);
626 }
627
628 /// Retreives which element is being constructed in a non-POD type array.
629 static std::optional<unsigned>
631 const LocationContext *LCtx);
632
633 /// Retreives which element is being destructed in a non-POD type array.
634 static std::optional<unsigned>
636 const LocationContext *LCtx);
637
638 /// Retreives the size of the array in the pending ArrayInitLoopExpr.
639 static std::optional<unsigned>
641 const LocationContext *LCtx);
642
643 /// By looking at a certain item that may be potentially part of an object's
644 /// ConstructionContext, retrieve such object's location. A particular
645 /// statement can be transparently passed as \p Item in most cases.
646 static std::optional<SVal>
648 const ConstructionContextItem &Item,
649 const LocationContext *LC);
650
651 /// Call PointerEscape callback when a value escapes as a result of bind.
653 ProgramStateRef State, ArrayRef<std::pair<SVal, SVal>> LocAndVals,
654 const LocationContext *LCtx, PointerEscapeKind Kind,
655 const CallEvent *Call);
656
657 /// Call PointerEscape callback when a value escapes as a result of
658 /// region invalidation.
659 /// \param[in] ITraits Specifies invalidation traits for regions/symbols.
661 ProgramStateRef State,
662 const InvalidatedSymbols *Invalidated,
663 ArrayRef<const MemRegion *> ExplicitRegions,
664 const CallEvent *Call,
666
667private:
668 /// evalBind - Handle the semantics of binding a value to a specific location.
669 /// This method is used by evalStore, VisitDeclStmt, and others.
670 void evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE, ExplodedNode *Pred,
671 SVal location, SVal Val, bool AtDeclInit = false,
672 const ProgramPoint *PP = nullptr);
673
676 SVal Loc, SVal Val,
677 const LocationContext *LCtx);
678
679public:
680 /// A simple wrapper when you only need to notify checkers of pointer-escape
681 /// of some values.
684 const CallEvent *Call = nullptr) const;
685
686 // FIXME: 'tag' should be removed, and a LocationContext should be used
687 // instead.
688 // FIXME: Comment on the meaning of the arguments, when 'St' may not
689 // be the same as Pred->state, and when 'location' may not be the
690 // same as state->getLValue(Ex).
691 /// Simulate a read of the result of Ex.
692 void evalLoad(ExplodedNodeSet &Dst,
693 const Expr *NodeEx, /* Eventually will be a CFGStmt */
694 const Expr *BoundExpr,
695 ExplodedNode *Pred,
697 SVal location,
698 const ProgramPointTag *tag = nullptr,
699 QualType LoadTy = QualType());
700
701 // FIXME: 'tag' should be removed, and a LocationContext should be used
702 // instead.
703 void evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, const Expr *StoreE,
704 ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val,
705 const ProgramPointTag *tag = nullptr);
706
707 /// Return the CFG element corresponding to the worklist element
708 /// that is currently being processed by ExprEngine.
710 return (*currBldrCtx->getBlock())[currStmtIdx];
711 }
712
713 /// Create a new state in which the call return value is binded to the
714 /// call origin expression.
716 const LocationContext *LCtx,
717 ProgramStateRef State);
718
719 /// Evaluate a call, running pre- and post-call checkers and allowing checkers
720 /// to be responsible for handling the evaluation of the call itself.
721 void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred,
722 const CallEvent &Call);
723
724 /// Default implementation of call evaluation.
726 const CallEvent &Call,
727 const EvalCallOptions &CallOpts = {});
728
729 /// Find location of the object that is being constructed by a given
730 /// constructor. This should ideally always succeed but due to not being
731 /// fully implemented it sometimes indicates that it failed via its
732 /// out-parameter CallOpts; in such cases a fake temporary region is
733 /// returned, which is better than nothing but does not represent
734 /// the actual behavior of the program. The Idx parameter is used if we
735 /// construct an array of objects. In that case it points to the index
736 /// of the continuous memory region.
737 /// E.g.:
738 /// For `int arr[4]` this index can be 0,1,2,3.
739 /// For `int arr2[3][3]` this index can be 0,1,...,7,8.
740 /// A multi-dimensional array is also a continuous memory location in a
741 /// row major order, so for arr[0][0] Idx is 0 and for arr[3][3] Idx is 8.
743 const NodeBuilderContext *BldrCtx,
744 const LocationContext *LCtx,
745 const ConstructionContext *CC,
746 EvalCallOptions &CallOpts,
747 unsigned Idx = 0);
748
749 /// Update the program state with all the path-sensitive information
750 /// that's necessary to perform construction of an object with a given
751 /// syntactic construction context. V and CallOpts have to be obtained from
752 /// computeObjectUnderConstruction() invoked with the same set of
753 /// the remaining arguments (E, State, LCtx, CC).
755 SVal V, const Expr *E, ProgramStateRef State, const LocationContext *LCtx,
756 const ConstructionContext *CC, const EvalCallOptions &CallOpts);
757
758 /// A convenient wrapper around computeObjectUnderConstruction
759 /// and updateObjectsUnderConstruction.
760 std::pair<ProgramStateRef, SVal> handleConstructionContext(
761 const Expr *E, ProgramStateRef State, const NodeBuilderContext *BldrCtx,
762 const LocationContext *LCtx, const ConstructionContext *CC,
763 EvalCallOptions &CallOpts, unsigned Idx = 0) {
764
765 SVal V = computeObjectUnderConstruction(E, State, BldrCtx, LCtx, CC,
766 CallOpts, Idx);
767 State = updateObjectsUnderConstruction(V, E, State, LCtx, CC, CallOpts);
768
769 return std::make_pair(State, V);
770 }
771
772private:
773 ProgramStateRef finishArgumentConstruction(ProgramStateRef State,
774 const CallEvent &Call);
775 void finishArgumentConstruction(ExplodedNodeSet &Dst, ExplodedNode *Pred,
776 const CallEvent &Call);
777
778 void evalLocation(ExplodedNodeSet &Dst,
779 const Stmt *NodeEx, /* This will eventually be a CFGStmt */
780 const Stmt *BoundEx,
781 ExplodedNode *Pred,
783 SVal location,
784 bool isLoad);
785
786 /// Count the stack depth and determine if the call is recursive.
787 void examineStackFrames(const Decl *D, const LocationContext *LCtx,
788 bool &IsRecursive, unsigned &StackDepth);
789
790 enum CallInlinePolicy {
791 CIP_Allowed,
792 CIP_DisallowedOnce,
793 CIP_DisallowedAlways
794 };
795
796 /// See if a particular call should be inlined, by only looking
797 /// at the call event and the current state of analysis.
798 CallInlinePolicy mayInlineCallKind(const CallEvent &Call,
799 const ExplodedNode *Pred,
800 AnalyzerOptions &Opts,
801 const EvalCallOptions &CallOpts);
802
803 /// See if the given AnalysisDeclContext is built for a function that we
804 /// should always inline simply because it's small enough.
805 /// Apart from "small" functions, we also have "large" functions
806 /// (cf. isLarge()), some of which are huge (cf. isHuge()), and we classify
807 /// the remaining functions as "medium".
808 bool isSmall(AnalysisDeclContext *ADC) const;
809
810 /// See if the given AnalysisDeclContext is built for a function that we
811 /// should inline carefully because it looks pretty large.
812 bool isLarge(AnalysisDeclContext *ADC) const;
813
814 /// See if the given AnalysisDeclContext is built for a function that we
815 /// should never inline because it's legit gigantic.
816 bool isHuge(AnalysisDeclContext *ADC) const;
817
818 /// See if the given AnalysisDeclContext is built for a function that we
819 /// should inline, just by looking at the declaration of the function.
820 bool mayInlineDecl(AnalysisDeclContext *ADC) const;
821
822 /// Checks our policies and decides whether the given call should be inlined.
823 bool shouldInlineCall(const CallEvent &Call, const Decl *D,
824 const ExplodedNode *Pred,
825 const EvalCallOptions &CallOpts = {});
826
827 /// Checks whether our policies allow us to inline a non-POD type array
828 /// construction.
829 bool shouldInlineArrayConstruction(const ProgramStateRef State,
830 const CXXConstructExpr *CE,
831 const LocationContext *LCtx);
832
833 /// Checks whether our policies allow us to inline a non-POD type array
834 /// destruction.
835 /// \param Size The size of the array.
836 bool shouldInlineArrayDestruction(uint64_t Size);
837
838 /// Prepares the program state for array destruction. If no error happens
839 /// the function binds a 'PendingArrayDestruction' entry to the state, which
840 /// it returns along with the index. If any error happens (we fail to read
841 /// the size, the index would be -1, etc.) the function will return the
842 /// original state along with an index of 0. The actual element count of the
843 /// array can be accessed by the optional 'ElementCountVal' parameter. \param
844 /// State The program state. \param Region The memory region where the array
845 /// is stored. \param ElementTy The type an element in the array. \param LCty
846 /// The location context. \param ElementCountVal A pointer to an optional
847 /// SVal. If specified, the size of the array will be returned in it. It can
848 /// be Unknown.
849 std::pair<ProgramStateRef, uint64_t> prepareStateForArrayDestruction(
850 const ProgramStateRef State, const MemRegion *Region,
851 const QualType &ElementTy, const LocationContext *LCtx,
852 SVal *ElementCountVal = nullptr);
853
854 /// Checks whether we construct an array of non-POD type, and decides if the
855 /// constructor should be inkoved once again.
856 bool shouldRepeatCtorCall(ProgramStateRef State, const CXXConstructExpr *E,
857 const LocationContext *LCtx);
858
859 void inlineCall(WorkList *WList, const CallEvent &Call, const Decl *D,
860 NodeBuilder &Bldr, ExplodedNode *Pred, ProgramStateRef State);
861
862 void ctuBifurcate(const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
863 ExplodedNode *Pred, ProgramStateRef State);
864
865 /// Returns true if the CTU analysis is running its second phase.
866 bool isSecondPhaseCTU() { return IsCTUEnabled && !Engine.getCTUWorkList(); }
867
868 /// Conservatively evaluate call by invalidating regions and binding
869 /// a conjured return value.
870 void conservativeEvalCall(const CallEvent &Call, NodeBuilder &Bldr,
871 ExplodedNode *Pred, ProgramStateRef State);
872
873 /// Either inline or process the call conservatively (or both), based
874 /// on DynamicDispatchBifurcation data.
875 void BifurcateCall(const MemRegion *BifurReg,
876 const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
877 ExplodedNode *Pred);
878
879 bool replayWithoutInlining(ExplodedNode *P, const LocationContext *CalleeLC);
880
881 /// Models a trivial copy or move constructor or trivial assignment operator
882 /// call with a simple bind.
883 void performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
884 const CallEvent &Call);
885
886 /// If the value of the given expression \p InitWithAdjustments is a NonLoc,
887 /// copy it into a new temporary object region, and replace the value of the
888 /// expression with that.
889 ///
890 /// If \p Result is provided, the new region will be bound to this expression
891 /// instead of \p InitWithAdjustments.
892 ///
893 /// Returns the temporary region with adjustments into the optional
894 /// OutRegionWithAdjustments out-parameter if a new region was indeed needed,
895 /// otherwise sets it to nullptr.
896 ProgramStateRef createTemporaryRegionIfNeeded(
897 ProgramStateRef State, const LocationContext *LC,
898 const Expr *InitWithAdjustments, const Expr *Result = nullptr,
899 const SubRegion **OutRegionWithAdjustments = nullptr);
900
901 /// Returns a region representing the `Idx`th element of a (possibly
902 /// multi-dimensional) array, for the purposes of element construction or
903 /// destruction.
904 ///
905 /// On return, \p Ty will be set to the base type of the array.
906 ///
907 /// If the type is not an array type at all, the original value is returned.
908 /// Otherwise the "IsArray" flag is set.
909 static SVal makeElementRegion(ProgramStateRef State, SVal LValue,
910 QualType &Ty, bool &IsArray, unsigned Idx = 0);
911
912 /// Common code that handles either a CXXConstructExpr or a
913 /// CXXInheritedCtorInitExpr.
914 void handleConstructor(const Expr *E, ExplodedNode *Pred,
915 ExplodedNodeSet &Dst);
916
917public:
918 /// Note whether this loop has any more iterations to model. These methods
919 // are essentially an interface for a GDM trait. Further reading in
920 /// ExprEngine::VisitObjCForCollectionStmt().
921 [[nodiscard]] static ProgramStateRef
923 const ObjCForCollectionStmt *O,
924 const LocationContext *LC, bool HasMoreIteraton);
925
926 [[nodiscard]] static ProgramStateRef
927 removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O,
928 const LocationContext *LC);
929
930 [[nodiscard]] static bool hasMoreIteration(ProgramStateRef State,
931 const ObjCForCollectionStmt *O,
932 const LocationContext *LC);
933
934private:
935 /// Assuming we construct an array of non-POD types, this method allows us
936 /// to store which element is to be constructed next.
937 static ProgramStateRef
938 setIndexOfElementToConstruct(ProgramStateRef State, const CXXConstructExpr *E,
939 const LocationContext *LCtx, unsigned Idx);
940
941 static ProgramStateRef
942 removeIndexOfElementToConstruct(ProgramStateRef State,
943 const CXXConstructExpr *E,
944 const LocationContext *LCtx);
945
946 /// Assuming we destruct an array of non-POD types, this method allows us
947 /// to store which element is to be destructed next.
948 static ProgramStateRef setPendingArrayDestruction(ProgramStateRef State,
949 const LocationContext *LCtx,
950 unsigned Idx);
951
952 static ProgramStateRef
953 removePendingArrayDestruction(ProgramStateRef State,
954 const LocationContext *LCtx);
955
956 /// Sets the size of the array in a pending ArrayInitLoopExpr.
957 static ProgramStateRef setPendingInitLoop(ProgramStateRef State,
958 const CXXConstructExpr *E,
959 const LocationContext *LCtx,
960 unsigned Idx);
961
962 static ProgramStateRef removePendingInitLoop(ProgramStateRef State,
963 const CXXConstructExpr *E,
964 const LocationContext *LCtx);
965
966 static ProgramStateRef
967 removeStateTraitsUsedForArrayEvaluation(ProgramStateRef State,
968 const CXXConstructExpr *E,
969 const LocationContext *LCtx);
970
971 /// Store the location of a C++ object corresponding to a statement
972 /// until the statement is actually encountered. For example, if a DeclStmt
973 /// has CXXConstructExpr as its initializer, the object would be considered
974 /// to be "under construction" between CXXConstructExpr and DeclStmt.
975 /// This allows, among other things, to keep bindings to variable's fields
976 /// made within the constructor alive until its declaration actually
977 /// goes into scope.
978 static ProgramStateRef
979 addObjectUnderConstruction(ProgramStateRef State,
980 const ConstructionContextItem &Item,
981 const LocationContext *LC, SVal V);
982
983 /// Mark the object as fully constructed, cleaning up the state trait
984 /// that tracks objects under construction.
985 static ProgramStateRef
986 finishObjectConstruction(ProgramStateRef State,
987 const ConstructionContextItem &Item,
988 const LocationContext *LC);
989
990 /// If the given expression corresponds to a temporary that was used for
991 /// passing into an elidable copy/move constructor and that constructor
992 /// was actually elided, track that we also need to elide the destructor.
993 static ProgramStateRef elideDestructor(ProgramStateRef State,
994 const CXXBindTemporaryExpr *BTE,
995 const LocationContext *LC);
996
997 /// Stop tracking the destructor that corresponds to an elided constructor.
998 static ProgramStateRef
999 cleanupElidedDestructor(ProgramStateRef State,
1000 const CXXBindTemporaryExpr *BTE,
1001 const LocationContext *LC);
1002
1003 /// Returns true if the given expression corresponds to a temporary that
1004 /// was constructed for passing into an elidable copy/move constructor
1005 /// and that constructor was actually elided.
1006 static bool isDestructorElided(ProgramStateRef State,
1007 const CXXBindTemporaryExpr *BTE,
1008 const LocationContext *LC);
1009
1010 /// Check if all objects under construction have been fully constructed
1011 /// for the given context range (including FromLC, not including ToLC).
1012 /// This is useful for assertions. Also checks if elided destructors
1013 /// were cleaned up.
1014 static bool areAllObjectsFullyConstructed(ProgramStateRef State,
1015 const LocationContext *FromLC,
1016 const LocationContext *ToLC);
1017};
1018
1019/// Traits for storing the call processing policy inside GDM.
1020/// The GDM stores the corresponding CallExpr pointer.
1021// FIXME: This does not use the nice trait macros because it must be accessible
1022// from multiple translation units.
1024template <>
1026 public ProgramStatePartialTrait<const void*> {
1027 static void *GDMIndex();
1028};
1029
1030} // namespace ento
1031
1032} // namespace clang
1033
1034#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:164
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:419
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:435
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:760
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:450
SVal evalBinOp(ProgramStateRef ST, BinaryOperator::Opcode Op, SVal LHS, SVal RHS, QualType T)
Definition ExprEngine.h:623
void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
ProgramStateRef processRegionChange(ProgramStateRef state, const MemRegion *MR, const LocationContext *LCtx)
Definition ExprEngine.h:408
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:440
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:709
std::string DumpGraph(bool trim=false, StringRef Filename="")
Dump graph to the specified filename.
bool hasWorkRemaining() const
Definition ExprEngine.h:448
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:224
static ProgramStateRef removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O, const LocationContext *LC)
const ExplodedGraph & getGraph() const
Definition ExprEngine.h:257
const StoreManager & getStoreManager() const
Definition ExprEngine.h:423
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:420
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:422
const ConstraintManager & getConstraintManager() const
Definition ExprEngine.h:430
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:447
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:229
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:439
void VisitAtomicExpr(const AtomicExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitAtomicExpr - Transfer function for builtin atomic expressions.
bool wasBlocksExhausted() const
Definition ExprEngine.h:446
MemRegionManager & getRegionManager()
Definition ExprEngine.h:441
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:427
DataTag::Factory & getDataTags()
Definition ExprEngine.h:443
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)
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:256
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:246
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.