clang 22.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;
90class ProgramState;
93class SymbolManager;
95
96/// Hints for figuring out of a call should be inlined during evalCall().
98 /// This call is a constructor or a destructor for which we do not currently
99 /// compute the this-region correctly.
101
102 /// This call is a constructor or a destructor for a single element within
103 /// an array, a part of array construction or destruction.
104 bool IsArrayCtorOrDtor = false;
105
106 /// This call is a constructor or a destructor of a temporary value.
108
109 /// This call is a constructor for a temporary that is lifetime-extended
110 /// by binding it to a reference-type field within an aggregate,
111 /// for example 'A { const C &c; }; A a = { C() };'
113
114 /// This call is a pre-C++17 elidable constructor that we failed to elide
115 /// because we failed to compute the target region into which
116 /// this constructor would have been ultimately elided. Analysis that
117 /// we perform in this case is still correct but it behaves differently,
118 /// as if copy elision is disabled.
120
122};
123
125 void anchor();
126
127public:
128 /// The modes of inlining, which override the default analysis-wide settings.
130 /// Follow the default settings for inlining callees.
132
133 /// Do minimal inlining of callees.
135 };
136
137private:
139 bool IsCTUEnabled;
140
141 AnalysisManager &AMgr;
142
143 AnalysisDeclContextManager &AnalysisDeclContexts;
144
145 CoreEngine Engine;
146
147 /// G - the simulation graph.
148 ExplodedGraph &G;
149
150 /// StateMgr - Object that manages the data for all created states.
151 ProgramStateManager StateMgr;
152
153 /// SymMgr - Object that manages the symbol information.
154 SymbolManager &SymMgr;
155
156 /// MRMgr - MemRegionManager object that creates memory regions.
157 MemRegionManager &MRMgr;
158
159 /// svalBuilder - SValBuilder object that creates SVals from expressions.
160 SValBuilder &svalBuilder;
161
162 unsigned int currStmtIdx = 0;
163 const NodeBuilderContext *currBldrCtx = nullptr;
164
165 /// Helper object to determine if an Objective-C message expression
166 /// implicitly never returns.
167 ObjCNoReturn ObjCNoRet;
168
169 /// The BugReporter associated with this engine. It is important that
170 /// this object be placed at the very end of member variables so that its
171 /// destructor is called before the rest of the ExprEngine is destroyed.
173
174 /// The functions which have been analyzed through inlining. This is owned by
175 /// AnalysisConsumer. It can be null.
176 SetOfConstDecls *VisitedCallees;
177
178 /// The flag, which specifies the mode of inlining for the engine.
179 InliningModes HowToInline;
180
181public:
183 SetOfConstDecls *VisitedCalleesIn,
184 FunctionSummariesTy *FS, InliningModes HowToInlineIn);
185
186 virtual ~ExprEngine() = default;
187
188 /// Returns true if there is still simulation state on the worklist.
189 bool ExecuteWorkList(const LocationContext *L, unsigned Steps = 150000) {
190 assert(L->inTopFrame());
191 BR.setAnalysisEntryPoint(L->getDecl());
192 return Engine.ExecuteWorkList(L, Steps, nullptr);
193 }
194
195 /// getContext - Return the ASTContext associated with this analysis.
196 ASTContext &getContext() const { return AMgr.getASTContext(); }
197
199 const AnalysisManager &getAnalysisManager() const { return AMgr; }
200
202 return AMgr.getAnalysisDeclContextManager();
203 }
204
206 return *AMgr.getCheckerManager();
207 }
208
209 SValBuilder &getSValBuilder() { return svalBuilder; }
210 const SValBuilder &getSValBuilder() const { return svalBuilder; }
211
212 BugReporter &getBugReporter() { return BR; }
213 const BugReporter &getBugReporter() const { return BR; }
214
217 return &CTU;
218 }
219
221 assert(currBldrCtx);
222 return *currBldrCtx;
223 }
224
225 const Stmt *getStmt() const;
226
228 assert(G.getRoot());
229 return G.getRoot()->getLocation().getLocationContext();
230 }
231
233 const CFGBlock *blockPtr = currBldrCtx ? currBldrCtx->getBlock() : nullptr;
234 return {blockPtr, currStmtIdx};
235 }
236
237 /// Dump graph to the specified filename.
238 /// If filename is empty, generate a temporary one.
239 /// \return The filename the graph is written into.
240 std::string DumpGraph(bool trim = false, StringRef Filename="");
241
242 /// Dump the graph consisting of the given nodes to a specified filename.
243 /// Generate a temporary filename if it's not provided.
244 /// \return The filename the graph is written into.
246 StringRef Filename = "");
247
248 /// Visualize the ExplodedGraph created by executing the simulation.
249 void ViewGraph(bool trim = false);
250
251 /// Visualize a trimmed ExplodedGraph that only contains paths to the given
252 /// nodes.
254
255 /// getInitialState - Return the initial state used for the root vertex
256 /// in the ExplodedGraph.
258
259 ExplodedGraph &getGraph() { return G; }
260 const ExplodedGraph &getGraph() const { return G; }
261
262 /// Run the analyzer's garbage collection - remove dead symbols and
263 /// bindings from the state.
264 ///
265 /// Checkers can participate in this process with two callbacks:
266 /// \c checkLiveSymbols and \c checkDeadSymbols. See the CheckerDocumentation
267 /// class for more information.
268 ///
269 /// \param Node The predecessor node, from which the processing should start.
270 /// \param Out The returned set of output nodes.
271 /// \param ReferenceStmt The statement which is about to be processed.
272 /// Everything needed for this statement should be considered live.
273 /// A null statement means that everything in child LocationContexts
274 /// is dead.
275 /// \param LC The location context of the \p ReferenceStmt. A null location
276 /// context means that we have reached the end of analysis and that
277 /// all statements and local variables should be considered dead.
278 /// \param DiagnosticStmt Used as a location for any warnings that should
279 /// occur while removing the dead (e.g. leaks). By default, the
280 /// \p ReferenceStmt is used.
281 /// \param K Denotes whether this is a pre- or post-statement purge. This
282 /// must only be ProgramPoint::PostStmtPurgeDeadSymbolsKind if an
283 /// entire location context is being cleared, in which case the
284 /// \p ReferenceStmt must either be a ReturnStmt or \c NULL. Otherwise,
285 /// it must be ProgramPoint::PreStmtPurgeDeadSymbolsKind (the default)
286 /// and \p ReferenceStmt must be valid (non-null).
287 void removeDead(ExplodedNode *Node, ExplodedNodeSet &Out,
288 const Stmt *ReferenceStmt, const LocationContext *LC,
289 const Stmt *DiagnosticStmt = nullptr,
291
292 /// A tag to track convenience transitions, which can be removed at cleanup.
293 /// This tag applies to a node created after removeDead.
294 static const ProgramPointTag *cleanupNodeTag();
295
296 /// processCFGElement - Called by CoreEngine. Used to generate new successor
297 /// nodes by processing the 'effects' of a CFG element.
298 void processCFGElement(const CFGElement E, ExplodedNode *Pred,
299 unsigned StmtIdx, NodeBuilderContext *Ctx);
300
301 void ProcessStmt(const Stmt *S, ExplodedNode *Pred);
302
303 void ProcessLoopExit(const Stmt* S, ExplodedNode *Pred);
304
306
308
309 void ProcessNewAllocator(const CXXNewExpr *NE, ExplodedNode *Pred);
310
312 ExplodedNode *Pred, ExplodedNodeSet &Dst);
313 void ProcessDeleteDtor(const CFGDeleteDtor D,
314 ExplodedNode *Pred, ExplodedNodeSet &Dst);
315 void ProcessBaseDtor(const CFGBaseDtor D,
316 ExplodedNode *Pred, ExplodedNodeSet &Dst);
317 void ProcessMemberDtor(const CFGMemberDtor D,
318 ExplodedNode *Pred, ExplodedNodeSet &Dst);
320 ExplodedNode *Pred, ExplodedNodeSet &Dst);
321
322 /// Called by CoreEngine when processing the entrance of a CFGBlock.
324 NodeBuilderWithSinks &nodeBuilder,
325 ExplodedNode *Pred);
326
328 const BlockEntrance &Entrance,
329 ExplodedNode *Pred, ExplodedNodeSet &Dst);
330
331 /// ProcessBranch - Called by CoreEngine. Used to generate successor nodes by
332 /// processing the 'effects' of a branch condition. If the branch condition
333 /// is a loop condition, IterationsCompletedInLoop is the number of completed
334 /// iterations (otherwise it's std::nullopt).
335 void processBranch(const Stmt *Condition, NodeBuilderContext &BuilderCtx,
336 ExplodedNode *Pred, ExplodedNodeSet &Dst,
337 const CFGBlock *DstT, const CFGBlock *DstF,
338 std::optional<unsigned> IterationsCompletedInLoop);
339
340 /// Called by CoreEngine.
341 /// Used to generate successor nodes for temporary destructors depending
342 /// on whether the corresponding constructor was visited.
344 NodeBuilderContext &BldCtx,
345 ExplodedNode *Pred, ExplodedNodeSet &Dst,
346 const CFGBlock *DstT,
347 const CFGBlock *DstF);
348
349 /// Called by CoreEngine. Used to processing branching behavior
350 /// at static initializers.
352 NodeBuilderContext& BuilderCtx,
353 ExplodedNode *Pred,
354 ExplodedNodeSet &Dst,
355 const CFGBlock *DstT,
356 const CFGBlock *DstF);
357
358 /// processIndirectGoto - Called by CoreEngine. Used to generate successor
359 /// nodes by processing the 'effects' of a computed goto jump.
361
362 /// ProcessSwitch - Called by CoreEngine. Used to generate successor
363 /// nodes by processing the 'effects' of a switch statement.
364 void processSwitch(SwitchNodeBuilder& builder);
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 StmtNodeBuilder &Bldr,
620 ExplodedNode *Pred);
621
623 StmtNodeBuilder &Bldr);
624
625public:
627 SVal LHS, SVal RHS, QualType T) {
628 return svalBuilder.evalBinOp(ST, Op, LHS, RHS, T);
629 }
630
631 /// Retreives which element is being constructed in a non-POD type array.
632 static std::optional<unsigned>
634 const LocationContext *LCtx);
635
636 /// Retreives which element is being destructed in a non-POD type array.
637 static std::optional<unsigned>
639 const LocationContext *LCtx);
640
641 /// Retreives the size of the array in the pending ArrayInitLoopExpr.
642 static std::optional<unsigned>
644 const LocationContext *LCtx);
645
646 /// By looking at a certain item that may be potentially part of an object's
647 /// ConstructionContext, retrieve such object's location. A particular
648 /// statement can be transparently passed as \p Item in most cases.
649 static std::optional<SVal>
651 const ConstructionContextItem &Item,
652 const LocationContext *LC);
653
654 /// Call PointerEscape callback when a value escapes as a result of bind.
656 ProgramStateRef State, ArrayRef<std::pair<SVal, SVal>> LocAndVals,
657 const LocationContext *LCtx, PointerEscapeKind Kind,
658 const CallEvent *Call);
659
660 /// Call PointerEscape callback when a value escapes as a result of
661 /// region invalidation.
662 /// \param[in] ITraits Specifies invalidation traits for regions/symbols.
664 ProgramStateRef State,
665 const InvalidatedSymbols *Invalidated,
666 ArrayRef<const MemRegion *> ExplicitRegions,
667 const CallEvent *Call,
669
670private:
671 /// evalBind - Handle the semantics of binding a value to a specific location.
672 /// This method is used by evalStore, VisitDeclStmt, and others.
673 void evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE, ExplodedNode *Pred,
674 SVal location, SVal Val, bool AtDeclInit = false,
675 const ProgramPoint *PP = nullptr);
676
679 SVal Loc, SVal Val,
680 const LocationContext *LCtx);
681
682public:
683 /// A simple wrapper when you only need to notify checkers of pointer-escape
684 /// of some values.
687 const CallEvent *Call = nullptr) const;
688
689 // FIXME: 'tag' should be removed, and a LocationContext should be used
690 // instead.
691 // FIXME: Comment on the meaning of the arguments, when 'St' may not
692 // be the same as Pred->state, and when 'location' may not be the
693 // same as state->getLValue(Ex).
694 /// Simulate a read of the result of Ex.
695 void evalLoad(ExplodedNodeSet &Dst,
696 const Expr *NodeEx, /* Eventually will be a CFGStmt */
697 const Expr *BoundExpr,
698 ExplodedNode *Pred,
700 SVal location,
701 const ProgramPointTag *tag = nullptr,
702 QualType LoadTy = QualType());
703
704 // FIXME: 'tag' should be removed, and a LocationContext should be used
705 // instead.
706 void evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, const Expr *StoreE,
707 ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val,
708 const ProgramPointTag *tag = nullptr);
709
710 /// Return the CFG element corresponding to the worklist element
711 /// that is currently being processed by ExprEngine.
713 return (*currBldrCtx->getBlock())[currStmtIdx];
714 }
715
716 /// Create a new state in which the call return value is binded to the
717 /// call origin expression.
719 const LocationContext *LCtx,
720 ProgramStateRef State);
721
722 /// Evaluate a call, running pre- and post-call checkers and allowing checkers
723 /// to be responsible for handling the evaluation of the call itself.
724 void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred,
725 const CallEvent &Call);
726
727 /// Default implementation of call evaluation.
729 const CallEvent &Call,
730 const EvalCallOptions &CallOpts = {});
731
732 /// Find location of the object that is being constructed by a given
733 /// constructor. This should ideally always succeed but due to not being
734 /// fully implemented it sometimes indicates that it failed via its
735 /// out-parameter CallOpts; in such cases a fake temporary region is
736 /// returned, which is better than nothing but does not represent
737 /// the actual behavior of the program. The Idx parameter is used if we
738 /// construct an array of objects. In that case it points to the index
739 /// of the continuous memory region.
740 /// E.g.:
741 /// For `int arr[4]` this index can be 0,1,2,3.
742 /// For `int arr2[3][3]` this index can be 0,1,...,7,8.
743 /// A multi-dimensional array is also a continuous memory location in a
744 /// row major order, so for arr[0][0] Idx is 0 and for arr[3][3] Idx is 8.
746 const NodeBuilderContext *BldrCtx,
747 const LocationContext *LCtx,
748 const ConstructionContext *CC,
749 EvalCallOptions &CallOpts,
750 unsigned Idx = 0);
751
752 /// Update the program state with all the path-sensitive information
753 /// that's necessary to perform construction of an object with a given
754 /// syntactic construction context. V and CallOpts have to be obtained from
755 /// computeObjectUnderConstruction() invoked with the same set of
756 /// the remaining arguments (E, State, LCtx, CC).
758 SVal V, const Expr *E, ProgramStateRef State, const LocationContext *LCtx,
759 const ConstructionContext *CC, const EvalCallOptions &CallOpts);
760
761 /// A convenient wrapper around computeObjectUnderConstruction
762 /// and updateObjectsUnderConstruction.
763 std::pair<ProgramStateRef, SVal> handleConstructionContext(
764 const Expr *E, ProgramStateRef State, const NodeBuilderContext *BldrCtx,
765 const LocationContext *LCtx, const ConstructionContext *CC,
766 EvalCallOptions &CallOpts, unsigned Idx = 0) {
767
768 SVal V = computeObjectUnderConstruction(E, State, BldrCtx, LCtx, CC,
769 CallOpts, Idx);
770 State = updateObjectsUnderConstruction(V, E, State, LCtx, CC, CallOpts);
771
772 return std::make_pair(State, V);
773 }
774
775private:
776 ProgramStateRef finishArgumentConstruction(ProgramStateRef State,
777 const CallEvent &Call);
778 void finishArgumentConstruction(ExplodedNodeSet &Dst, ExplodedNode *Pred,
779 const CallEvent &Call);
780
781 void evalLocation(ExplodedNodeSet &Dst,
782 const Stmt *NodeEx, /* This will eventually be a CFGStmt */
783 const Stmt *BoundEx,
784 ExplodedNode *Pred,
786 SVal location,
787 bool isLoad);
788
789 /// Count the stack depth and determine if the call is recursive.
790 void examineStackFrames(const Decl *D, const LocationContext *LCtx,
791 bool &IsRecursive, unsigned &StackDepth);
792
793 enum CallInlinePolicy {
794 CIP_Allowed,
795 CIP_DisallowedOnce,
796 CIP_DisallowedAlways
797 };
798
799 /// See if a particular call should be inlined, by only looking
800 /// at the call event and the current state of analysis.
801 CallInlinePolicy mayInlineCallKind(const CallEvent &Call,
802 const ExplodedNode *Pred,
803 AnalyzerOptions &Opts,
804 const EvalCallOptions &CallOpts);
805
806 /// See if the given AnalysisDeclContext is built for a function that we
807 /// should always inline simply because it's small enough.
808 /// Apart from "small" functions, we also have "large" functions
809 /// (cf. isLarge()), some of which are huge (cf. isHuge()), and we classify
810 /// the remaining functions as "medium".
811 bool isSmall(AnalysisDeclContext *ADC) const;
812
813 /// See if the given AnalysisDeclContext is built for a function that we
814 /// should inline carefully because it looks pretty large.
815 bool isLarge(AnalysisDeclContext *ADC) const;
816
817 /// See if the given AnalysisDeclContext is built for a function that we
818 /// should never inline because it's legit gigantic.
819 bool isHuge(AnalysisDeclContext *ADC) const;
820
821 /// See if the given AnalysisDeclContext is built for a function that we
822 /// should inline, just by looking at the declaration of the function.
823 bool mayInlineDecl(AnalysisDeclContext *ADC) const;
824
825 /// Checks our policies and decides whether the given call should be inlined.
826 bool shouldInlineCall(const CallEvent &Call, const Decl *D,
827 const ExplodedNode *Pred,
828 const EvalCallOptions &CallOpts = {});
829
830 /// Checks whether our policies allow us to inline a non-POD type array
831 /// construction.
832 bool shouldInlineArrayConstruction(const ProgramStateRef State,
833 const CXXConstructExpr *CE,
834 const LocationContext *LCtx);
835
836 /// Checks whether our policies allow us to inline a non-POD type array
837 /// destruction.
838 /// \param Size The size of the array.
839 bool shouldInlineArrayDestruction(uint64_t Size);
840
841 /// Prepares the program state for array destruction. If no error happens
842 /// the function binds a 'PendingArrayDestruction' entry to the state, which
843 /// it returns along with the index. If any error happens (we fail to read
844 /// the size, the index would be -1, etc.) the function will return the
845 /// original state along with an index of 0. The actual element count of the
846 /// array can be accessed by the optional 'ElementCountVal' parameter. \param
847 /// State The program state. \param Region The memory region where the array
848 /// is stored. \param ElementTy The type an element in the array. \param LCty
849 /// The location context. \param ElementCountVal A pointer to an optional
850 /// SVal. If specified, the size of the array will be returned in it. It can
851 /// be Unknown.
852 std::pair<ProgramStateRef, uint64_t> prepareStateForArrayDestruction(
853 const ProgramStateRef State, const MemRegion *Region,
854 const QualType &ElementTy, const LocationContext *LCtx,
855 SVal *ElementCountVal = nullptr);
856
857 /// Checks whether we construct an array of non-POD type, and decides if the
858 /// constructor should be inkoved once again.
859 bool shouldRepeatCtorCall(ProgramStateRef State, const CXXConstructExpr *E,
860 const LocationContext *LCtx);
861
862 void inlineCall(WorkList *WList, const CallEvent &Call, const Decl *D,
863 NodeBuilder &Bldr, ExplodedNode *Pred, ProgramStateRef State);
864
865 void ctuBifurcate(const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
866 ExplodedNode *Pred, ProgramStateRef State);
867
868 /// Returns true if the CTU analysis is running its second phase.
869 bool isSecondPhaseCTU() { return IsCTUEnabled && !Engine.getCTUWorkList(); }
870
871 /// Conservatively evaluate call by invalidating regions and binding
872 /// a conjured return value.
873 void conservativeEvalCall(const CallEvent &Call, NodeBuilder &Bldr,
874 ExplodedNode *Pred, ProgramStateRef State);
875
876 /// Either inline or process the call conservatively (or both), based
877 /// on DynamicDispatchBifurcation data.
878 void BifurcateCall(const MemRegion *BifurReg,
879 const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
880 ExplodedNode *Pred);
881
882 bool replayWithoutInlining(ExplodedNode *P, const LocationContext *CalleeLC);
883
884 /// Models a trivial copy or move constructor or trivial assignment operator
885 /// call with a simple bind.
886 void performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
887 const CallEvent &Call);
888
889 /// If the value of the given expression \p InitWithAdjustments is a NonLoc,
890 /// copy it into a new temporary object region, and replace the value of the
891 /// expression with that.
892 ///
893 /// If \p Result is provided, the new region will be bound to this expression
894 /// instead of \p InitWithAdjustments.
895 ///
896 /// Returns the temporary region with adjustments into the optional
897 /// OutRegionWithAdjustments out-parameter if a new region was indeed needed,
898 /// otherwise sets it to nullptr.
899 ProgramStateRef createTemporaryRegionIfNeeded(
900 ProgramStateRef State, const LocationContext *LC,
901 const Expr *InitWithAdjustments, const Expr *Result = nullptr,
902 const SubRegion **OutRegionWithAdjustments = nullptr);
903
904 /// Returns a region representing the `Idx`th element of a (possibly
905 /// multi-dimensional) array, for the purposes of element construction or
906 /// destruction.
907 ///
908 /// On return, \p Ty will be set to the base type of the array.
909 ///
910 /// If the type is not an array type at all, the original value is returned.
911 /// Otherwise the "IsArray" flag is set.
912 static SVal makeElementRegion(ProgramStateRef State, SVal LValue,
913 QualType &Ty, bool &IsArray, unsigned Idx = 0);
914
915 /// Common code that handles either a CXXConstructExpr or a
916 /// CXXInheritedCtorInitExpr.
917 void handleConstructor(const Expr *E, ExplodedNode *Pred,
918 ExplodedNodeSet &Dst);
919
920public:
921 /// Note whether this loop has any more iterations to model. These methods
922 // are essentially an interface for a GDM trait. Further reading in
923 /// ExprEngine::VisitObjCForCollectionStmt().
924 [[nodiscard]] static ProgramStateRef
926 const ObjCForCollectionStmt *O,
927 const LocationContext *LC, bool HasMoreIteraton);
928
929 [[nodiscard]] static ProgramStateRef
930 removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O,
931 const LocationContext *LC);
932
933 [[nodiscard]] static bool hasMoreIteration(ProgramStateRef State,
934 const ObjCForCollectionStmt *O,
935 const LocationContext *LC);
936
937private:
938 /// Assuming we construct an array of non-POD types, this method allows us
939 /// to store which element is to be constructed next.
940 static ProgramStateRef
941 setIndexOfElementToConstruct(ProgramStateRef State, const CXXConstructExpr *E,
942 const LocationContext *LCtx, unsigned Idx);
943
944 static ProgramStateRef
945 removeIndexOfElementToConstruct(ProgramStateRef State,
946 const CXXConstructExpr *E,
947 const LocationContext *LCtx);
948
949 /// Assuming we destruct an array of non-POD types, this method allows us
950 /// to store which element is to be destructed next.
951 static ProgramStateRef setPendingArrayDestruction(ProgramStateRef State,
952 const LocationContext *LCtx,
953 unsigned Idx);
954
955 static ProgramStateRef
956 removePendingArrayDestruction(ProgramStateRef State,
957 const LocationContext *LCtx);
958
959 /// Sets the size of the array in a pending ArrayInitLoopExpr.
960 static ProgramStateRef setPendingInitLoop(ProgramStateRef State,
961 const CXXConstructExpr *E,
962 const LocationContext *LCtx,
963 unsigned Idx);
964
965 static ProgramStateRef removePendingInitLoop(ProgramStateRef State,
966 const CXXConstructExpr *E,
967 const LocationContext *LCtx);
968
969 static ProgramStateRef
970 removeStateTraitsUsedForArrayEvaluation(ProgramStateRef State,
971 const CXXConstructExpr *E,
972 const LocationContext *LCtx);
973
974 /// Store the location of a C++ object corresponding to a statement
975 /// until the statement is actually encountered. For example, if a DeclStmt
976 /// has CXXConstructExpr as its initializer, the object would be considered
977 /// to be "under construction" between CXXConstructExpr and DeclStmt.
978 /// This allows, among other things, to keep bindings to variable's fields
979 /// made within the constructor alive until its declaration actually
980 /// goes into scope.
981 static ProgramStateRef
982 addObjectUnderConstruction(ProgramStateRef State,
983 const ConstructionContextItem &Item,
984 const LocationContext *LC, SVal V);
985
986 /// Mark the object as fully constructed, cleaning up the state trait
987 /// that tracks objects under construction.
988 static ProgramStateRef
989 finishObjectConstruction(ProgramStateRef State,
990 const ConstructionContextItem &Item,
991 const LocationContext *LC);
992
993 /// If the given expression corresponds to a temporary that was used for
994 /// passing into an elidable copy/move constructor and that constructor
995 /// was actually elided, track that we also need to elide the destructor.
996 static ProgramStateRef elideDestructor(ProgramStateRef State,
997 const CXXBindTemporaryExpr *BTE,
998 const LocationContext *LC);
999
1000 /// Stop tracking the destructor that corresponds to an elided constructor.
1001 static ProgramStateRef
1002 cleanupElidedDestructor(ProgramStateRef State,
1003 const CXXBindTemporaryExpr *BTE,
1004 const LocationContext *LC);
1005
1006 /// Returns true if the given expression corresponds to a temporary that
1007 /// was constructed for passing into an elidable copy/move constructor
1008 /// and that constructor was actually elided.
1009 static bool isDestructorElided(ProgramStateRef State,
1010 const CXXBindTemporaryExpr *BTE,
1011 const LocationContext *LC);
1012
1013 /// Check if all objects under construction have been fully constructed
1014 /// for the given context range (including FromLC, not including ToLC).
1015 /// This is useful for assertions. Also checks if elided destructors
1016 /// were cleaned up.
1017 static bool areAllObjectsFullyConstructed(ProgramStateRef State,
1018 const LocationContext *FromLC,
1019 const LocationContext *ToLC);
1020};
1021
1022/// Traits for storing the call processing policy inside GDM.
1023/// The GDM stores the corresponding CallExpr pointer.
1024// FIXME: This does not use the nice trait macros because it must be accessible
1025// from multiple translation units.
1027template <>
1029 public ProgramStatePartialTrait<const void*> {
1030 static void *GDMIndex();
1031};
1032
1033} // namespace ento
1034
1035} // namespace clang
1036
1037#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:188
AnalysisDeclContext contains the context data for the function, method or block under analysis.
Stores options for the analyzer from the command line.
Represents a loop initializing the elements of an array.
Definition Expr.h:5904
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2723
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6816
Represents an attribute applied to a statement.
Definition Stmt.h:2203
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:3974
BinaryOperatorKind Opcode
Definition Expr.h:3979
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6560
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
Definition CFG.h:418
Represents C++ object destructor implicitly generated for base object in destructor.
Definition CFG.h:469
Represents a single basic block in a source-level CFG.
Definition CFG.h:605
Represents C++ object destructor generated from a call to delete.
Definition CFG.h:443
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:367
Represents C++ base or member initializer from constructor's initialization list.
Definition CFG.h:228
Represents C++ object destructor implicitly generated for member object in destructor.
Definition CFG.h:490
Represents C++ object destructor implicitly generated at the end of full expression for temporary obj...
Definition CFG.h:511
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:2620
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1753
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2349
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:2879
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3612
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3541
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:1611
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:3395
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h:1970
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:3614
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4914
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3300
This represents a decl that may have a name.
Definition Decl.h:273
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:548
An expression that sends a message to the given Objective-C object or class.
Definition ExprObjC.h:940
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2529
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:3160
Stmt - This represents one statement.
Definition Stmt.h:85
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2627
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2246
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:173
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 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:763
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:626
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.
ProgramStateRef handleLValueBitCast(ProgramStateRef state, const Expr *Ex, const LocationContext *LCtx, QualType T, QualType ExTy, const CastExpr *CastE, StmtNodeBuilder &Bldr, ExplodedNode *Pred)
void VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitMSAsmStmt - Transfer function logic for MS inline asm.
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:712
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:129
@ Inline_Minimal
Do minimal inlining of callees.
Definition ExprEngine.h:134
@ Inline_Regular
Follow the default settings for inlining callees.
Definition ExprEngine.h:131
ProgramStateRef processPointerEscapedOnBind(ProgramStateRef State, ArrayRef< std::pair< SVal, SVal > > LocAndVals, const LocationContext *LCtx, PointerEscapeKind Kind, const CallEvent *Call)
Call PointerEscape callback when a value escapes as a result of bind.
SVal computeObjectUnderConstruction(const Expr *E, ProgramStateRef State, const NodeBuilderContext *BldrCtx, const LocationContext *LCtx, const ConstructionContext *CC, EvalCallOptions &CallOpts, unsigned Idx=0)
Find location of the object that is being constructed by a given constructor.
const LocationContext * getRootLocationContext() const
Definition ExprEngine.h:227
static ProgramStateRef removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O, const LocationContext *LC)
const ExplodedGraph & getGraph() const
Definition ExprEngine.h:260
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:201
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 VisitBlockExpr(const BlockExpr *BE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitBlockExpr - Transfer function logic for BlockExprs.
void ProcessBaseDtor(const CFGBaseDtor D, ExplodedNode *Pred, ExplodedNodeSet &Dst)
static std::pair< const ProgramPointTag *, const ProgramPointTag * > getEagerlyAssumeBifurcationTags()
void VisitIncrementDecrementOperator(const UnaryOperator *U, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Handle ++ and – (both pre- and post-increment).
void VisitCallExpr(const CallExpr *CE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitCall - Transfer function for function calls.
ASTContext & getContext() const
getContext - Return the ASTContext associated with this analysis.
Definition ExprEngine.h:196
StoreManager & getStoreManager()
Definition ExprEngine.h: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:212
void processCFGBlockEntrance(const BlockEdge &L, NodeBuilderWithSinks &nodeBuilder, ExplodedNode *Pred)
Called by CoreEngine when processing the entrance of a CFGBlock.
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:232
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 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:216
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 processSwitch(SwitchNodeBuilder &builder)
ProcessSwitch - Called by CoreEngine.
void processEndWorklist()
Called by CoreEngine when the analysis worklist has terminated.
CheckerManager & getCheckerManager() const
Definition ExprEngine.h:205
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:199
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 handleUOExtension(ExplodedNode *N, const UnaryOperator *U, StmtNodeBuilder &Bldr)
void removeDeadOnEndOfFunction(NodeBuilderContext &BC, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Remove dead bindings/symbols before exiting a function.
void Visit(const Stmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Visit - Transfer function logic for all statements.
void defaultEvalCall(NodeBuilder &B, ExplodedNode *Pred, const CallEvent &Call, const EvalCallOptions &CallOpts={})
Default implementation of call evaluation.
AnalysisManager & getAnalysisManager()
Definition ExprEngine.h:198
ExplodedGraph & getGraph()
Definition ExprEngine.h:259
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:213
SValBuilder & getSValBuilder()
Definition ExprEngine.h:209
void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitArrayInitLoopExpr - Transfer function for array init loop.
ProgramStateRef updateObjectsUnderConstruction(SVal V, const Expr *E, ProgramStateRef State, const LocationContext *LCtx, const ConstructionContext *CC, const EvalCallOptions &CallOpts)
Update the program state with all the path-sensitive information that's necessary to perform construc...
bool ExecuteWorkList(const LocationContext *L, unsigned Steps=150000)
Returns true if there is still simulation state on the worklist.
Definition ExprEngine.h:189
void evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, const Expr *StoreE, ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val, const ProgramPointTag *tag=nullptr)
evalStore - Handle the semantics of a store via an assignment.
void VisitAttributedStmt(const AttributedStmt *A, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitAttributedStmt - Transfer function logic for AttributedStmt.
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE, ExplodedNodeSet &PreVisit, ExplodedNodeSet &Dst)
void processIndirectGoto(IndirectGotoNodeBuilder &builder)
processIndirectGoto - Called by CoreEngine.
const NodeBuilderContext & getBuilderContext()
Definition ExprEngine.h:220
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:210
void ProcessNewAllocator(const CXXNewExpr *NE, ExplodedNode *Pred)
MemRegion - The root abstract class for all memory regions.
Definition MemRegion.h:98
This node builder keeps track of the generated sink nodes.
Definition CoreEngine.h:347
This is the simplest builder which generates nodes in the ExplodedGraph.
Definition CoreEngine.h:240
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
This builder class is useful for generating nodes that resulted from visiting a statement.
Definition CoreEngine.h:384
Definition ARM.cpp:1134
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:1199
@ Result
The result type of a method or function.
Definition TypeBase.h:905
const FunctionProtoType * T
Hints for figuring out of a call should be inlined during evalCall().
Definition ExprEngine.h:97
bool IsTemporaryLifetimeExtendedViaAggregate
This call is a constructor for a temporary that is lifetime-extended by binding it to a reference-typ...
Definition ExprEngine.h:112
bool IsTemporaryCtorOrDtor
This call is a constructor or a destructor of a temporary value.
Definition ExprEngine.h:107
bool IsArrayCtorOrDtor
This call is a constructor or a destructor for a single element within an array, a part of array cons...
Definition ExprEngine.h:104
bool IsElidableCtorThatHasNotBeenElided
This call is a pre-C++17 elidable constructor that we failed to elide because we failed to compute th...
Definition ExprEngine.h:119
bool IsCtorOrDtorWithImproperlyModeledTargetRegion
This call is a constructor or a destructor for which we do not currently compute the this-region corr...
Definition ExprEngine.h:100
Traits for storing the call processing policy inside GDM.