]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
Update clang to trunk r290819 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / StaticAnalyzer / Core / PathSensitive / ExprEngine.h
1 //===-- ExprEngine.h - Path-Sensitive Expression-Level Dataflow ---*- C++ -*-=//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_EXPRENGINE_H
17 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_EXPRENGINE_H
18
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"
28
29 namespace clang {
30
31 class AnalysisDeclContextManager;
32 class CXXCatchStmt;
33 class CXXConstructExpr;
34 class CXXDeleteExpr;
35 class CXXNewExpr;
36 class CXXTemporaryObjectExpr;
37 class CXXThisExpr;
38 class MaterializeTemporaryExpr;
39 class ObjCAtSynchronizedStmt;
40 class ObjCForCollectionStmt;
41   
42 namespace ento {
43
44 class AnalysisManager;
45 class CallEvent;
46 class CXXConstructorCall;
47
48 class ExprEngine : public SubEngine {
49 public:
50   /// The modes of inlining, which override the default analysis-wide settings.
51   enum InliningModes {
52     /// Follow the default settings for inlining callees.
53     Inline_Regular = 0,
54     /// Do minimal inlining of callees.
55     Inline_Minimal = 0x1
56   };
57
58 private:
59   AnalysisManager &AMgr;
60   
61   AnalysisDeclContextManager &AnalysisDeclContexts;
62
63   CoreEngine Engine;
64
65   /// G - the simulation graph.
66   ExplodedGraph& G;
67
68   /// StateMgr - Object that manages the data for all created states.
69   ProgramStateManager StateMgr;
70
71   /// SymMgr - Object that manages the symbol information.
72   SymbolManager& SymMgr;
73
74   /// svalBuilder - SValBuilder object that creates SVals from expressions.
75   SValBuilder &svalBuilder;
76
77   unsigned int currStmtIdx;
78   const NodeBuilderContext *currBldrCtx;
79   
80   /// Helper object to determine if an Objective-C message expression
81   /// implicitly never returns.
82   ObjCNoReturn ObjCNoRet;
83   
84   /// Whether or not GC is enabled in this analysis.
85   bool ObjCGCEnabled;
86
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.
90   GRBugReporter BR;
91
92   /// The functions which have been analyzed through inlining. This is owned by
93   /// AnalysisConsumer. It can be null.
94   SetOfConstDecls *VisitedCallees;
95
96   /// The flag, which specifies the mode of inlining for the engine.
97   InliningModes HowToInline;
98
99 public:
100   ExprEngine(AnalysisManager &mgr, bool gcEnabled,
101              SetOfConstDecls *VisitedCalleesIn,
102              FunctionSummariesTy *FS,
103              InliningModes HowToInlineIn);
104
105   ~ExprEngine() override;
106
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);
110   }
111
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);
120   }
121
122   /// getContext - Return the ASTContext associated with this analysis.
123   ASTContext &getContext() const { return AMgr.getASTContext(); }
124
125   AnalysisManager &getAnalysisManager() override { return AMgr; }
126
127   CheckerManager &getCheckerManager() const {
128     return *AMgr.getCheckerManager();
129   }
130
131   SValBuilder &getSValBuilder() { return svalBuilder; }
132
133   BugReporter& getBugReporter() { return BR; }
134
135   const NodeBuilderContext &getBuilderContext() {
136     assert(currBldrCtx);
137     return *currBldrCtx;
138   }
139
140   bool isObjCGCEnabled() { return ObjCGCEnabled; }
141
142   const Stmt *getStmt() const;
143
144   void GenerateAutoTransition(ExplodedNode *N);
145   void enqueueEndOfPath(ExplodedNodeSet &S);
146   void GenerateCallExitNode(ExplodedNode *N);
147
148   /// Visualize the ExplodedGraph created by executing the simulation.
149   void ViewGraph(bool trim = false);
150
151   /// Visualize a trimmed ExplodedGraph that only contains paths to the given
152   /// nodes.
153   void ViewGraph(ArrayRef<const ExplodedNode*> Nodes);
154
155   /// getInitialState - Return the initial state used for the root vertex
156   ///  in the ExplodedGraph.
157   ProgramStateRef getInitialState(const LocationContext *InitLoc) override;
158
159   ExplodedGraph& getGraph() { return G; }
160   const ExplodedGraph& getGraph() const { return G; }
161
162   /// \brief Run the analyzer's garbage collection - remove dead symbols and
163   /// bindings from the state.
164   ///
165   /// Checkers can participate in this process with two callbacks:
166   /// \c checkLiveSymbols and \c checkDeadSymbols. See the CheckerDocumentation
167   /// class for more information.
168   ///
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
174   ///        is dead.
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);
191
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;
196
197   void ProcessStmt(const CFGStmt S, ExplodedNode *Pred);
198
199   void ProcessInitializer(const CFGInitializer I, ExplodedNode *Pred);
200
201   void ProcessImplicitDtor(const CFGImplicitDtor D, ExplodedNode *Pred);
202
203   void ProcessNewAllocator(const CXXNewExpr *NE, ExplodedNode *Pred);
204
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);
215
216   /// Called by CoreEngine when processing the entrance of a CFGBlock.
217   void processCFGBlockEntrance(const BlockEdge &L,
218                                NodeBuilderWithSinks &nodeBuilder,
219                                ExplodedNode *Pred) override;
220  
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,
225                      ExplodedNode *Pred,
226                      ExplodedNodeSet &Dst,
227                      const CFGBlock *DstT,
228                      const CFGBlock *DstF) override;
229
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;
238
239   /// Called by CoreEngine.  Used to processing branching behavior
240   /// at static initalizers.
241   void processStaticInitializer(const DeclStmt *DS,
242                                 NodeBuilderContext& BuilderCtx,
243                                 ExplodedNode *Pred,
244                                 ExplodedNodeSet &Dst,
245                                 const CFGBlock *DstT,
246                                 const CFGBlock *DstF) override;
247
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;
251
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;
255
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;
261
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,
265                             ExplodedNode *Pred,
266                             const ReturnStmt *RS = nullptr) override;
267
268   /// Remove dead bindings/symbols before exiting a function.
269   void removeDeadOnEndOfFunction(NodeBuilderContext& BC,
270                                  ExplodedNode *Pred,
271                                  ExplodedNodeSet &Dst);
272
273   /// Generate the entry node of the callee.
274   void processCallEnter(NodeBuilderContext& BC, CallEnter CE,
275                         ExplodedNode *Pred) override;
276
277   /// Generate the sequence of nodes that simulate the call exit and the post
278   /// visit for CallExpr.
279   void processCallExit(ExplodedNode *Pred) override;
280
281   /// Called by CoreEngine when the analysis worklist has terminated.
282   void processEndWorklist(bool hasWorkRemaining) override;
283
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;
288
289   /// processRegionChanges - Called by ProgramStateManager whenever a change is made
290   ///  to the store. Used to update checkers that track region values.
291   ProgramStateRef 
292   processRegionChanges(ProgramStateRef state,
293                        const InvalidatedSymbols *invalidated,
294                        ArrayRef<const MemRegion *> ExplicitRegions,
295                        ArrayRef<const MemRegion *> Regions,
296                        const CallEvent *Call) override;
297
298   /// printState - Called by ProgramStateManager to print checker-specific data.
299   void printState(raw_ostream &Out, ProgramStateRef State,
300                   const char *NL, const char *Sep) override;
301
302   ProgramStateManager& getStateManager() override { return StateMgr; }
303
304   StoreManager& getStoreManager() { return StateMgr.getStoreManager(); }
305
306   ConstraintManager& getConstraintManager() {
307     return StateMgr.getConstraintManager();
308   }
309
310   // FIXME: Remove when we migrate over to just using SValBuilder.
311   BasicValueFactory& getBasicVals() {
312     return StateMgr.getBasicVals();
313   }
314
315   // FIXME: Remove when we migrate over to just using ValueManager.
316   SymbolManager& getSymbolManager() { return SymMgr; }
317   const SymbolManager& getSymbolManager() const { return SymMgr; }
318
319   // Functions for external checking of whether we have unfinished work
320   bool wasBlocksExhausted() const { return Engine.wasBlocksExhausted(); }
321   bool hasEmptyWorkList() const { return !Engine.getWorkList()->hasWork(); }
322   bool hasWorkRemaining() const { return Engine.hasWorkRemaining(); }
323
324   const CoreEngine &getCoreEngine() const { return Engine; }
325
326 public:
327   /// Visit - Transfer function logic for all statements.  Dispatches to
328   ///  other functions that handle specific kinds of statements.
329   void Visit(const Stmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst);
330
331   /// VisitArraySubscriptExpr - Transfer function for array accesses.
332   void VisitLvalArraySubscriptExpr(const ArraySubscriptExpr *Ex,
333                                    ExplodedNode *Pred,
334                                    ExplodedNodeSet &Dst);
335
336   /// VisitGCCAsmStmt - Transfer function logic for inline asm.
337   void VisitGCCAsmStmt(const GCCAsmStmt *A, ExplodedNode *Pred,
338                        ExplodedNodeSet &Dst);
339
340   /// VisitMSAsmStmt - Transfer function logic for MS inline asm.
341   void VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred,
342                       ExplodedNodeSet &Dst);
343
344   /// VisitBlockExpr - Transfer function logic for BlockExprs.
345   void VisitBlockExpr(const BlockExpr *BE, ExplodedNode *Pred, 
346                       ExplodedNodeSet &Dst);
347
348   /// VisitLambdaExpr - Transfer function logic for LambdaExprs.
349   void VisitLambdaExpr(const LambdaExpr *LE, ExplodedNode *Pred, 
350                        ExplodedNodeSet &Dst);
351
352   /// VisitBinaryOperator - Transfer function logic for binary operators.
353   void VisitBinaryOperator(const BinaryOperator* B, ExplodedNode *Pred, 
354                            ExplodedNodeSet &Dst);
355
356
357   /// VisitCall - Transfer function for function calls.
358   void VisitCallExpr(const CallExpr *CE, ExplodedNode *Pred,
359                      ExplodedNodeSet &Dst);
360
361   /// VisitCast - Transfer function logic for all casts (implicit and explicit).
362   void VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNode *Pred,
363                 ExplodedNodeSet &Dst);
364
365   /// VisitCompoundLiteralExpr - Transfer function logic for compound literals.
366   void VisitCompoundLiteralExpr(const CompoundLiteralExpr *CL, 
367                                 ExplodedNode *Pred, ExplodedNodeSet &Dst);
368
369   /// Transfer function logic for DeclRefExprs and BlockDeclRefExprs.
370   void VisitCommonDeclRefExpr(const Expr *DR, const NamedDecl *D,
371                               ExplodedNode *Pred, ExplodedNodeSet &Dst);
372   
373   /// VisitDeclStmt - Transfer function logic for DeclStmts.
374   void VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred, 
375                      ExplodedNodeSet &Dst);
376
377   /// VisitGuardedExpr - Transfer function logic for ?, __builtin_choose
378   void VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R, 
379                         ExplodedNode *Pred, ExplodedNodeSet &Dst);
380   
381   void VisitInitListExpr(const InitListExpr *E, ExplodedNode *Pred,
382                          ExplodedNodeSet &Dst);
383
384   /// VisitLogicalExpr - Transfer function logic for '&&', '||'
385   void VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
386                         ExplodedNodeSet &Dst);
387
388   /// VisitMemberExpr - Transfer function for member expressions.
389   void VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred, 
390                            ExplodedNodeSet &Dst);
391
392   /// VisitMemberExpr - Transfer function for builtin atomic expressions
393   void VisitAtomicExpr(const AtomicExpr *E, ExplodedNode *Pred,
394                        ExplodedNodeSet &Dst);
395
396   /// Transfer function logic for ObjCAtSynchronizedStmts.
397   void VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S,
398                                    ExplodedNode *Pred, ExplodedNodeSet &Dst);
399
400   /// Transfer function logic for computing the lvalue of an Objective-C ivar.
401   void VisitLvalObjCIvarRefExpr(const ObjCIvarRefExpr *DR, ExplodedNode *Pred,
402                                 ExplodedNodeSet &Dst);
403
404   /// VisitObjCForCollectionStmt - Transfer function logic for
405   ///  ObjCForCollectionStmt.
406   void VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S, 
407                                   ExplodedNode *Pred, ExplodedNodeSet &Dst);
408
409   void VisitObjCMessage(const ObjCMessageExpr *ME, ExplodedNode *Pred,
410                         ExplodedNodeSet &Dst);
411
412   /// VisitReturnStmt - Transfer function logic for return statements.
413   void VisitReturnStmt(const ReturnStmt *R, ExplodedNode *Pred, 
414                        ExplodedNodeSet &Dst);
415   
416   /// VisitOffsetOfExpr - Transfer function for offsetof.
417   void VisitOffsetOfExpr(const OffsetOfExpr *Ex, ExplodedNode *Pred,
418                          ExplodedNodeSet &Dst);
419
420   /// VisitUnaryExprOrTypeTraitExpr - Transfer function for sizeof.
421   void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Ex,
422                               ExplodedNode *Pred, ExplodedNodeSet &Dst);
423
424   /// VisitUnaryOperator - Transfer function logic for unary operators.
425   void VisitUnaryOperator(const UnaryOperator* B, ExplodedNode *Pred, 
426                           ExplodedNodeSet &Dst);
427
428   /// Handle ++ and -- (both pre- and post-increment).
429   void VisitIncrementDecrementOperator(const UnaryOperator* U,
430                                        ExplodedNode *Pred,
431                                        ExplodedNodeSet &Dst);
432
433   void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE,
434                                  ExplodedNodeSet &PreVisit,
435                                  ExplodedNodeSet &Dst);
436
437   void VisitCXXCatchStmt(const CXXCatchStmt *CS, ExplodedNode *Pred,
438                          ExplodedNodeSet &Dst);
439
440   void VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred, 
441                         ExplodedNodeSet & Dst);
442
443   void VisitCXXConstructExpr(const CXXConstructExpr *E, ExplodedNode *Pred,
444                              ExplodedNodeSet &Dst);
445
446   void VisitCXXDestructor(QualType ObjectType, const MemRegion *Dest,
447                           const Stmt *S, bool IsBaseDtor,
448                           ExplodedNode *Pred, ExplodedNodeSet &Dst);
449
450   void VisitCXXNewAllocatorCall(const CXXNewExpr *CNE,
451                                 ExplodedNode *Pred,
452                                 ExplodedNodeSet &Dst);
453
454   void VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
455                        ExplodedNodeSet &Dst);
456
457   void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE, ExplodedNode *Pred,
458                           ExplodedNodeSet &Dst);
459
460   /// Create a C++ temporary object for an rvalue.
461   void CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME,
462                                 ExplodedNode *Pred, 
463                                 ExplodedNodeSet &Dst);
464   
465   /// evalEagerlyAssumeBinOpBifurcation - Given the nodes in 'Src', eagerly assume symbolic
466   ///  expressions of the form 'x != 0' and generate new nodes (stored in Dst)
467   ///  with those assumptions.
468   void evalEagerlyAssumeBinOpBifurcation(ExplodedNodeSet &Dst, ExplodedNodeSet &Src, 
469                          const Expr *Ex);
470   
471   std::pair<const ProgramPointTag *, const ProgramPointTag*>
472     geteagerlyAssumeBinOpBifurcationTags();
473
474   SVal evalMinus(SVal X) {
475     return X.isValid() ? svalBuilder.evalMinus(X.castAs<NonLoc>()) : X;
476   }
477
478   SVal evalComplement(SVal X) {
479     return X.isValid() ? svalBuilder.evalComplement(X.castAs<NonLoc>()) : X;
480   }
481
482   ProgramStateRef handleLValueBitCast(ProgramStateRef state, const Expr *Ex,
483                                       const LocationContext *LCtx, QualType T,
484                                       QualType ExTy, const CastExpr *CastE,
485                                       StmtNodeBuilder &Bldr,
486                                       ExplodedNode *Pred);
487
488   ProgramStateRef handleLVectorSplat(ProgramStateRef state,
489                                      const LocationContext *LCtx,
490                                      const CastExpr *CastE,
491                                      StmtNodeBuilder &Bldr,
492                                      ExplodedNode *Pred);
493
494   void handleUOExtension(ExplodedNodeSet::iterator I,
495                          const UnaryOperator* U,
496                          StmtNodeBuilder &Bldr);
497
498 public:
499
500   SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
501                  NonLoc L, NonLoc R, QualType T) {
502     return svalBuilder.evalBinOpNN(state, op, L, R, T);
503   }
504
505   SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
506                  NonLoc L, SVal R, QualType T) {
507     return R.isValid() ? svalBuilder.evalBinOpNN(state, op, L,
508                                                  R.castAs<NonLoc>(), T) : R;
509   }
510
511   SVal evalBinOp(ProgramStateRef ST, BinaryOperator::Opcode Op,
512                  SVal LHS, SVal RHS, QualType T) {
513     return svalBuilder.evalBinOp(ST, Op, LHS, RHS, T);
514   }
515   
516 protected:
517   /// evalBind - Handle the semantics of binding a value to a specific location.
518   ///  This method is used by evalStore, VisitDeclStmt, and others.
519   void evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE, ExplodedNode *Pred,
520                 SVal location, SVal Val, bool atDeclInit = false,
521                 const ProgramPoint *PP = nullptr);
522
523   /// Call PointerEscape callback when a value escapes as a result of bind.
524   ProgramStateRef processPointerEscapedOnBind(ProgramStateRef State,
525                                               SVal Loc, SVal Val) override;
526   /// Call PointerEscape callback when a value escapes as a result of
527   /// region invalidation.
528   /// \param[in] ITraits Specifies invalidation traits for regions/symbols.
529   ProgramStateRef notifyCheckersOfPointerEscape(
530                            ProgramStateRef State,
531                            const InvalidatedSymbols *Invalidated,
532                            ArrayRef<const MemRegion *> ExplicitRegions,
533                            ArrayRef<const MemRegion *> Regions,
534                            const CallEvent *Call,
535                            RegionAndSymbolInvalidationTraits &ITraits) override;
536
537 public:
538   // FIXME: 'tag' should be removed, and a LocationContext should be used
539   // instead.
540   // FIXME: Comment on the meaning of the arguments, when 'St' may not
541   // be the same as Pred->state, and when 'location' may not be the
542   // same as state->getLValue(Ex).
543   /// Simulate a read of the result of Ex.
544   void evalLoad(ExplodedNodeSet &Dst,
545                 const Expr *NodeEx,  /* Eventually will be a CFGStmt */
546                 const Expr *BoundExpr,
547                 ExplodedNode *Pred,
548                 ProgramStateRef St,
549                 SVal location,
550                 const ProgramPointTag *tag = nullptr,
551                 QualType LoadTy = QualType());
552
553   // FIXME: 'tag' should be removed, and a LocationContext should be used
554   // instead.
555   void evalStore(ExplodedNodeSet &Dst, const Expr *AssignE, const Expr *StoreE,
556                  ExplodedNode *Pred, ProgramStateRef St, SVal TargetLV, SVal Val,
557                  const ProgramPointTag *tag = nullptr);
558
559   /// \brief Create a new state in which the call return value is binded to the
560   /// call origin expression.
561   ProgramStateRef bindReturnValue(const CallEvent &Call,
562                                   const LocationContext *LCtx,
563                                   ProgramStateRef State);
564
565   /// Evaluate a call, running pre- and post-call checks and allowing checkers
566   /// to be responsible for handling the evaluation of the call itself.
567   void evalCall(ExplodedNodeSet &Dst, ExplodedNode *Pred,
568                 const CallEvent &Call);
569
570   /// \brief Default implementation of call evaluation.
571   void defaultEvalCall(NodeBuilder &B, ExplodedNode *Pred,
572                        const CallEvent &Call);
573 private:
574   void evalLoadCommon(ExplodedNodeSet &Dst,
575                       const Expr *NodeEx,  /* Eventually will be a CFGStmt */
576                       const Expr *BoundEx,
577                       ExplodedNode *Pred,
578                       ProgramStateRef St,
579                       SVal location,
580                       const ProgramPointTag *tag,
581                       QualType LoadTy);
582
583   // FIXME: 'tag' should be removed, and a LocationContext should be used
584   // instead.
585   void evalLocation(ExplodedNodeSet &Dst,
586                     const Stmt *NodeEx, /* This will eventually be a CFGStmt */
587                     const Stmt *BoundEx,
588                     ExplodedNode *Pred,
589                     ProgramStateRef St, SVal location,
590                     const ProgramPointTag *tag, bool isLoad);
591
592   /// Count the stack depth and determine if the call is recursive.
593   void examineStackFrames(const Decl *D, const LocationContext *LCtx,
594                           bool &IsRecursive, unsigned &StackDepth);
595
596   /// Checks our policies and decides weither the given call should be inlined.
597   bool shouldInlineCall(const CallEvent &Call, const Decl *D,
598                         const ExplodedNode *Pred);
599
600   bool inlineCall(const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
601                   ExplodedNode *Pred, ProgramStateRef State);
602
603   /// \brief Conservatively evaluate call by invalidating regions and binding
604   /// a conjured return value.
605   void conservativeEvalCall(const CallEvent &Call, NodeBuilder &Bldr,
606                             ExplodedNode *Pred, ProgramStateRef State);
607
608   /// \brief Either inline or process the call conservatively (or both), based
609   /// on DynamicDispatchBifurcation data.
610   void BifurcateCall(const MemRegion *BifurReg,
611                      const CallEvent &Call, const Decl *D, NodeBuilder &Bldr,
612                      ExplodedNode *Pred);
613
614   bool replayWithoutInlining(ExplodedNode *P, const LocationContext *CalleeLC);
615
616   /// Models a trivial copy or move constructor or trivial assignment operator
617   /// call with a simple bind.
618   void performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
619                           const CallEvent &Call);
620
621   /// If the value of the given expression is a NonLoc, copy it into a new
622   /// temporary object region, and replace the value of the expression with
623   /// that.
624   ///
625   /// If \p ResultE is provided, the new region will be bound to this expression
626   /// instead of \p E.
627   ProgramStateRef createTemporaryRegionIfNeeded(ProgramStateRef State,
628                                                 const LocationContext *LC,
629                                                 const Expr *E,
630                                                 const Expr *ResultE = nullptr);
631
632   /// For a DeclStmt or CXXInitCtorInitializer, walk backward in the current CFG
633   /// block to find the constructor expression that directly constructed into
634   /// the storage for this statement. Returns null if the constructor for this
635   /// statement created a temporary object region rather than directly
636   /// constructing into an existing region.
637   const CXXConstructExpr *findDirectConstructorForCurrentCFGElement();
638
639   /// For a CXXConstructExpr, walk forward in the current CFG block to find the
640   /// CFGElement for the DeclStmt or CXXInitCtorInitializer for which is
641   /// directly constructed by this constructor. Returns None if the current
642   /// constructor expression did not directly construct into an existing
643   /// region.
644   Optional<CFGElement> findElementDirectlyInitializedByCurrentConstructor();
645
646   /// For a given constructor, look forward in the current CFG block to
647   /// determine the region into which an object will be constructed by \p CE.
648   /// Returns either a field or local variable region if the object will be
649   /// directly constructed in an existing region or a temporary object region
650   /// if not.
651   const MemRegion *getRegionForConstructedObject(const CXXConstructExpr *CE,
652                                                  ExplodedNode *Pred);
653 };
654
655 /// Traits for storing the call processing policy inside GDM.
656 /// The GDM stores the corresponding CallExpr pointer.
657 // FIXME: This does not use the nice trait macros because it must be accessible
658 // from multiple translation units.
659 struct ReplayWithoutInlining{};
660 template <>
661 struct ProgramStateTrait<ReplayWithoutInlining> :
662   public ProgramStatePartialTrait<const void*> {
663   static void *GDMIndex() { static int index = 0; return &index; }
664 };
665
666 } // end ento namespace
667
668 } // end clang namespace
669
670 #endif