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
163 /// Pointer to a (so-called, somewhat misnamed) NodeBuilderContext object
164 /// which has three independent roles:
165 /// - It holds a pointer to the CFGBlock that is currently under analysis.
166 /// (This is the primary way to get the current block.)
167 /// - It holds a pointer to the current LocationContext. (This is rarely
168 /// used, the location context is usually queried from a recent
169 /// ExplodedNode. Unfortunately it seems that these two sources of truth
170 /// are not always consistent.)
171 /// - It can be used for constructing `NodeBuilder`s. Practically all
172 /// `NodeBuilder` objects are useless complications in the code, so I
173 /// intend to replace them with direct use of `CoreEngine::makeNode`.
174 /// TODO: Eventually `currBldrCtx` should be replaced by two separate fields:
175 /// `const CFGBlock *CurrBlock` & `const LocationContext *CurrLocationContext`
176 /// that are kept up-to-date and are almost always non-null during the
177 /// analysis. I will switch to this more natural representation when
178 /// `NodeBuilder`s are eliminated from the code.
179 const NodeBuilderContext *currBldrCtx = nullptr;
180 /// Historically `currBldrCtx` pointed to a local variable in some stack
181 /// frame. This field is introduced as a temporary measure to allow a gradual
182 /// transition. Only use this in {re,}setLocationContextAndBlock!
183 /// TODO: Remove this temporary hack.
184 std::optional<NodeBuilderContext> OwnedCurrBldrCtx;
185
186 /// Helper object to determine if an Objective-C message expression
187 /// implicitly never returns.
188 ObjCNoReturn ObjCNoRet;
189
190 /// The BugReporter associated with this engine. It is important that
191 /// this object be placed at the very end of member variables so that its
192 /// destructor is called before the rest of the ExprEngine is destroyed.
194
195 /// The functions which have been analyzed through inlining. This is owned by
196 /// AnalysisConsumer. It can be null.
197 SetOfConstDecls *VisitedCallees;
198
199 /// The flag, which specifies the mode of inlining for the engine.
200 InliningModes HowToInline;
201
202public:
204 SetOfConstDecls *VisitedCalleesIn,
205 FunctionSummariesTy *FS, InliningModes HowToInlineIn);
206
207 virtual ~ExprEngine() = default;
208
209 /// Returns true if there is still simulation state on the worklist.
210 bool ExecuteWorkList(const LocationContext *L, unsigned Steps = 150000) {
211 assert(L->inTopFrame());
212 BR.setAnalysisEntryPoint(L->getDecl());
213 return Engine.ExecuteWorkList(L, Steps, nullptr);
214 }
215
216 /// getContext - Return the ASTContext associated with this analysis.
217 ASTContext &getContext() const { return AMgr.getASTContext(); }
218
220 const AnalysisManager &getAnalysisManager() const { return AMgr; }
221
223 return AMgr.getAnalysisDeclContextManager();
224 }
225
227 return *AMgr.getCheckerManager();
228 }
229
230 SValBuilder &getSValBuilder() { return svalBuilder; }
231 const SValBuilder &getSValBuilder() const { return svalBuilder; }
232
233 BugReporter &getBugReporter() { return BR; }
234 const BugReporter &getBugReporter() const { return BR; }
235
238 return &CTU;
239 }
240
241 // FIXME: Ideally the body of this method should look like
242 // CurrLocationContext = LC;
243 // CurrBlock = B;
244 // where CurrLocationContext and CurrBlock are new member variables that
245 // fulfill the roles of `currBldrCtx` in a more natural way.
246 // This implementation is a temporary measure to allow a gradual transition.
248 const CFGBlock *B) {
249 // The current LocationContext and Block is reset at the beginning of
250 // dispacthWorkItem. Ideally, this method should be called only once per
251 // dipatchWorkItem call (= elementary analysis step); so the following
252 // assertion is there to catch accidental repeated calls. If the current
253 // LocationContext and Block needs to change in the middle of a single step
254 // (which currently happens only once, in processCallExit), use an explicit
255 // call to resetCurrLocationContextAndBlock.
256 assert(!currBldrCtx && !OwnedCurrBldrCtx &&
257 "The current LocationContext and Block is already set");
258 OwnedCurrBldrCtx.emplace(Engine, B, LC);
259 currBldrCtx = &*OwnedCurrBldrCtx;
260 }
261
263 currBldrCtx = nullptr;
264 OwnedCurrBldrCtx = std::nullopt;
265 }
266
268 assert(currBldrCtx);
269 return *currBldrCtx;
270 }
271
273 assert(G.getRoot());
274 return G.getRoot()->getLocation().getLocationContext();
275 }
276
277 /// Get the 'current' location context corresponding to the current work item
278 /// (elementary analysis step handled by `dispatchWorkItem`).
279 /// FIXME: This sometimes (e.g. in some `BeginFunction` callbacks) differs
280 /// from the `LocationContext` that can be obtained from different sources
281 /// (e.g. a recent `ExplodedNode`). Traditionally this location context is
282 /// only used for block count calculations (`getNumVisited`); it is probably
283 /// wise to follow this tradition until the discrepancies are resolved.
285 return currBldrCtx ? currBldrCtx->getLocationContext() : nullptr;
286 }
287
288 /// Get the 'current' CFGBlock corresponding to the current work item
289 /// (elementary analysis step handled by `dispatchWorkItem`).
290 const CFGBlock *getCurrBlock() const {
291 return currBldrCtx ? currBldrCtx->getBlock() : nullptr;
292 }
293
295 return {getCurrBlock(), currStmtIdx};
296 }
297
298 unsigned getNumVisited(const LocationContext *LC,
299 const CFGBlock *Block) const {
300 return Engine.WList->getBlockCounter().getNumVisited(LC->getStackFrame(),
301 Block->getBlockID());
302 }
303
304 unsigned getNumVisitedCurrent() const {
306 }
307
308 /// Dump graph to the specified filename.
309 /// If filename is empty, generate a temporary one.
310 /// \return The filename the graph is written into.
311 std::string DumpGraph(bool trim = false, StringRef Filename="");
312
313 /// Dump the graph consisting of the given nodes to a specified filename.
314 /// Generate a temporary filename if it's not provided.
315 /// \return The filename the graph is written into.
317 StringRef Filename = "");
318
319 /// Visualize the ExplodedGraph created by executing the simulation.
320 void ViewGraph(bool trim = false);
321
322 /// Visualize a trimmed ExplodedGraph that only contains paths to the given
323 /// nodes.
325
326 /// getInitialState - Return the initial state used for the root vertex
327 /// in the ExplodedGraph.
329
330 ExplodedGraph &getGraph() { return G; }
331 const ExplodedGraph &getGraph() const { return G; }
332
333 /// Run the analyzer's garbage collection - remove dead symbols and
334 /// bindings from the state.
335 ///
336 /// Checkers can participate in this process with two callbacks:
337 /// \c checkLiveSymbols and \c checkDeadSymbols. See the CheckerDocumentation
338 /// class for more information.
339 ///
340 /// \param Node The predecessor node, from which the processing should start.
341 /// \param Out The returned set of output nodes.
342 /// \param ReferenceStmt The statement which is about to be processed.
343 /// Everything needed for this statement should be considered live.
344 /// A null statement means that everything in child LocationContexts
345 /// is dead.
346 /// \param LC The location context of the \p ReferenceStmt. A null location
347 /// context means that we have reached the end of analysis and that
348 /// all statements and local variables should be considered dead.
349 /// \param DiagnosticStmt Used as a location for any warnings that should
350 /// occur while removing the dead (e.g. leaks). By default, the
351 /// \p ReferenceStmt is used.
352 /// \param K Denotes whether this is a pre- or post-statement purge. This
353 /// must only be ProgramPoint::PostStmtPurgeDeadSymbolsKind if an
354 /// entire location context is being cleared, in which case the
355 /// \p ReferenceStmt must either be a ReturnStmt or \c NULL. Otherwise,
356 /// it must be ProgramPoint::PreStmtPurgeDeadSymbolsKind (the default)
357 /// and \p ReferenceStmt must be valid (non-null).
358 void removeDead(ExplodedNode *Node, ExplodedNodeSet &Out,
359 const Stmt *ReferenceStmt, const LocationContext *LC,
360 const Stmt *DiagnosticStmt = nullptr,
362
363 /// A tag to track convenience transitions, which can be removed at cleanup.
364 /// This tag applies to a node created after removeDead.
365 static const ProgramPointTag *cleanupNodeTag();
366
367 /// processCFGElement - Called by CoreEngine. Used to generate new successor
368 /// nodes by processing the 'effects' of a CFG element.
369 void processCFGElement(const CFGElement E, ExplodedNode *Pred,
370 unsigned StmtIdx);
371
372 void ProcessStmt(const Stmt *S, ExplodedNode *Pred);
373
374 void ProcessLoopExit(const Stmt* S, ExplodedNode *Pred);
375
377
379
380 void ProcessNewAllocator(const CXXNewExpr *NE, ExplodedNode *Pred);
381
383 ExplodedNode *Pred, ExplodedNodeSet &Dst);
384 void ProcessDeleteDtor(const CFGDeleteDtor D,
385 ExplodedNode *Pred, ExplodedNodeSet &Dst);
386 void ProcessBaseDtor(const CFGBaseDtor D,
387 ExplodedNode *Pred, ExplodedNodeSet &Dst);
388 void ProcessMemberDtor(const CFGMemberDtor D,
389 ExplodedNode *Pred, ExplodedNodeSet &Dst);
391 ExplodedNode *Pred, ExplodedNodeSet &Dst);
392
393 /// Called by CoreEngine when processing the entrance of a CFGBlock.
394 void processCFGBlockEntrance(const BlockEdge &L, const BlockEntrance &BE,
395 NodeBuilder &Builder, ExplodedNode *Pred);
396
397 void runCheckersForBlockEntrance(const BlockEntrance &Entrance,
398 ExplodedNode *Pred, ExplodedNodeSet &Dst);
399
400 /// ProcessBranch - Called by CoreEngine. Used to generate successor nodes by
401 /// processing the 'effects' of a branch condition. If the branch condition
402 /// is a loop condition, IterationsCompletedInLoop is the number of completed
403 /// iterations (otherwise it's std::nullopt).
404 void processBranch(const Stmt *Condition, ExplodedNode *Pred,
405 ExplodedNodeSet &Dst, const CFGBlock *DstT,
406 const CFGBlock *DstF,
407 std::optional<unsigned> IterationsCompletedInLoop);
408
409 /// Called by CoreEngine.
410 /// Used to generate successor nodes for temporary destructors depending
411 /// on whether the corresponding constructor was visited.
413 ExplodedNode *Pred, ExplodedNodeSet &Dst,
414 const CFGBlock *DstT,
415 const CFGBlock *DstF);
416
417 /// Called by CoreEngine. Used to processing branching behavior
418 /// at static initializers.
420 ExplodedNodeSet &Dst, const CFGBlock *DstT,
421 const CFGBlock *DstF);
422
423 /// processIndirectGoto - Called by CoreEngine. Used to generate successor
424 /// nodes by processing the 'effects' of a computed goto jump.
426 ExplodedNode *Pred);
427
428 /// ProcessSwitch - Called by CoreEngine. Used to generate successor
429 /// nodes by processing the 'effects' of a switch statement.
430 void processSwitch(const SwitchStmt *Switch, ExplodedNode *Pred,
431 ExplodedNodeSet &Dst);
432
433 /// Called by CoreEngine. Used to notify checkers that processing a
434 /// function has begun. Called for both inlined and top-level functions.
436 const BlockEdge &L);
437
438 /// Called by CoreEngine. Used to notify checkers that processing a
439 /// function has ended. Called for both inlined and top-level functions.
440 void processEndOfFunction(ExplodedNode *Pred, const ReturnStmt *RS = nullptr);
441
442 /// Remove dead bindings/symbols before exiting a function.
444
445 /// Generate the entry node of the callee.
447
448 /// Generate the sequence of nodes that simulate the call exit and the post
449 /// visit for CallExpr.
450 void processCallExit(ExplodedNode *Pred);
451
452 /// Called by CoreEngine when the analysis worklist has terminated.
453 void processEndWorklist();
454
455 /// evalAssume - Callback function invoked by the ConstraintManager when
456 /// making assumptions about state values.
458 bool assumption);
459
460 /// processRegionChanges - Called by ProgramStateManager whenever a change is made
461 /// to the store. Used to update checkers that track region values.
464 const InvalidatedSymbols *invalidated,
465 ArrayRef<const MemRegion *> ExplicitRegions,
467 const LocationContext *LCtx,
468 const CallEvent *Call);
469
470 inline ProgramStateRef
472 const MemRegion* MR,
473 const LocationContext *LCtx) {
474 return processRegionChanges(state, nullptr, MR, MR, LCtx, nullptr);
475 }
476
477 /// printJson - Called by ProgramStateManager to print checker-specific data.
478 void printJson(raw_ostream &Out, ProgramStateRef State,
479 const LocationContext *LCtx, const char *NL,
480 unsigned int Space, bool IsDot) const;
481
482 ProgramStateManager &getStateManager() { return StateMgr; }
483 const ProgramStateManager &getStateManager() const { return StateMgr; }
484
485 StoreManager &getStoreManager() { return StateMgr.getStoreManager(); }
487 return StateMgr.getStoreManager();
488 }
489
491 return StateMgr.getConstraintManager();
492 }
494 return StateMgr.getConstraintManager();
495 }
496
497 // FIXME: Remove when we migrate over to just using SValBuilder.
499 return StateMgr.getBasicVals();
500 }
501
502 SymbolManager &getSymbolManager() { return SymMgr; }
503 const SymbolManager &getSymbolManager() const { return SymMgr; }
505
506 DataTag::Factory &getDataTags() { return Engine.getDataTags(); }
507
508 // Functions for external checking of whether we have unfinished work.
509 bool wasBlocksExhausted() const { return Engine.wasBlocksExhausted(); }
510 bool hasEmptyWorkList() const { return !Engine.getWorkList()->hasWork(); }
511 bool hasWorkRemaining() const { return Engine.hasWorkRemaining(); }
512
513 const CoreEngine &getCoreEngine() const { return Engine; }
514
515public:
516 /// Visit - Transfer function logic for all statements. Dispatches to
517 /// other functions that handle specific kinds of statements.
518 void Visit(const Stmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst);
519
520 /// VisitArrayInitLoopExpr - Transfer function for array init loop.
522 ExplodedNodeSet &Dst);
523
524 /// VisitArraySubscriptExpr - Transfer function for array accesses.
526 ExplodedNode *Pred,
527 ExplodedNodeSet &Dst);
528
529 /// VisitGCCAsmStmt - Transfer function logic for inline asm.
530 void VisitGCCAsmStmt(const GCCAsmStmt *A, ExplodedNode *Pred,
531 ExplodedNodeSet &Dst);
532
533 /// VisitMSAsmStmt - Transfer function logic for MS inline asm.
534 void VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred,
535 ExplodedNodeSet &Dst);
536
537 /// VisitBlockExpr - Transfer function logic for BlockExprs.
538 void VisitBlockExpr(const BlockExpr *BE, ExplodedNode *Pred,
539 ExplodedNodeSet &Dst);
540
541 /// VisitLambdaExpr - Transfer function logic for LambdaExprs.
542 void VisitLambdaExpr(const LambdaExpr *LE, ExplodedNode *Pred,
543 ExplodedNodeSet &Dst);
544
545 /// VisitBinaryOperator - Transfer function logic for binary operators.
547 ExplodedNodeSet &Dst);
548
549
550 /// VisitCall - Transfer function for function calls.
551 void VisitCallExpr(const CallExpr *CE, ExplodedNode *Pred,
552 ExplodedNodeSet &Dst);
553
554 /// VisitCast - Transfer function logic for all casts (implicit and explicit).
555 void VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNode *Pred,
556 ExplodedNodeSet &Dst);
557
558 /// VisitCompoundLiteralExpr - Transfer function logic for compound literals.
560 ExplodedNode *Pred, ExplodedNodeSet &Dst);
561
562 /// Transfer function logic for DeclRefExprs and BlockDeclRefExprs.
563 void VisitCommonDeclRefExpr(const Expr *DR, const NamedDecl *D,
564 ExplodedNode *Pred, ExplodedNodeSet &Dst);
565
566 /// VisitDeclStmt - Transfer function logic for DeclStmts.
567 void VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred,
568 ExplodedNodeSet &Dst);
569
570 /// VisitGuardedExpr - Transfer function logic for ?, __builtin_choose
571 void VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R,
572 ExplodedNode *Pred, ExplodedNodeSet &Dst);
573
574 /// VisitAttributedStmt - Transfer function logic for AttributedStmt.
576 ExplodedNodeSet &Dst);
577
578 /// VisitLogicalExpr - Transfer function logic for '&&', '||'.
579 void VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
580 ExplodedNodeSet &Dst);
581
582 /// VisitMemberExpr - Transfer function for member expressions.
583 void VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred,
584 ExplodedNodeSet &Dst);
585
586 /// VisitAtomicExpr - Transfer function for builtin atomic expressions.
587 void VisitAtomicExpr(const AtomicExpr *E, ExplodedNode *Pred,
588 ExplodedNodeSet &Dst);
589
590 /// Transfer function logic for ObjCAtSynchronizedStmts.
592 ExplodedNode *Pred, ExplodedNodeSet &Dst);
593
594 /// Transfer function logic for computing the lvalue of an Objective-C ivar.
596 ExplodedNodeSet &Dst);
597
598 /// VisitObjCForCollectionStmt - Transfer function logic for
599 /// ObjCForCollectionStmt.
601 ExplodedNode *Pred, ExplodedNodeSet &Dst);
602
603 void VisitObjCMessage(const ObjCMessageExpr *ME, ExplodedNode *Pred,
604 ExplodedNodeSet &Dst);
605
606 /// VisitReturnStmt - Transfer function logic for return statements.
607 void VisitReturnStmt(const ReturnStmt *R, ExplodedNode *Pred,
608 ExplodedNodeSet &Dst);
609
610 /// VisitOffsetOfExpr - Transfer function for offsetof.
611 void VisitOffsetOfExpr(const OffsetOfExpr *Ex, ExplodedNode *Pred,
612 ExplodedNodeSet &Dst);
613
614 /// VisitUnaryExprOrTypeTraitExpr - Transfer function for sizeof.
616 ExplodedNode *Pred, ExplodedNodeSet &Dst);
617
618 /// VisitUnaryOperator - Transfer function logic for unary operators.
619 void VisitUnaryOperator(const UnaryOperator* B, ExplodedNode *Pred,
620 ExplodedNodeSet &Dst);
621
622 /// Handle ++ and -- (both pre- and post-increment).
624 ExplodedNode *Pred,
625 ExplodedNodeSet &Dst);
626
628 ExplodedNodeSet &PreVisit,
629 ExplodedNodeSet &Dst);
630
631 void VisitCXXCatchStmt(const CXXCatchStmt *CS, ExplodedNode *Pred,
632 ExplodedNodeSet &Dst);
633
634 void VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred,
635 ExplodedNodeSet & Dst);
636
638 ExplodedNodeSet &Dst);
639
641 ExplodedNode *Pred, ExplodedNodeSet &Dst);
642
643 void VisitCXXDestructor(QualType ObjectType, const MemRegion *Dest,
644 const Stmt *S, bool IsBaseDtor,
645 ExplodedNode *Pred, ExplodedNodeSet &Dst,
646 EvalCallOptions &Options);
647
648 void VisitCXXNewAllocatorCall(const CXXNewExpr *CNE,
649 ExplodedNode *Pred,
650 ExplodedNodeSet &Dst);
651
652 void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
653 ExplodedNodeSet &Dst);
654
656 ExplodedNodeSet &Dst);
657
658 /// Create a C++ temporary object for an rvalue.
660 ExplodedNode *Pred,
661 ExplodedNodeSet &Dst);
662
663 void ConstructInitList(const Expr *Source, ArrayRef<Expr *> Args,
664 bool IsTransparent, ExplodedNode *Pred,
665 ExplodedNodeSet &Dst);
666
667 /// evalEagerlyAssumeBifurcation - Given the nodes in 'Src', eagerly assume
668 /// concrete boolean values for 'Ex', storing the resulting nodes in 'Dst'.
670 const Expr *Ex);
671
672 bool didEagerlyAssumeBifurcateAt(ProgramStateRef State, const Expr *Ex) const;
673
674 static std::pair<const ProgramPointTag *, const ProgramPointTag *>
676
678 const LocationContext *LCtx, QualType T,
679 QualType ExTy, const CastExpr *CastE,
680 NodeBuilder &Bldr, ExplodedNode *Pred);
681
683 NodeBuilder &Bldr);
684
685public:
687 SVal LHS, SVal RHS, QualType T) {
688 return svalBuilder.evalBinOp(ST, Op, LHS, RHS, T);
689 }
690
691 /// Retreives which element is being constructed in a non-POD type array.
692 static std::optional<unsigned>
694 const LocationContext *LCtx);
695
696 /// Retreives which element is being destructed in a non-POD type array.
697 static std::optional<unsigned>
699 const LocationContext *LCtx);
700
701 /// Retreives the size of the array in the pending ArrayInitLoopExpr.
702 static std::optional<unsigned>
704 const LocationContext *LCtx);
705
706 /// By looking at a certain item that may be potentially part of an object's
707 /// ConstructionContext, retrieve such object's location. A particular
708 /// statement can be transparently passed as \p Item in most cases.
709 static std::optional<SVal>
711 const ConstructionContextItem &Item,
712 const LocationContext *LC);
713
714 /// Call PointerEscape callback when a value escapes as a result of bind.
716 ProgramStateRef State, ArrayRef<std::pair<SVal, SVal>> LocAndVals,
717 const LocationContext *LCtx, PointerEscapeKind Kind,
718 const CallEvent *Call);
719
720 /// Call PointerEscape callback when a value escapes as a result of
721 /// region invalidation.
722 /// \param[in] ITraits Specifies invalidation traits for regions/symbols.
724 ProgramStateRef State,
725 const InvalidatedSymbols *Invalidated,
726 ArrayRef<const MemRegion *> ExplicitRegions,
727 const CallEvent *Call,
729
730private:
731 /// evalBind - Handle the semantics of binding a value to a specific location.
732 /// This method is used by evalStore, VisitDeclStmt, and others.
733 void evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE, ExplodedNode *Pred,
734 SVal location, SVal Val, bool AtDeclInit = false,
735 const ProgramPoint *PP = nullptr);
736
739 SVal Loc, SVal Val,
740 const LocationContext *LCtx);
741
742public:
743 /// A simple wrapper when you only need to notify checkers of pointer-escape
744 /// of some values.
747 const CallEvent *Call = nullptr) const;
748
749 // FIXME: 'tag' should be removed, and a LocationContext should be used
750 // instead.
751 // FIXME: Comment on the meaning of the arguments, when 'St' may not
752 // be the same as Pred->state, and when 'location' may not be the
753 // same as state->getLValue(Ex).
754 /// Simulate a read of the result of Ex.
755 void evalLoad(ExplodedNodeSet &Dst,
756 const Expr *NodeEx, /* Eventually will be a CFGStmt */
757 const Expr *BoundExpr,
758 ExplodedNode *Pred,
760 SVal location,
761 const ProgramPointTag *tag = nullptr,
762 QualType LoadTy = QualType());
763
764 // FIXME: 'tag' should be removed, and a LocationContext should be used
765 // instead.
766 void evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, const Expr *StoreE,
767 ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val,
768 const ProgramPointTag *tag = nullptr);
769
770 /// Return the CFG element corresponding to the worklist element
771 /// that is currently being processed by ExprEngine.
772 CFGElement getCurrentCFGElement() { return (*getCurrBlock())[currStmtIdx]; }
773
774 /// Create a new state in which the call return value is binded to the
775 /// call origin expression.
777 const LocationContext *LCtx,
778 ProgramStateRef State);
779
780 /// Evaluate a call, running pre- and post-call checkers and allowing checkers
781 /// to be responsible for handling the evaluation of the call itself.
782 void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred,
783 const CallEvent &Call);
784
785 /// Default implementation of call evaluation.
787 const CallEvent &Call,
788 const EvalCallOptions &CallOpts = {});
789
790 /// Find location of the object that is being constructed by a given
791 /// constructor. This should ideally always succeed but due to not being
792 /// fully implemented it sometimes indicates that it failed via its
793 /// out-parameter CallOpts; in such cases a fake temporary region is
794 /// returned, which is better than nothing but does not represent
795 /// the actual behavior of the program. The Idx parameter is used if we
796 /// construct an array of objects. In that case it points to the index
797 /// of the continuous memory region.
798 /// E.g.:
799 /// For `int arr[4]` this index can be 0,1,2,3.
800 /// For `int arr2[3][3]` this index can be 0,1,...,7,8.
801 /// A multi-dimensional array is also a continuous memory location in a
802 /// row major order, so for arr[0][0] Idx is 0 and for arr[3][3] Idx is 8.
804 unsigned NumVisitedCaller,
805 const LocationContext *LCtx,
806 const ConstructionContext *CC,
807 EvalCallOptions &CallOpts,
808 unsigned Idx = 0);
809
810 /// Update the program state with all the path-sensitive information
811 /// that's necessary to perform construction of an object with a given
812 /// syntactic construction context. V and CallOpts have to be obtained from
813 /// computeObjectUnderConstruction() invoked with the same set of
814 /// the remaining arguments (E, State, LCtx, CC).
816 SVal V, const Expr *E, ProgramStateRef State, const LocationContext *LCtx,
817 const ConstructionContext *CC, const EvalCallOptions &CallOpts);
818
819 /// A convenient wrapper around computeObjectUnderConstruction
820 /// and updateObjectsUnderConstruction.
821 std::pair<ProgramStateRef, SVal> handleConstructionContext(
822 const Expr *E, ProgramStateRef State, const NodeBuilderContext *BldrCtx,
823 const LocationContext *LCtx, const ConstructionContext *CC,
824 EvalCallOptions &CallOpts, unsigned Idx = 0) {
825
826 SVal V = computeObjectUnderConstruction(E, State, BldrCtx->blockCount(),
827 LCtx, CC, CallOpts, Idx);
828 State = updateObjectsUnderConstruction(V, E, State, LCtx, CC, CallOpts);
829
830 return std::make_pair(State, V);
831 }
832
833private:
834 ProgramStateRef finishArgumentConstruction(ProgramStateRef State,
835 const CallEvent &Call);
836 void finishArgumentConstruction(ExplodedNodeSet &Dst, ExplodedNode *Pred,
837 const CallEvent &Call);
838
839 void evalLocation(ExplodedNodeSet &Dst,
840 const Stmt *NodeEx, /* This will eventually be a CFGStmt */
841 const Stmt *BoundEx,
842 ExplodedNode *Pred,
844 SVal location,
845 bool isLoad);
846
847 /// Count the stack depth and determine if the call is recursive.
848 void examineStackFrames(const Decl *D, const LocationContext *LCtx,
849 bool &IsRecursive, unsigned &StackDepth);
850
851 enum CallInlinePolicy {
852 CIP_Allowed,
853 CIP_DisallowedOnce,
854 CIP_DisallowedAlways
855 };
856
857 /// See if a particular call should be inlined, by only looking
858 /// at the call event and the current state of analysis.
859 CallInlinePolicy mayInlineCallKind(const CallEvent &Call,
860 const ExplodedNode *Pred,
861 AnalyzerOptions &Opts,
862 const EvalCallOptions &CallOpts);
863
864 /// See if the given AnalysisDeclContext is built for a function that we
865 /// should always inline simply because it's small enough.
866 /// Apart from "small" functions, we also have "large" functions
867 /// (cf. isLarge()), some of which are huge (cf. isHuge()), and we classify
868 /// the remaining functions as "medium".
869 bool isSmall(AnalysisDeclContext *ADC) const;
870
871 /// See if the given AnalysisDeclContext is built for a function that we
872 /// should inline carefully because it looks pretty large.
873 bool isLarge(AnalysisDeclContext *ADC) const;
874
875 /// See if the given AnalysisDeclContext is built for a function that we
876 /// should never inline because it's legit gigantic.
877 bool isHuge(AnalysisDeclContext *ADC) const;
878
879 /// See if the given AnalysisDeclContext is built for a function that we
880 /// should inline, just by looking at the declaration of the function.
881 bool mayInlineDecl(AnalysisDeclContext *ADC) const;
882
883 /// Checks our policies and decides whether the given call should be inlined.
884 bool shouldInlineCall(const CallEvent &Call, const Decl *D,
885 const ExplodedNode *Pred,
886 const EvalCallOptions &CallOpts = {});
887
888 /// Checks whether our policies allow us to inline a non-POD type array
889 /// construction.
890 bool shouldInlineArrayConstruction(const ProgramStateRef State,
891 const CXXConstructExpr *CE,
892 const LocationContext *LCtx);
893
894 /// Checks whether our policies allow us to inline a non-POD type array
895 /// destruction.
896 /// \param Size The size of the array.
897 bool shouldInlineArrayDestruction(uint64_t Size);
898
899 /// Prepares the program state for array destruction. If no error happens
900 /// the function binds a 'PendingArrayDestruction' entry to the state, which
901 /// it returns along with the index. If any error happens (we fail to read
902 /// the size, the index would be -1, etc.) the function will return the
903 /// original state along with an index of 0. The actual element count of the
904 /// array can be accessed by the optional 'ElementCountVal' parameter. \param
905 /// State The program state. \param Region The memory region where the array
906 /// is stored. \param ElementTy The type an element in the array. \param LCty
907 /// The location context. \param ElementCountVal A pointer to an optional
908 /// SVal. If specified, the size of the array will be returned in it. It can
909 /// be Unknown.
910 std::pair<ProgramStateRef, uint64_t> prepareStateForArrayDestruction(
911 const ProgramStateRef State, const MemRegion *Region,
912 const QualType &ElementTy, const LocationContext *LCtx,
913 SVal *ElementCountVal = nullptr);
914
915 /// Checks whether we construct an array of non-POD type, and decides if the
916 /// constructor should be inkoved once again.
917 bool shouldRepeatCtorCall(ProgramStateRef State, const CXXConstructExpr *E,
918 const LocationContext *LCtx);
919
920 void inlineCall(WorkList *WList, const CallEvent &Call, const Decl *D,
921 NodeBuilder &Bldr, ExplodedNode *Pred, ProgramStateRef State);
922
923 void ctuBifurcate(const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
924 ExplodedNode *Pred, ProgramStateRef State);
925
926 /// Returns true if the CTU analysis is running its second phase.
927 bool isSecondPhaseCTU() { return IsCTUEnabled && !Engine.getCTUWorkList(); }
928
929 /// Conservatively evaluate call by invalidating regions and binding
930 /// a conjured return value.
931 void conservativeEvalCall(const CallEvent &Call, NodeBuilder &Bldr,
932 ExplodedNode *Pred, ProgramStateRef State);
933
934 /// Either inline or process the call conservatively (or both), based
935 /// on DynamicDispatchBifurcation data.
936 void BifurcateCall(const MemRegion *BifurReg,
937 const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
938 ExplodedNode *Pred);
939
940 bool replayWithoutInlining(ExplodedNode *P, const LocationContext *CalleeLC);
941
942 /// Models a trivial copy or move constructor or trivial assignment operator
943 /// call with a simple bind.
944 void performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
945 const CallEvent &Call);
946
947 /// If the value of the given expression \p InitWithAdjustments is a NonLoc,
948 /// copy it into a new temporary object region, and replace the value of the
949 /// expression with that.
950 ///
951 /// If \p Result is provided, the new region will be bound to this expression
952 /// instead of \p InitWithAdjustments.
953 ///
954 /// Returns the temporary region with adjustments into the optional
955 /// OutRegionWithAdjustments out-parameter if a new region was indeed needed,
956 /// otherwise sets it to nullptr.
957 ProgramStateRef createTemporaryRegionIfNeeded(
958 ProgramStateRef State, const LocationContext *LC,
959 const Expr *InitWithAdjustments, const Expr *Result = nullptr,
960 const SubRegion **OutRegionWithAdjustments = nullptr);
961
962 /// Returns a region representing the `Idx`th element of a (possibly
963 /// multi-dimensional) array, for the purposes of element construction or
964 /// destruction.
965 ///
966 /// On return, \p Ty will be set to the base type of the array.
967 ///
968 /// If the type is not an array type at all, the original value is returned.
969 /// Otherwise the "IsArray" flag is set.
970 static SVal makeElementRegion(ProgramStateRef State, SVal LValue,
971 QualType &Ty, bool &IsArray, unsigned Idx = 0);
972
973 /// Common code that handles either a CXXConstructExpr or a
974 /// CXXInheritedCtorInitExpr.
975 void handleConstructor(const Expr *E, ExplodedNode *Pred,
976 ExplodedNodeSet &Dst);
977
978public:
979 /// Note whether this loop has any more iterations to model. These methods
980 // are essentially an interface for a GDM trait. Further reading in
981 /// ExprEngine::VisitObjCForCollectionStmt().
982 [[nodiscard]] static ProgramStateRef
984 const ObjCForCollectionStmt *O,
985 const LocationContext *LC, bool HasMoreIteraton);
986
987 [[nodiscard]] static ProgramStateRef
988 removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O,
989 const LocationContext *LC);
990
991 [[nodiscard]] static bool hasMoreIteration(ProgramStateRef State,
992 const ObjCForCollectionStmt *O,
993 const LocationContext *LC);
994
995private:
996 /// Assuming we construct an array of non-POD types, this method allows us
997 /// to store which element is to be constructed next.
998 static ProgramStateRef
999 setIndexOfElementToConstruct(ProgramStateRef State, const CXXConstructExpr *E,
1000 const LocationContext *LCtx, unsigned Idx);
1001
1002 static ProgramStateRef
1003 removeIndexOfElementToConstruct(ProgramStateRef State,
1004 const CXXConstructExpr *E,
1005 const LocationContext *LCtx);
1006
1007 /// Assuming we destruct an array of non-POD types, this method allows us
1008 /// to store which element is to be destructed next.
1009 static ProgramStateRef setPendingArrayDestruction(ProgramStateRef State,
1010 const LocationContext *LCtx,
1011 unsigned Idx);
1012
1013 static ProgramStateRef
1014 removePendingArrayDestruction(ProgramStateRef State,
1015 const LocationContext *LCtx);
1016
1017 /// Sets the size of the array in a pending ArrayInitLoopExpr.
1018 static ProgramStateRef setPendingInitLoop(ProgramStateRef State,
1019 const CXXConstructExpr *E,
1020 const LocationContext *LCtx,
1021 unsigned Idx);
1022
1023 static ProgramStateRef removePendingInitLoop(ProgramStateRef State,
1024 const CXXConstructExpr *E,
1025 const LocationContext *LCtx);
1026
1027 static ProgramStateRef
1028 removeStateTraitsUsedForArrayEvaluation(ProgramStateRef State,
1029 const CXXConstructExpr *E,
1030 const LocationContext *LCtx);
1031
1032 /// Store the location of a C++ object corresponding to a statement
1033 /// until the statement is actually encountered. For example, if a DeclStmt
1034 /// has CXXConstructExpr as its initializer, the object would be considered
1035 /// to be "under construction" between CXXConstructExpr and DeclStmt.
1036 /// This allows, among other things, to keep bindings to variable's fields
1037 /// made within the constructor alive until its declaration actually
1038 /// goes into scope.
1039 static ProgramStateRef
1040 addObjectUnderConstruction(ProgramStateRef State,
1041 const ConstructionContextItem &Item,
1042 const LocationContext *LC, SVal V);
1043
1044 /// Mark the object as fully constructed, cleaning up the state trait
1045 /// that tracks objects under construction.
1046 static ProgramStateRef
1047 finishObjectConstruction(ProgramStateRef State,
1048 const ConstructionContextItem &Item,
1049 const LocationContext *LC);
1050
1051 /// If the given expression corresponds to a temporary that was used for
1052 /// passing into an elidable copy/move constructor and that constructor
1053 /// was actually elided, track that we also need to elide the destructor.
1054 static ProgramStateRef elideDestructor(ProgramStateRef State,
1055 const CXXBindTemporaryExpr *BTE,
1056 const LocationContext *LC);
1057
1058 /// Stop tracking the destructor that corresponds to an elided constructor.
1059 static ProgramStateRef
1060 cleanupElidedDestructor(ProgramStateRef State,
1061 const CXXBindTemporaryExpr *BTE,
1062 const LocationContext *LC);
1063
1064 /// Returns true if the given expression corresponds to a temporary that
1065 /// was constructed for passing into an elidable copy/move constructor
1066 /// and that constructor was actually elided.
1067 static bool isDestructorElided(ProgramStateRef State,
1068 const CXXBindTemporaryExpr *BTE,
1069 const LocationContext *LC);
1070
1071 /// Check if all objects under construction have been fully constructed
1072 /// for the given context range (including FromLC, not including ToLC).
1073 /// This is useful for assertions. Also checks if elided destructors
1074 /// were cleaned up.
1075 static bool areAllObjectsFullyConstructed(ProgramStateRef State,
1076 const LocationContext *FromLC,
1077 const LocationContext *ToLC);
1078};
1079
1080/// Traits for storing the call processing policy inside GDM.
1081/// The GDM stores the corresponding CallExpr pointer.
1082// FIXME: This does not use the nice trait macros because it must be accessible
1083// from multiple translation units.
1085template <>
1087 public ProgramStatePartialTrait<const void*> {
1088 static void *GDMIndex();
1089};
1090
1091} // namespace ento
1092
1093} // namespace clang
1094
1095#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
const StackFrameContext * getStackFrame() 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 VisitBinaryOperator(const BinaryOperator *B, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitBinaryOperator - Transfer function logic for binary operators.
ProgramStateManager & getStateManager()
Definition ExprEngine.h:482
void processCFGElement(const CFGElement E, ExplodedNode *Pred, unsigned StmtIdx)
processCFGElement - Called by CoreEngine.
void processBranch(const Stmt *Condition, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF, std::optional< unsigned > IterationsCompletedInLoop)
ProcessBranch - Called by CoreEngine.
void VisitArraySubscriptExpr(const ArraySubscriptExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitArraySubscriptExpr - Transfer function for array accesses.
void VisitCommonDeclRefExpr(const Expr *DR, const NamedDecl *D, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Transfer function logic for DeclRefExprs and BlockDeclRefExprs.
void ProcessInitializer(const CFGInitializer I, ExplodedNode *Pred)
void VisitObjCMessage(const ObjCMessageExpr *ME, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void ProcessTemporaryDtor(const CFGTemporaryDtor D, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitGuardedExpr - Transfer function logic for ?, __builtin_choose.
void runCheckersForBlockEntrance(const BlockEntrance &Entrance, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitCast - Transfer function logic for all casts (implicit and explicit).
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:498
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:821
void processEndOfFunction(ExplodedNode *Pred, const ReturnStmt *RS=nullptr)
Called by CoreEngine.
void VisitCXXDestructor(QualType ObjectType, const MemRegion *Dest, const Stmt *S, bool IsBaseDtor, ExplodedNode *Pred, ExplodedNodeSet &Dst, EvalCallOptions &Options)
void removeDeadOnEndOfFunction(ExplodedNode *Pred, ExplodedNodeSet &Dst)
Remove dead bindings/symbols before exiting a function.
void evalEagerlyAssumeBifurcation(ExplodedNodeSet &Dst, ExplodedNodeSet &Src, const Expr *Ex)
evalEagerlyAssumeBifurcation - Given the nodes in 'Src', eagerly assume concrete boolean values for '...
void VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Transfer function logic for ObjCAtSynchronizedStmts.
void VisitReturnStmt(const ReturnStmt *R, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitReturnStmt - Transfer function logic for return statements.
const CoreEngine & getCoreEngine() const
Definition ExprEngine.h:513
SVal evalBinOp(ProgramStateRef ST, BinaryOperator::Opcode Op, SVal LHS, SVal RHS, QualType T)
Definition ExprEngine.h:686
void processCallEnter(CallEnter CE, ExplodedNode *Pred)
Generate the entry node of the callee.
void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred, ExplodedNodeSet &Dst)
ProgramStateRef processRegionChange(ProgramStateRef state, const MemRegion *MR, const LocationContext *LCtx)
Definition ExprEngine.h:471
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.
void processStaticInitializer(const DeclStmt *DS, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF)
Called by CoreEngine.
const SymbolManager & getSymbolManager() const
Definition ExprEngine.h:503
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:772
unsigned getNumVisited(const LocationContext *LC, const CFGBlock *Block) const
Definition ExprEngine.h:298
std::string DumpGraph(bool trim=false, StringRef Filename="")
Dump graph to the specified filename.
bool hasWorkRemaining() const
Definition ExprEngine.h:511
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, unsigned NumVisitedCaller, 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:272
static ProgramStateRef removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O, const LocationContext *LC)
const ExplodedGraph & getGraph() const
Definition ExprEngine.h:331
const StoreManager & getStoreManager() const
Definition ExprEngine.h:486
void setCurrLocationContextAndBlock(const LocationContext *LC, const CFGBlock *B)
Definition ExprEngine.h:247
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:222
const ProgramStateManager & getStateManager() const
Definition ExprEngine.h:483
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.
void processCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE, ExplodedNode *Pred, ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF)
Called by CoreEngine.
ASTContext & getContext() const
getContext - Return the ASTContext associated with this analysis.
Definition ExprEngine.h:217
StoreManager & getStoreManager()
Definition ExprEngine.h:485
const ConstraintManager & getConstraintManager() const
Definition ExprEngine.h:493
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:233
bool hasEmptyWorkList() const
Definition ExprEngine.h:510
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:294
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 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:237
ProgramStateRef escapeValues(ProgramStateRef State, ArrayRef< SVal > Vs, PointerEscapeKind K, const CallEvent *Call=nullptr) const
A simple wrapper when you only need to notify checkers of pointer-escape of some values.
void ProcessLoopExit(const Stmt *S, ExplodedNode *Pred)
void processEndWorklist()
Called by CoreEngine when the analysis worklist has terminated.
void resetCurrLocationContextAndBlock()
Definition ExprEngine.h:262
CheckerManager & getCheckerManager() const
Definition ExprEngine.h:226
SymbolManager & getSymbolManager()
Definition ExprEngine.h:502
void processBeginOfFunction(ExplodedNode *Pred, ExplodedNodeSet &Dst, const BlockEdge &L)
Called by CoreEngine.
void VisitAtomicExpr(const AtomicExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitAtomicExpr - Transfer function for builtin atomic expressions.
bool wasBlocksExhausted() const
Definition ExprEngine.h:509
MemRegionManager & getRegionManager()
Definition ExprEngine.h:504
const AnalysisManager & getAnalysisManager() const
Definition ExprEngine.h:220
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 processSwitch(const SwitchStmt *Switch, ExplodedNode *Pred, ExplodedNodeSet &Dst)
ProcessSwitch - Called by CoreEngine.
void VisitCXXConstructExpr(const CXXConstructExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
void VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E, ExplodedNode *Pred, ExplodedNodeSet &Dst)
bool didEagerlyAssumeBifurcateAt(ProgramStateRef State, const Expr *Ex) const
ConstraintManager & getConstraintManager()
Definition ExprEngine.h:490
DataTag::Factory & getDataTags()
Definition ExprEngine.h:506
const NodeBuilderContext & getBuilderContext() const
Definition ExprEngine.h:267
void ProcessAutomaticObjDtor(const CFGAutomaticObjDtor D, ExplodedNode *Pred, ExplodedNodeSet &Dst)
unsigned getNumVisitedCurrent() const
Definition ExprEngine.h:304
void VisitOffsetOfExpr(const OffsetOfExpr *Ex, ExplodedNode *Pred, ExplodedNodeSet &Dst)
VisitOffsetOfExpr - Transfer function for offsetof.
void evalLoad(ExplodedNodeSet &Dst, const Expr *NodeEx, const Expr *BoundExpr, ExplodedNode *Pred, ProgramStateRef St, SVal location, const ProgramPointTag *tag=nullptr, QualType LoadTy=QualType())
Simulate a read of the result of Ex.
void Visit(const Stmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst)
Visit - Transfer function logic for all statements.
void defaultEvalCall(NodeBuilder &B, ExplodedNode *Pred, const CallEvent &Call, const EvalCallOptions &CallOpts={})
Default implementation of call evaluation.
AnalysisManager & getAnalysisManager()
Definition ExprEngine.h:219
ExplodedGraph & getGraph()
Definition ExprEngine.h:330
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:234
const LocationContext * getCurrLocationContext() const
Get the 'current' location context corresponding to the current work item (elementary analysis step h...
Definition ExprEngine.h:284
void handleUOExtension(ExplodedNode *N, const UnaryOperator *U, NodeBuilder &Bldr)
SValBuilder & getSValBuilder()
Definition ExprEngine.h:230
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:210
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 CFGBlock * getCurrBlock() const
Get the 'current' CFGBlock corresponding to the current work item (elementary analysis step handled b...
Definition ExprEngine.h:290
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:231
void ProcessNewAllocator(const CXXNewExpr *NE, ExplodedNode *Pred)
MemRegion - The root abstract class for all memory regions.
Definition MemRegion.h:98
unsigned blockCount() const
Returns the number of times the current basic block has been visited on the exploded graph path.
Definition CoreEngine.h:219
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.