1 //===-- ExprEngine.h - Path-Sensitive Expression-Level Dataflow ---*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a meta-engine for path-sensitive dataflow analysis that
11 // is built on CoreEngine, but provides the boilerplate to execute transfer
12 // functions and build the ExplodedGraph at the expression level.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_EXPRENGINE_H
17 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_EXPRENGINE_H
19 #include "clang/AST/Expr.h"
20 #include "clang/AST/Type.h"
21 #include "clang/Analysis/DomainSpecific/ObjCNoReturn.h"
22 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
23 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
24 #include "clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h"
25 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
26 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
27 #include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
31 class AnalysisDeclContextManager;
33 class CXXConstructExpr;
36 class CXXTemporaryObjectExpr;
38 class MaterializeTemporaryExpr;
39 class ObjCAtSynchronizedStmt;
40 class ObjCForCollectionStmt;
44 class AnalysisManager;
46 class CXXConstructorCall;
48 class ExprEngine : public SubEngine {
50 /// The modes of inlining, which override the default analysis-wide settings.
52 /// Follow the default settings for inlining callees.
54 /// Do minimal inlining of callees.
59 AnalysisManager &AMgr;
61 AnalysisDeclContextManager &AnalysisDeclContexts;
65 /// G - the simulation graph.
68 /// StateMgr - Object that manages the data for all created states.
69 ProgramStateManager StateMgr;
71 /// SymMgr - Object that manages the symbol information.
72 SymbolManager& SymMgr;
74 /// svalBuilder - SValBuilder object that creates SVals from expressions.
75 SValBuilder &svalBuilder;
77 unsigned int currStmtIdx;
78 const NodeBuilderContext *currBldrCtx;
80 /// Helper object to determine if an Objective-C message expression
81 /// implicitly never returns.
82 ObjCNoReturn ObjCNoRet;
84 /// Whether or not GC is enabled in this analysis.
87 /// The BugReporter associated with this engine. It is important that
88 /// this object be placed at the very end of member variables so that its
89 /// destructor is called before the rest of the ExprEngine is destroyed.
92 /// The functions which have been analyzed through inlining. This is owned by
93 /// AnalysisConsumer. It can be null.
94 SetOfConstDecls *VisitedCallees;
96 /// The flag, which specifies the mode of inlining for the engine.
97 InliningModes HowToInline;
100 ExprEngine(AnalysisManager &mgr, bool gcEnabled,
101 SetOfConstDecls *VisitedCalleesIn,
102 FunctionSummariesTy *FS,
103 InliningModes HowToInlineIn);
105 ~ExprEngine() override;
107 /// Returns true if there is still simulation state on the worklist.
108 bool ExecuteWorkList(const LocationContext *L, unsigned Steps = 150000) {
109 return Engine.ExecuteWorkList(L, Steps, nullptr);
112 /// Execute the work list with an initial state. Nodes that reaches the exit
113 /// of the function are added into the Dst set, which represent the exit
114 /// state of the function call. Returns true if there is still simulation
115 /// state on the worklist.
116 bool ExecuteWorkListWithInitialState(const LocationContext *L, unsigned Steps,
117 ProgramStateRef InitState,
118 ExplodedNodeSet &Dst) {
119 return Engine.ExecuteWorkListWithInitialState(L, Steps, InitState, Dst);
122 /// getContext - Return the ASTContext associated with this analysis.
123 ASTContext &getContext() const { return AMgr.getASTContext(); }
125 AnalysisManager &getAnalysisManager() override { return AMgr; }
127 CheckerManager &getCheckerManager() const {
128 return *AMgr.getCheckerManager();
131 SValBuilder &getSValBuilder() { return svalBuilder; }
133 BugReporter& getBugReporter() { return BR; }
135 const NodeBuilderContext &getBuilderContext() {
140 bool isObjCGCEnabled() { return ObjCGCEnabled; }
142 const Stmt *getStmt() const;
144 void GenerateAutoTransition(ExplodedNode *N);
145 void enqueueEndOfPath(ExplodedNodeSet &S);
146 void GenerateCallExitNode(ExplodedNode *N);
148 /// Visualize the ExplodedGraph created by executing the simulation.
149 void ViewGraph(bool trim = false);
151 /// Visualize a trimmed ExplodedGraph that only contains paths to the given
153 void ViewGraph(ArrayRef<const ExplodedNode*> Nodes);
155 /// getInitialState - Return the initial state used for the root vertex
156 /// in the ExplodedGraph.
157 ProgramStateRef getInitialState(const LocationContext *InitLoc) override;
159 ExplodedGraph& getGraph() { return G; }
160 const ExplodedGraph& getGraph() const { return G; }
162 /// \brief Run the analyzer's garbage collection - remove dead symbols and
163 /// bindings from the state.
165 /// Checkers can participate in this process with two callbacks:
166 /// \c checkLiveSymbols and \c checkDeadSymbols. See the CheckerDocumentation
167 /// class for more information.
169 /// \param Node The predecessor node, from which the processing should start.
170 /// \param Out The returned set of output nodes.
171 /// \param ReferenceStmt The statement which is about to be processed.
172 /// Everything needed for this statement should be considered live.
173 /// A null statement means that everything in child LocationContexts
175 /// \param LC The location context of the \p ReferenceStmt. A null location
176 /// context means that we have reached the end of analysis and that
177 /// all statements and local variables should be considered dead.
178 /// \param DiagnosticStmt Used as a location for any warnings that should
179 /// occur while removing the dead (e.g. leaks). By default, the
180 /// \p ReferenceStmt is used.
181 /// \param K Denotes whether this is a pre- or post-statement purge. This
182 /// must only be ProgramPoint::PostStmtPurgeDeadSymbolsKind if an
183 /// entire location context is being cleared, in which case the
184 /// \p ReferenceStmt must either be a ReturnStmt or \c NULL. Otherwise,
185 /// it must be ProgramPoint::PreStmtPurgeDeadSymbolsKind (the default)
186 /// and \p ReferenceStmt must be valid (non-null).
187 void removeDead(ExplodedNode *Node, ExplodedNodeSet &Out,
188 const Stmt *ReferenceStmt, const LocationContext *LC,
189 const Stmt *DiagnosticStmt = nullptr,
190 ProgramPoint::Kind K = ProgramPoint::PreStmtPurgeDeadSymbolsKind);
192 /// processCFGElement - Called by CoreEngine. Used to generate new successor
193 /// nodes by processing the 'effects' of a CFG element.
194 void processCFGElement(const CFGElement E, ExplodedNode *Pred,
195 unsigned StmtIdx, NodeBuilderContext *Ctx) override;
197 void ProcessStmt(const CFGStmt S, ExplodedNode *Pred);
199 void ProcessInitializer(const CFGInitializer I, ExplodedNode *Pred);
201 void ProcessImplicitDtor(const CFGImplicitDtor D, ExplodedNode *Pred);
203 void ProcessNewAllocator(const CXXNewExpr *NE, ExplodedNode *Pred);
205 void ProcessAutomaticObjDtor(const CFGAutomaticObjDtor D,
206 ExplodedNode *Pred, ExplodedNodeSet &Dst);
207 void ProcessDeleteDtor(const CFGDeleteDtor D,
208 ExplodedNode *Pred, ExplodedNodeSet &Dst);
209 void ProcessBaseDtor(const CFGBaseDtor D,
210 ExplodedNode *Pred, ExplodedNodeSet &Dst);
211 void ProcessMemberDtor(const CFGMemberDtor D,
212 ExplodedNode *Pred, ExplodedNodeSet &Dst);
213 void ProcessTemporaryDtor(const CFGTemporaryDtor D,
214 ExplodedNode *Pred, ExplodedNodeSet &Dst);
216 /// Called by CoreEngine when processing the entrance of a CFGBlock.
217 void processCFGBlockEntrance(const BlockEdge &L,
218 NodeBuilderWithSinks &nodeBuilder,
219 ExplodedNode *Pred) override;
221 /// ProcessBranch - Called by CoreEngine. Used to generate successor
222 /// nodes by processing the 'effects' of a branch condition.
223 void processBranch(const Stmt *Condition, const Stmt *Term,
224 NodeBuilderContext& BuilderCtx,
226 ExplodedNodeSet &Dst,
227 const CFGBlock *DstT,
228 const CFGBlock *DstF) override;
230 /// Called by CoreEngine.
231 /// Used to generate successor nodes for temporary destructors depending
232 /// on whether the corresponding constructor was visited.
233 void processCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE,
234 NodeBuilderContext &BldCtx,
235 ExplodedNode *Pred, ExplodedNodeSet &Dst,
236 const CFGBlock *DstT,
237 const CFGBlock *DstF) override;
239 /// Called by CoreEngine. Used to processing branching behavior
240 /// at static initializers.
241 void processStaticInitializer(const DeclStmt *DS,
242 NodeBuilderContext& BuilderCtx,
244 ExplodedNodeSet &Dst,
245 const CFGBlock *DstT,
246 const CFGBlock *DstF) override;
248 /// processIndirectGoto - Called by CoreEngine. Used to generate successor
249 /// nodes by processing the 'effects' of a computed goto jump.
250 void processIndirectGoto(IndirectGotoNodeBuilder& builder) override;
252 /// ProcessSwitch - Called by CoreEngine. Used to generate successor
253 /// nodes by processing the 'effects' of a switch statement.
254 void processSwitch(SwitchNodeBuilder& builder) override;
256 /// Called by CoreEngine. Used to notify checkers that processing a
257 /// function has begun. Called for both inlined and and top-level functions.
258 void processBeginOfFunction(NodeBuilderContext &BC,
259 ExplodedNode *Pred, ExplodedNodeSet &Dst,
260 const BlockEdge &L) override;
262 /// Called by CoreEngine. Used to notify checkers that processing a
263 /// function has ended. Called for both inlined and and top-level functions.
264 void processEndOfFunction(NodeBuilderContext& BC,
266 const ReturnStmt *RS = nullptr) override;
268 /// Remove dead bindings/symbols before exiting a function.
269 void removeDeadOnEndOfFunction(NodeBuilderContext& BC,
271 ExplodedNodeSet &Dst);
273 /// Generate the entry node of the callee.
274 void processCallEnter(NodeBuilderContext& BC, CallEnter CE,
275 ExplodedNode *Pred) override;
277 /// Generate the sequence of nodes that simulate the call exit and the post
278 /// visit for CallExpr.
279 void processCallExit(ExplodedNode *Pred) override;
281 /// Called by CoreEngine when the analysis worklist has terminated.
282 void processEndWorklist(bool hasWorkRemaining) override;
284 /// evalAssume - Callback function invoked by the ConstraintManager when
285 /// making assumptions about state values.
286 ProgramStateRef processAssume(ProgramStateRef state, SVal cond,
287 bool assumption) override;
289 /// processRegionChanges - Called by ProgramStateManager whenever a change is made
290 /// to the store. Used to update checkers that track region values.
292 processRegionChanges(ProgramStateRef state,
293 const InvalidatedSymbols *invalidated,
294 ArrayRef<const MemRegion *> ExplicitRegions,
295 ArrayRef<const MemRegion *> Regions,
296 const LocationContext *LCtx,
297 const CallEvent *Call) override;
299 /// printState - Called by ProgramStateManager to print checker-specific data.
300 void printState(raw_ostream &Out, ProgramStateRef State,
301 const char *NL, const char *Sep) override;
303 ProgramStateManager& getStateManager() override { return StateMgr; }
305 StoreManager& getStoreManager() { return StateMgr.getStoreManager(); }
307 ConstraintManager& getConstraintManager() {
308 return StateMgr.getConstraintManager();
311 // FIXME: Remove when we migrate over to just using SValBuilder.
312 BasicValueFactory& getBasicVals() {
313 return StateMgr.getBasicVals();
316 // FIXME: Remove when we migrate over to just using ValueManager.
317 SymbolManager& getSymbolManager() { return SymMgr; }
318 const SymbolManager& getSymbolManager() const { return SymMgr; }
320 // Functions for external checking of whether we have unfinished work
321 bool wasBlocksExhausted() const { return Engine.wasBlocksExhausted(); }
322 bool hasEmptyWorkList() const { return !Engine.getWorkList()->hasWork(); }
323 bool hasWorkRemaining() const { return Engine.hasWorkRemaining(); }
325 const CoreEngine &getCoreEngine() const { return Engine; }
328 /// Visit - Transfer function logic for all statements. Dispatches to
329 /// other functions that handle specific kinds of statements.
330 void Visit(const Stmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst);
332 /// VisitArraySubscriptExpr - Transfer function for array accesses.
333 void VisitLvalArraySubscriptExpr(const ArraySubscriptExpr *Ex,
335 ExplodedNodeSet &Dst);
337 /// VisitGCCAsmStmt - Transfer function logic for inline asm.
338 void VisitGCCAsmStmt(const GCCAsmStmt *A, ExplodedNode *Pred,
339 ExplodedNodeSet &Dst);
341 /// VisitMSAsmStmt - Transfer function logic for MS inline asm.
342 void VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred,
343 ExplodedNodeSet &Dst);
345 /// VisitBlockExpr - Transfer function logic for BlockExprs.
346 void VisitBlockExpr(const BlockExpr *BE, ExplodedNode *Pred,
347 ExplodedNodeSet &Dst);
349 /// VisitLambdaExpr - Transfer function logic for LambdaExprs.
350 void VisitLambdaExpr(const LambdaExpr *LE, ExplodedNode *Pred,
351 ExplodedNodeSet &Dst);
353 /// VisitBinaryOperator - Transfer function logic for binary operators.
354 void VisitBinaryOperator(const BinaryOperator* B, ExplodedNode *Pred,
355 ExplodedNodeSet &Dst);
358 /// VisitCall - Transfer function for function calls.
359 void VisitCallExpr(const CallExpr *CE, ExplodedNode *Pred,
360 ExplodedNodeSet &Dst);
362 /// VisitCast - Transfer function logic for all casts (implicit and explicit).
363 void VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNode *Pred,
364 ExplodedNodeSet &Dst);
366 /// VisitCompoundLiteralExpr - Transfer function logic for compound literals.
367 void VisitCompoundLiteralExpr(const CompoundLiteralExpr *CL,
368 ExplodedNode *Pred, ExplodedNodeSet &Dst);
370 /// Transfer function logic for DeclRefExprs and BlockDeclRefExprs.
371 void VisitCommonDeclRefExpr(const Expr *DR, const NamedDecl *D,
372 ExplodedNode *Pred, ExplodedNodeSet &Dst);
374 /// VisitDeclStmt - Transfer function logic for DeclStmts.
375 void VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred,
376 ExplodedNodeSet &Dst);
378 /// VisitGuardedExpr - Transfer function logic for ?, __builtin_choose
379 void VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R,
380 ExplodedNode *Pred, ExplodedNodeSet &Dst);
382 void VisitInitListExpr(const InitListExpr *E, ExplodedNode *Pred,
383 ExplodedNodeSet &Dst);
385 /// VisitLogicalExpr - Transfer function logic for '&&', '||'
386 void VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
387 ExplodedNodeSet &Dst);
389 /// VisitMemberExpr - Transfer function for member expressions.
390 void VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred,
391 ExplodedNodeSet &Dst);
393 /// VisitMemberExpr - Transfer function for builtin atomic expressions
394 void VisitAtomicExpr(const AtomicExpr *E, ExplodedNode *Pred,
395 ExplodedNodeSet &Dst);
397 /// Transfer function logic for ObjCAtSynchronizedStmts.
398 void VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S,
399 ExplodedNode *Pred, ExplodedNodeSet &Dst);
401 /// Transfer function logic for computing the lvalue of an Objective-C ivar.
402 void VisitLvalObjCIvarRefExpr(const ObjCIvarRefExpr *DR, ExplodedNode *Pred,
403 ExplodedNodeSet &Dst);
405 /// VisitObjCForCollectionStmt - Transfer function logic for
406 /// ObjCForCollectionStmt.
407 void VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S,
408 ExplodedNode *Pred, ExplodedNodeSet &Dst);
410 void VisitObjCMessage(const ObjCMessageExpr *ME, ExplodedNode *Pred,
411 ExplodedNodeSet &Dst);
413 /// VisitReturnStmt - Transfer function logic for return statements.
414 void VisitReturnStmt(const ReturnStmt *R, ExplodedNode *Pred,
415 ExplodedNodeSet &Dst);
417 /// VisitOffsetOfExpr - Transfer function for offsetof.
418 void VisitOffsetOfExpr(const OffsetOfExpr *Ex, ExplodedNode *Pred,
419 ExplodedNodeSet &Dst);
421 /// VisitUnaryExprOrTypeTraitExpr - Transfer function for sizeof.
422 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Ex,
423 ExplodedNode *Pred, ExplodedNodeSet &Dst);
425 /// VisitUnaryOperator - Transfer function logic for unary operators.
426 void VisitUnaryOperator(const UnaryOperator* B, ExplodedNode *Pred,
427 ExplodedNodeSet &Dst);
429 /// Handle ++ and -- (both pre- and post-increment).
430 void VisitIncrementDecrementOperator(const UnaryOperator* U,
432 ExplodedNodeSet &Dst);
434 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE,
435 ExplodedNodeSet &PreVisit,
436 ExplodedNodeSet &Dst);
438 void VisitCXXCatchStmt(const CXXCatchStmt *CS, ExplodedNode *Pred,
439 ExplodedNodeSet &Dst);
441 void VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred,
442 ExplodedNodeSet & Dst);
444 void VisitCXXConstructExpr(const CXXConstructExpr *E, ExplodedNode *Pred,
445 ExplodedNodeSet &Dst);
447 void VisitCXXDestructor(QualType ObjectType, const MemRegion *Dest,
448 const Stmt *S, bool IsBaseDtor,
449 ExplodedNode *Pred, ExplodedNodeSet &Dst);
451 void VisitCXXNewAllocatorCall(const CXXNewExpr *CNE,
453 ExplodedNodeSet &Dst);
455 void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
456 ExplodedNodeSet &Dst);
458 void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE, ExplodedNode *Pred,
459 ExplodedNodeSet &Dst);
461 /// Create a C++ temporary object for an rvalue.
462 void CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME,
464 ExplodedNodeSet &Dst);
466 /// evalEagerlyAssumeBinOpBifurcation - Given the nodes in 'Src', eagerly assume symbolic
467 /// expressions of the form 'x != 0' and generate new nodes (stored in Dst)
468 /// with those assumptions.
469 void evalEagerlyAssumeBinOpBifurcation(ExplodedNodeSet &Dst, ExplodedNodeSet &Src,
472 std::pair<const ProgramPointTag *, const ProgramPointTag*>
473 geteagerlyAssumeBinOpBifurcationTags();
475 SVal evalMinus(SVal X) {
476 return X.isValid() ? svalBuilder.evalMinus(X.castAs<NonLoc>()) : X;
479 SVal evalComplement(SVal X) {
480 return X.isValid() ? svalBuilder.evalComplement(X.castAs<NonLoc>()) : X;
483 ProgramStateRef handleLValueBitCast(ProgramStateRef state, const Expr *Ex,
484 const LocationContext *LCtx, QualType T,
485 QualType ExTy, const CastExpr *CastE,
486 StmtNodeBuilder &Bldr,
489 ProgramStateRef handleLVectorSplat(ProgramStateRef state,
490 const LocationContext *LCtx,
491 const CastExpr *CastE,
492 StmtNodeBuilder &Bldr,
495 void handleUOExtension(ExplodedNodeSet::iterator I,
496 const UnaryOperator* U,
497 StmtNodeBuilder &Bldr);
501 SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
502 NonLoc L, NonLoc R, QualType T) {
503 return svalBuilder.evalBinOpNN(state, op, L, R, T);
506 SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
507 NonLoc L, SVal R, QualType T) {
508 return R.isValid() ? svalBuilder.evalBinOpNN(state, op, L,
509 R.castAs<NonLoc>(), T) : R;
512 SVal evalBinOp(ProgramStateRef ST, BinaryOperator::Opcode Op,
513 SVal LHS, SVal RHS, QualType T) {
514 return svalBuilder.evalBinOp(ST, Op, LHS, RHS, T);
518 /// evalBind - Handle the semantics of binding a value to a specific location.
519 /// This method is used by evalStore, VisitDeclStmt, and others.
520 void evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE, ExplodedNode *Pred,
521 SVal location, SVal Val, bool atDeclInit = false,
522 const ProgramPoint *PP = nullptr);
524 /// Call PointerEscape callback when a value escapes as a result of bind.
525 ProgramStateRef processPointerEscapedOnBind(ProgramStateRef State,
528 const LocationContext *LCtx) override;
529 /// Call PointerEscape callback when a value escapes as a result of
530 /// region invalidation.
531 /// \param[in] ITraits Specifies invalidation traits for regions/symbols.
532 ProgramStateRef notifyCheckersOfPointerEscape(
533 ProgramStateRef State,
534 const InvalidatedSymbols *Invalidated,
535 ArrayRef<const MemRegion *> ExplicitRegions,
536 ArrayRef<const MemRegion *> Regions,
537 const CallEvent *Call,
538 RegionAndSymbolInvalidationTraits &ITraits) override;
541 // FIXME: 'tag' should be removed, and a LocationContext should be used
543 // FIXME: Comment on the meaning of the arguments, when 'St' may not
544 // be the same as Pred->state, and when 'location' may not be the
545 // same as state->getLValue(Ex).
546 /// Simulate a read of the result of Ex.
547 void evalLoad(ExplodedNodeSet &Dst,
548 const Expr *NodeEx, /* Eventually will be a CFGStmt */
549 const Expr *BoundExpr,
553 const ProgramPointTag *tag = nullptr,
554 QualType LoadTy = QualType());
556 // FIXME: 'tag' should be removed, and a LocationContext should be used
558 void evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, const Expr *StoreE,
559 ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val,
560 const ProgramPointTag *tag = nullptr);
562 /// \brief Create a new state in which the call return value is binded to the
563 /// call origin expression.
564 ProgramStateRef bindReturnValue(const CallEvent &Call,
565 const LocationContext *LCtx,
566 ProgramStateRef State);
568 /// Evaluate a call, running pre- and post-call checks and allowing checkers
569 /// to be responsible for handling the evaluation of the call itself.
570 void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred,
571 const CallEvent &Call);
573 /// \brief Default implementation of call evaluation.
574 void defaultEvalCall(NodeBuilder &B, ExplodedNode *Pred,
575 const CallEvent &Call);
577 void evalLoadCommon(ExplodedNodeSet &Dst,
578 const Expr *NodeEx, /* Eventually will be a CFGStmt */
583 const ProgramPointTag *tag,
586 // FIXME: 'tag' should be removed, and a LocationContext should be used
588 void evalLocation(ExplodedNodeSet &Dst,
589 const Stmt *NodeEx, /* This will eventually be a CFGStmt */
592 ProgramStateRef St, SVal location,
593 const ProgramPointTag *tag, bool isLoad);
595 /// Count the stack depth and determine if the call is recursive.
596 void examineStackFrames(const Decl *D, const LocationContext *LCtx,
597 bool &IsRecursive, unsigned &StackDepth);
599 /// Checks our policies and decides weither the given call should be inlined.
600 bool shouldInlineCall(const CallEvent &Call, const Decl *D,
601 const ExplodedNode *Pred);
603 bool inlineCall(const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
604 ExplodedNode *Pred, ProgramStateRef State);
606 /// \brief Conservatively evaluate call by invalidating regions and binding
607 /// a conjured return value.
608 void conservativeEvalCall(const CallEvent &Call, NodeBuilder &Bldr,
609 ExplodedNode *Pred, ProgramStateRef State);
611 /// \brief Either inline or process the call conservatively (or both), based
612 /// on DynamicDispatchBifurcation data.
613 void BifurcateCall(const MemRegion *BifurReg,
614 const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
617 bool replayWithoutInlining(ExplodedNode *P, const LocationContext *CalleeLC);
619 /// Models a trivial copy or move constructor or trivial assignment operator
620 /// call with a simple bind.
621 void performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
622 const CallEvent &Call);
624 /// If the value of the given expression \p InitWithAdjustments is a NonLoc,
625 /// copy it into a new temporary object region, and replace the value of the
626 /// expression with that.
628 /// If \p Result is provided, the new region will be bound to this expression
629 /// instead of \p InitWithAdjustments.
630 ProgramStateRef createTemporaryRegionIfNeeded(ProgramStateRef State,
631 const LocationContext *LC,
632 const Expr *InitWithAdjustments,
633 const Expr *Result = nullptr);
635 /// For a DeclStmt or CXXInitCtorInitializer, walk backward in the current CFG
636 /// block to find the constructor expression that directly constructed into
637 /// the storage for this statement. Returns null if the constructor for this
638 /// statement created a temporary object region rather than directly
639 /// constructing into an existing region.
640 const CXXConstructExpr *findDirectConstructorForCurrentCFGElement();
642 /// For a CXXConstructExpr, walk forward in the current CFG block to find the
643 /// CFGElement for the DeclStmt or CXXInitCtorInitializer for which is
644 /// directly constructed by this constructor. Returns None if the current
645 /// constructor expression did not directly construct into an existing
647 Optional<CFGElement> findElementDirectlyInitializedByCurrentConstructor();
649 /// For a given constructor, look forward in the current CFG block to
650 /// determine the region into which an object will be constructed by \p CE.
651 /// Returns either a field or local variable region if the object will be
652 /// directly constructed in an existing region or a temporary object region
654 const MemRegion *getRegionForConstructedObject(const CXXConstructExpr *CE,
658 /// Traits for storing the call processing policy inside GDM.
659 /// The GDM stores the corresponding CallExpr pointer.
660 // FIXME: This does not use the nice trait macros because it must be accessible
661 // from multiple translation units.
662 struct ReplayWithoutInlining{};
664 struct ProgramStateTrait<ReplayWithoutInlining> :
665 public ProgramStatePartialTrait<const void*> {
666 static void *GDMIndex() { static int index = 0; return &index; }
669 } // end ento namespace
671 } // end clang namespace