110e25031STed Kremenek //===- ExprEngineCXX.cpp - ExprEngine support for C++ -----------*- C++ -*-===//
210e25031STed Kremenek //
310e25031STed Kremenek //                     The LLVM Compiler Infrastructure
410e25031STed Kremenek //
510e25031STed Kremenek // This file is distributed under the University of Illinois Open Source
610e25031STed Kremenek // License. See LICENSE.TXT for details.
710e25031STed Kremenek //
810e25031STed Kremenek //===----------------------------------------------------------------------===//
910e25031STed Kremenek //
1010e25031STed Kremenek //  This file defines the C++ expression evaluation engine.
1110e25031STed Kremenek //
1210e25031STed Kremenek //===----------------------------------------------------------------------===//
1310e25031STed Kremenek 
1410e25031STed Kremenek #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
1510e25031STed Kremenek #include "clang/AST/DeclCXX.h"
168fdb59f9STed Kremenek #include "clang/AST/StmtCXX.h"
1717a8757aSJordan Rose #include "clang/Basic/PrettyStackTrace.h"
183a02247dSChandler Carruth #include "clang/StaticAnalyzer/Core/CheckerManager.h"
193a02247dSChandler Carruth #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
203a02247dSChandler Carruth #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
2110e25031STed Kremenek 
2210e25031STed Kremenek using namespace clang;
2310e25031STed Kremenek using namespace ento;
2410e25031STed Kremenek 
2510e25031STed Kremenek void ExprEngine::CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME,
2610e25031STed Kremenek                                           ExplodedNode *Pred,
2710e25031STed Kremenek                                           ExplodedNodeSet &Dst) {
28d94854a4STed Kremenek   StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
292a14c695STed Kremenek   const Expr *tempExpr = ME->GetTemporaryExpr()->IgnoreParens();
3049b1e38eSTed Kremenek   ProgramStateRef state = Pred->getState();
31632e3b7eSTed Kremenek   const LocationContext *LCtx = Pred->getLocationContext();
3210e25031STed Kremenek 
3310e25031STed Kremenek   // Bind the temporary object to the value of the expression. Then bind
3410e25031STed Kremenek   // the expression to the location of the object.
35c9318304SJordan Rose   SVal V = state->getSVal(tempExpr, LCtx);
3610e25031STed Kremenek 
37fcdda361SJordan Rose   // If the value is already a CXXTempObjectRegion, it is fine as it is.
38fcdda361SJordan Rose   // Otherwise, create a new CXXTempObjectRegion, and copy the value into it.
39fcdda361SJordan Rose   const MemRegion *MR = V.getAsRegion();
40fcdda361SJordan Rose   if (!MR || !isa<CXXTempObjectRegion>(MR)) {
4110e25031STed Kremenek     const MemRegion *R =
42632e3b7eSTed Kremenek       svalBuilder.getRegionManager().getCXXTempObjectRegion(ME, LCtx);
4310e25031STed Kremenek 
44c9318304SJordan Rose     SVal L = loc::MemRegionVal(R);
45c9318304SJordan Rose     state = state->bindLoc(L, V);
46c9318304SJordan Rose     V = L;
47c9318304SJordan Rose   }
48c9318304SJordan Rose 
49c9318304SJordan Rose   Bldr.generateNode(ME, Pred, state->BindExpr(ME, LCtx, V));
5010e25031STed Kremenek }
5110e25031STed Kremenek 
5288bb563cSJordan Rose void ExprEngine::performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
5388bb563cSJordan Rose                                     const CXXConstructorCall &Call) {
5488bb563cSJordan Rose   const CXXConstructExpr *CtorExpr = Call.getOriginExpr();
5588bb563cSJordan Rose   assert(CtorExpr->getConstructor()->isCopyOrMoveConstructor());
5688bb563cSJordan Rose   assert(CtorExpr->getConstructor()->isTrivial());
5788bb563cSJordan Rose 
5888bb563cSJordan Rose   SVal ThisVal = Call.getCXXThisVal();
5988bb563cSJordan Rose   const LocationContext *LCtx = Pred->getLocationContext();
6088bb563cSJordan Rose 
6188bb563cSJordan Rose   ExplodedNodeSet Dst;
6288bb563cSJordan Rose   Bldr.takeNodes(Pred);
6388bb563cSJordan Rose 
6488bb563cSJordan Rose   SVal V = Call.getArgSVal(0);
6588bb563cSJordan Rose 
6688bb563cSJordan Rose   // Make sure the value being copied is not unknown.
67*05785d16SDavid Blaikie   if (Optional<Loc> L = V.getAs<Loc>())
6888bb563cSJordan Rose     V = Pred->getState()->getSVal(*L);
6988bb563cSJordan Rose 
7088bb563cSJordan Rose   evalBind(Dst, CtorExpr, Pred, ThisVal, V, true);
7188bb563cSJordan Rose 
7288bb563cSJordan Rose   PostStmt PS(CtorExpr, LCtx);
7388bb563cSJordan Rose   for (ExplodedNodeSet::iterator I = Dst.begin(), E = Dst.end();
7488bb563cSJordan Rose        I != E; ++I) {
7588bb563cSJordan Rose     ProgramStateRef State = (*I)->getState();
7688bb563cSJordan Rose     State = bindReturnValue(Call, LCtx, State);
7788bb563cSJordan Rose     Bldr.generateNode(PS, State, *I);
7888bb563cSJordan Rose   }
7988bb563cSJordan Rose }
8088bb563cSJordan Rose 
81f3c12ac3SJordan Rose void ExprEngine::VisitCXXConstructExpr(const CXXConstructExpr *CE,
8210e25031STed Kremenek                                        ExplodedNode *Pred,
8310e25031STed Kremenek                                        ExplodedNodeSet &destNodes) {
84b970505dSJordan Rose   const LocationContext *LCtx = Pred->getLocationContext();
8505375eb4SJordan Rose   ProgramStateRef State = Pred->getState();
8605375eb4SJordan Rose 
87b970505dSJordan Rose   const MemRegion *Target = 0;
8888bb563cSJordan Rose   bool IsArray = false;
89b970505dSJordan Rose 
90b970505dSJordan Rose   switch (CE->getConstructionKind()) {
91b970505dSJordan Rose   case CXXConstructExpr::CK_Complete: {
9205375eb4SJordan Rose     // See if we're constructing an existing region by looking at the next
9305375eb4SJordan Rose     // element in the CFG.
94d94854a4STed Kremenek     const CFGBlock *B = currBldrCtx->getBlock();
95d94854a4STed Kremenek     if (currStmtIdx + 1 < B->size()) {
96d94854a4STed Kremenek       CFGElement Next = (*B)[currStmtIdx+1];
9705375eb4SJordan Rose 
9805375eb4SJordan Rose       // Is this a constructor for a local variable?
9920edae87SJordan Rose       if (const CFGStmt *StmtElem = dyn_cast<CFGStmt>(&Next)) {
10020edae87SJordan Rose         if (const DeclStmt *DS = dyn_cast<DeclStmt>(StmtElem->getStmt())) {
10120edae87SJordan Rose           if (const VarDecl *Var = dyn_cast<VarDecl>(DS->getSingleDecl())) {
10220edae87SJordan Rose             if (Var->getInit()->IgnoreImplicit() == CE) {
10320edae87SJordan Rose               QualType Ty = Var->getType();
10420edae87SJordan Rose               if (const ArrayType *AT = getContext().getAsArrayType(Ty)) {
10520edae87SJordan Rose                 // FIXME: Handle arrays, which run the same constructor for
10620edae87SJordan Rose                 // every element. This workaround will just run the first
10720edae87SJordan Rose                 // constructor (which should still invalidate the entire array).
10820edae87SJordan Rose                 SVal Base = State->getLValue(Var, LCtx);
10920edae87SJordan Rose                 Target = State->getLValue(AT->getElementType(),
11020edae87SJordan Rose                                           getSValBuilder().makeZeroArrayIndex(),
11120edae87SJordan Rose                                           Base).getAsRegion();
11288bb563cSJordan Rose                 IsArray = true;
11320edae87SJordan Rose               } else {
11405375eb4SJordan Rose                 Target = State->getLValue(Var, LCtx).getAsRegion();
11520edae87SJordan Rose               }
11620edae87SJordan Rose             }
11720edae87SJordan Rose           }
11820edae87SJordan Rose         }
11920edae87SJordan Rose       }
12005375eb4SJordan Rose 
12154529a34SJordan Rose       // Is this a constructor for a member?
12254529a34SJordan Rose       if (const CFGInitializer *InitElem = dyn_cast<CFGInitializer>(&Next)) {
12354529a34SJordan Rose         const CXXCtorInitializer *Init = InitElem->getInitializer();
12454529a34SJordan Rose         assert(Init->isAnyMemberInitializer());
12554529a34SJordan Rose 
12654529a34SJordan Rose         const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl());
12754529a34SJordan Rose         Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor,
12854529a34SJordan Rose                                                   LCtx->getCurrentStackFrame());
12954529a34SJordan Rose         SVal ThisVal = State->getSVal(ThisPtr);
13054529a34SJordan Rose 
13154529a34SJordan Rose         if (Init->isIndirectMemberInitializer()) {
13254529a34SJordan Rose           SVal Field = State->getLValue(Init->getIndirectMember(), ThisVal);
13320edae87SJordan Rose           Target = Field.getAsRegion();
13454529a34SJordan Rose         } else {
13554529a34SJordan Rose           SVal Field = State->getLValue(Init->getMember(), ThisVal);
13620edae87SJordan Rose           Target = Field.getAsRegion();
13754529a34SJordan Rose         }
13854529a34SJordan Rose       }
13954529a34SJordan Rose 
14005375eb4SJordan Rose       // FIXME: This will eventually need to handle new-expressions as well.
14105375eb4SJordan Rose     }
14205375eb4SJordan Rose 
143c9318304SJordan Rose     // If we couldn't find an existing region to construct into, assume we're
144c9318304SJordan Rose     // constructing a temporary.
145c9318304SJordan Rose     if (!Target) {
146c9318304SJordan Rose       MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
147c9318304SJordan Rose       Target = MRMgr.getCXXTempObjectRegion(CE, LCtx);
148c9318304SJordan Rose     }
14905375eb4SJordan Rose 
150b970505dSJordan Rose     break;
151b970505dSJordan Rose   }
152b970505dSJordan Rose   case CXXConstructExpr::CK_NonVirtualBase:
153b970505dSJordan Rose   case CXXConstructExpr::CK_VirtualBase:
154b970505dSJordan Rose   case CXXConstructExpr::CK_Delegating: {
155b970505dSJordan Rose     const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl());
156b970505dSJordan Rose     Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor,
157b970505dSJordan Rose                                               LCtx->getCurrentStackFrame());
15805375eb4SJordan Rose     SVal ThisVal = State->getSVal(ThisPtr);
159b970505dSJordan Rose 
160b970505dSJordan Rose     if (CE->getConstructionKind() == CXXConstructExpr::CK_Delegating) {
161b970505dSJordan Rose       Target = ThisVal.getAsRegion();
162b970505dSJordan Rose     } else {
163b970505dSJordan Rose       // Cast to the base type.
164b970505dSJordan Rose       QualType BaseTy = CE->getType();
165b970505dSJordan Rose       SVal BaseVal = getStoreManager().evalDerivedToBase(ThisVal, BaseTy);
16620edae87SJordan Rose       Target = BaseVal.getAsRegion();
167b970505dSJordan Rose     }
168b970505dSJordan Rose     break;
169b970505dSJordan Rose   }
170b970505dSJordan Rose   }
171b970505dSJordan Rose 
172fcd016e5SJordan Rose   CallEventManager &CEMgr = getStateManager().getCallEventManager();
173fcd016e5SJordan Rose   CallEventRef<CXXConstructorCall> Call =
174fcd016e5SJordan Rose     CEMgr.getCXXConstructorCall(CE, Target, State, LCtx);
17510e25031STed Kremenek 
176f3c12ac3SJordan Rose   ExplodedNodeSet DstPreVisit;
177f3c12ac3SJordan Rose   getCheckerManager().runCheckersForPreStmt(DstPreVisit, Pred, CE, *this);
178afe7c2c2SJordan Rose   ExplodedNodeSet DstPreCall;
179afe7c2c2SJordan Rose   getCheckerManager().runCheckersForPreCall(DstPreCall, DstPreVisit,
180fcd016e5SJordan Rose                                             *Call, *this);
18110e25031STed Kremenek 
18288bb563cSJordan Rose   ExplodedNodeSet DstEvaluated;
18388bb563cSJordan Rose   StmtNodeBuilder Bldr(DstPreCall, DstEvaluated, *currBldrCtx);
18488bb563cSJordan Rose 
18588bb563cSJordan Rose   if (CE->getConstructor()->isTrivial() &&
18688bb563cSJordan Rose       CE->getConstructor()->isCopyOrMoveConstructor() &&
18788bb563cSJordan Rose       !IsArray) {
18888bb563cSJordan Rose     // FIXME: Handle other kinds of trivial constructors as well.
18988bb563cSJordan Rose     for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
19088bb563cSJordan Rose          I != E; ++I)
19188bb563cSJordan Rose       performTrivialCopy(Bldr, *I, *Call);
19288bb563cSJordan Rose 
19388bb563cSJordan Rose   } else {
194afe7c2c2SJordan Rose     for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
195f3c12ac3SJordan Rose          I != E; ++I)
196fcd016e5SJordan Rose       defaultEvalCall(Bldr, *I, *Call);
19788bb563cSJordan Rose   }
19810e25031STed Kremenek 
199afe7c2c2SJordan Rose   ExplodedNodeSet DstPostCall;
20088bb563cSJordan Rose   getCheckerManager().runCheckersForPostCall(DstPostCall, DstEvaluated,
201fcd016e5SJordan Rose                                              *Call, *this);
202afe7c2c2SJordan Rose   getCheckerManager().runCheckersForPostStmt(destNodes, DstPostCall, CE, *this);
20310e25031STed Kremenek }
20410e25031STed Kremenek 
205b970505dSJordan Rose void ExprEngine::VisitCXXDestructor(QualType ObjectType,
20610e25031STed Kremenek                                     const MemRegion *Dest,
20710e25031STed Kremenek                                     const Stmt *S,
2082bc9674bSJordan Rose                                     bool IsBaseDtor,
20910e25031STed Kremenek                                     ExplodedNode *Pred,
21010e25031STed Kremenek                                     ExplodedNodeSet &Dst) {
211fcd016e5SJordan Rose   const LocationContext *LCtx = Pred->getLocationContext();
212fcd016e5SJordan Rose   ProgramStateRef State = Pred->getState();
213fcd016e5SJordan Rose 
21420edae87SJordan Rose   // FIXME: We need to run the same destructor on every element of the array.
21520edae87SJordan Rose   // This workaround will just run the first destructor (which will still
21620edae87SJordan Rose   // invalidate the entire array).
2174cfdbff3SJordan Rose   // This is a loop because of multidimensional arrays.
2184cfdbff3SJordan Rose   while (const ArrayType *AT = getContext().getAsArrayType(ObjectType)) {
21920edae87SJordan Rose     ObjectType = AT->getElementType();
220fcd016e5SJordan Rose     Dest = State->getLValue(ObjectType, getSValBuilder().makeZeroArrayIndex(),
22120edae87SJordan Rose                             loc::MemRegionVal(Dest)).getAsRegion();
22220edae87SJordan Rose   }
22320edae87SJordan Rose 
224b970505dSJordan Rose   const CXXRecordDecl *RecordDecl = ObjectType->getAsCXXRecordDecl();
225b970505dSJordan Rose   assert(RecordDecl && "Only CXXRecordDecls should have destructors");
226b970505dSJordan Rose   const CXXDestructorDecl *DtorDecl = RecordDecl->getDestructor();
227b970505dSJordan Rose 
228fcd016e5SJordan Rose   CallEventManager &CEMgr = getStateManager().getCallEventManager();
229fcd016e5SJordan Rose   CallEventRef<CXXDestructorCall> Call =
2302bc9674bSJordan Rose     CEMgr.getCXXDestructorCall(DtorDecl, S, Dest, IsBaseDtor, State, LCtx);
231142adc49STed Kremenek 
23217a8757aSJordan Rose   PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
23317a8757aSJordan Rose                                 Call->getSourceRange().getBegin(),
23417a8757aSJordan Rose                                 "Error evaluating destructor");
23517a8757aSJordan Rose 
2364ee71b8aSJordan Rose   ExplodedNodeSet DstPreCall;
2374ee71b8aSJordan Rose   getCheckerManager().runCheckersForPreCall(DstPreCall, Pred,
238fcd016e5SJordan Rose                                             *Call, *this);
23910e25031STed Kremenek 
2404ee71b8aSJordan Rose   ExplodedNodeSet DstInvalidated;
241d94854a4STed Kremenek   StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
2424ee71b8aSJordan Rose   for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
2434ee71b8aSJordan Rose        I != E; ++I)
244fcd016e5SJordan Rose     defaultEvalCall(Bldr, *I, *Call);
2454ee71b8aSJordan Rose 
2464ee71b8aSJordan Rose   ExplodedNodeSet DstPostCall;
2474ee71b8aSJordan Rose   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
248fcd016e5SJordan Rose                                              *Call, *this);
24910e25031STed Kremenek }
25010e25031STed Kremenek 
25110e25031STed Kremenek void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
25210e25031STed Kremenek                                    ExplodedNodeSet &Dst) {
253a4ee064cSJordan Rose   // FIXME: Much of this should eventually migrate to CXXAllocatorCall.
254a4ee064cSJordan Rose   // Also, we need to decide how allocators actually work -- they're not
255a4ee064cSJordan Rose   // really part of the CXXNewExpr because they happen BEFORE the
256a4ee064cSJordan Rose   // CXXConstructExpr subexpression. See PR12014 for some discussion.
257d94854a4STed Kremenek   StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
25810e25031STed Kremenek 
259d94854a4STed Kremenek   unsigned blockCount = currBldrCtx->blockCount();
260d519cae8STed Kremenek   const LocationContext *LCtx = Pred->getLocationContext();
261d227833cSTed Kremenek   DefinedOrUnknownSVal symVal = svalBuilder.conjureSymbolVal(0, CNE, LCtx,
262d227833cSTed Kremenek                                                              CNE->getType(),
263d227833cSTed Kremenek                                                              blockCount);
26444320367SJordan Rose   ProgramStateRef State = Pred->getState();
26510e25031STed Kremenek 
266fcd016e5SJordan Rose   CallEventManager &CEMgr = getStateManager().getCallEventManager();
267fcd016e5SJordan Rose   CallEventRef<CXXAllocatorCall> Call =
268fcd016e5SJordan Rose     CEMgr.getCXXAllocatorCall(CNE, State, LCtx);
269fcd016e5SJordan Rose 
270a4ee064cSJordan Rose   // Invalidate placement args.
271fcd016e5SJordan Rose   // FIXME: Once we figure out how we want allocators to work,
272fcd016e5SJordan Rose   // we should be using the usual pre-/(default-)eval-/post-call checks here.
273fcd016e5SJordan Rose   State = Call->invalidateRegions(blockCount);
274a4ee064cSJordan Rose 
2753957fd58SJordan Rose   // If we're compiling with exceptions enabled, and this allocation function
2763957fd58SJordan Rose   // is not declared as non-throwing, failures /must/ be signalled by
2773957fd58SJordan Rose   // exceptions, and thus the return value will never be NULL.
2783957fd58SJordan Rose   // C++11 [basic.stc.dynamic.allocation]p3.
2793957fd58SJordan Rose   FunctionDecl *FD = CNE->getOperatorNew();
2803957fd58SJordan Rose   if (FD && getContext().getLangOpts().CXXExceptions) {
2813957fd58SJordan Rose     QualType Ty = FD->getType();
2823957fd58SJordan Rose     if (const FunctionProtoType *ProtoType = Ty->getAs<FunctionProtoType>())
2833957fd58SJordan Rose       if (!ProtoType->isNothrow(getContext()))
2843957fd58SJordan Rose         State = State->assume(symVal, true);
2853957fd58SJordan Rose   }
2863957fd58SJordan Rose 
28710e25031STed Kremenek   if (CNE->isArray()) {
28810e25031STed Kremenek     // FIXME: allocating an array requires simulating the constructors.
28910e25031STed Kremenek     // For now, just return a symbolicated region.
2902fdacbc5SDavid Blaikie     const MemRegion *NewReg = symVal.castAs<loc::MemRegionVal>().getRegion();
291a4ee064cSJordan Rose     QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType();
292a4ee064cSJordan Rose     const ElementRegion *EleReg =
293a4ee064cSJordan Rose       getStoreManager().GetElementZeroRegion(NewReg, ObjTy);
29444320367SJordan Rose     State = State->BindExpr(CNE, Pred->getLocationContext(),
295632e3b7eSTed Kremenek                             loc::MemRegionVal(EleReg));
29644320367SJordan Rose     Bldr.generateNode(CNE, Pred, State);
29710e25031STed Kremenek     return;
29810e25031STed Kremenek   }
29910e25031STed Kremenek 
300a4ee064cSJordan Rose   // FIXME: Once we have proper support for CXXConstructExprs inside
301a4ee064cSJordan Rose   // CXXNewExpr, we need to make sure that the constructed object is not
302a4ee064cSJordan Rose   // immediately invalidated here. (The placement call should happen before
303a4ee064cSJordan Rose   // the constructor call anyway.)
30444320367SJordan Rose   if (FD && FD->isReservedGlobalPlacementOperator()) {
30544320367SJordan Rose     // Non-array placement new should always return the placement location.
30644320367SJordan Rose     SVal PlacementLoc = State->getSVal(CNE->getPlacementArg(0), LCtx);
307aaf83184SJordan Rose     SVal Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(),
308aaf83184SJordan Rose                                        CNE->getPlacementArg(0)->getType());
309aaf83184SJordan Rose     State = State->BindExpr(CNE, LCtx, Result);
31044320367SJordan Rose   } else {
311a4ee064cSJordan Rose     State = State->BindExpr(CNE, LCtx, symVal);
31244320367SJordan Rose   }
31344320367SJordan Rose 
3145089f3b3SJordan Rose   // If the type is not a record, we won't have a CXXConstructExpr as an
3155089f3b3SJordan Rose   // initializer. Copy the value over.
3165089f3b3SJordan Rose   if (const Expr *Init = CNE->getInitializer()) {
3175089f3b3SJordan Rose     if (!isa<CXXConstructExpr>(Init)) {
3185089f3b3SJordan Rose       QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType();
3195089f3b3SJordan Rose       (void)ObjTy;
3205089f3b3SJordan Rose       assert(!ObjTy->isRecordType());
3215089f3b3SJordan Rose       SVal Location = State->getSVal(CNE, LCtx);
322*05785d16SDavid Blaikie       if (Optional<Loc> LV = Location.getAs<Loc>())
3232fdacbc5SDavid Blaikie         State = State->bindLoc(*LV, State->getSVal(Init, LCtx));
3245089f3b3SJordan Rose     }
3255089f3b3SJordan Rose   }
3265089f3b3SJordan Rose 
32744320367SJordan Rose   Bldr.generateNode(CNE, Pred, State);
32810e25031STed Kremenek }
32910e25031STed Kremenek 
33010e25031STed Kremenek void ExprEngine::VisitCXXDeleteExpr(const CXXDeleteExpr *CDE,
33110e25031STed Kremenek                                     ExplodedNode *Pred, ExplodedNodeSet &Dst) {
332d94854a4STed Kremenek   StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
33364aea652SErik Verbruggen   ProgramStateRef state = Pred->getState();
33464aea652SErik Verbruggen   Bldr.generateNode(CDE, Pred, state);
33510e25031STed Kremenek }
33610e25031STed Kremenek 
3378fdb59f9STed Kremenek void ExprEngine::VisitCXXCatchStmt(const CXXCatchStmt *CS,
3388fdb59f9STed Kremenek                                    ExplodedNode *Pred,
3398fdb59f9STed Kremenek                                    ExplodedNodeSet &Dst) {
3408fdb59f9STed Kremenek   const VarDecl *VD = CS->getExceptionDecl();
341b1279b5cSTed Kremenek   if (!VD) {
342b1279b5cSTed Kremenek     Dst.Add(Pred);
343b1279b5cSTed Kremenek     return;
344b1279b5cSTed Kremenek   }
345b1279b5cSTed Kremenek 
3468fdb59f9STed Kremenek   const LocationContext *LCtx = Pred->getLocationContext();
347d227833cSTed Kremenek   SVal V = svalBuilder.conjureSymbolVal(CS, LCtx, VD->getType(),
348d94854a4STed Kremenek                                         currBldrCtx->blockCount());
3498fdb59f9STed Kremenek   ProgramStateRef state = Pred->getState();
3508fdb59f9STed Kremenek   state = state->bindLoc(state->getLValue(VD, LCtx), V);
3518fdb59f9STed Kremenek 
352d94854a4STed Kremenek   StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
3538fdb59f9STed Kremenek   Bldr.generateNode(CS, Pred, state);
3548fdb59f9STed Kremenek }
3558fdb59f9STed Kremenek 
35610e25031STed Kremenek void ExprEngine::VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred,
35710e25031STed Kremenek                                     ExplodedNodeSet &Dst) {
358d94854a4STed Kremenek   StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
359e594034fSAnna Zaks 
36010e25031STed Kremenek   // Get the this object region from StoreManager.
361632e3b7eSTed Kremenek   const LocationContext *LCtx = Pred->getLocationContext();
36210e25031STed Kremenek   const MemRegion *R =
36310e25031STed Kremenek     svalBuilder.getRegionManager().getCXXThisRegion(
36410e25031STed Kremenek                                   getContext().getCanonicalType(TE->getType()),
365632e3b7eSTed Kremenek                                                     LCtx);
36610e25031STed Kremenek 
36749b1e38eSTed Kremenek   ProgramStateRef state = Pred->getState();
36810e25031STed Kremenek   SVal V = state->getSVal(loc::MemRegionVal(R));
369632e3b7eSTed Kremenek   Bldr.generateNode(TE, Pred, state->BindExpr(TE, LCtx, V));
37010e25031STed Kremenek }
371