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 
33c9318304SJordan Rose   SVal V = state->getSVal(tempExpr, LCtx);
3410e25031STed Kremenek 
35fcdda361SJordan Rose   // If the value is already a CXXTempObjectRegion, it is fine as it is.
36fcdda361SJordan Rose   // Otherwise, create a new CXXTempObjectRegion, and copy the value into it.
37fcdda361SJordan Rose   const MemRegion *MR = V.getAsRegion();
38*5772f82dSJordan Rose   if (MR && isa<CXXTempObjectRegion>(MR))
39*5772f82dSJordan Rose     state = state->BindExpr(ME, LCtx, V);
40*5772f82dSJordan Rose   else
41*5772f82dSJordan Rose     state = createTemporaryRegionIfNeeded(state, LCtx, tempExpr, ME);
4210e25031STed Kremenek 
43*5772f82dSJordan Rose   Bldr.generateNode(ME, Pred, state);
4410e25031STed Kremenek }
4510e25031STed Kremenek 
4688bb563cSJordan Rose void ExprEngine::performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
4788bb563cSJordan Rose                                     const CXXConstructorCall &Call) {
4888bb563cSJordan Rose   const CXXConstructExpr *CtorExpr = Call.getOriginExpr();
4988bb563cSJordan Rose   assert(CtorExpr->getConstructor()->isCopyOrMoveConstructor());
5088bb563cSJordan Rose   assert(CtorExpr->getConstructor()->isTrivial());
5188bb563cSJordan Rose 
5288bb563cSJordan Rose   SVal ThisVal = Call.getCXXThisVal();
5388bb563cSJordan Rose   const LocationContext *LCtx = Pred->getLocationContext();
5488bb563cSJordan Rose 
5588bb563cSJordan Rose   ExplodedNodeSet Dst;
5688bb563cSJordan Rose   Bldr.takeNodes(Pred);
5788bb563cSJordan Rose 
5888bb563cSJordan Rose   SVal V = Call.getArgSVal(0);
5988bb563cSJordan Rose 
6088bb563cSJordan Rose   // Make sure the value being copied is not unknown.
6105785d16SDavid Blaikie   if (Optional<Loc> L = V.getAs<Loc>())
6288bb563cSJordan Rose     V = Pred->getState()->getSVal(*L);
6388bb563cSJordan Rose 
6488bb563cSJordan Rose   evalBind(Dst, CtorExpr, Pred, ThisVal, V, true);
6588bb563cSJordan Rose 
6688bb563cSJordan Rose   PostStmt PS(CtorExpr, LCtx);
6788bb563cSJordan Rose   for (ExplodedNodeSet::iterator I = Dst.begin(), E = Dst.end();
6888bb563cSJordan Rose        I != E; ++I) {
6988bb563cSJordan Rose     ProgramStateRef State = (*I)->getState();
7088bb563cSJordan Rose     State = bindReturnValue(Call, LCtx, State);
7188bb563cSJordan Rose     Bldr.generateNode(PS, State, *I);
7288bb563cSJordan Rose   }
7388bb563cSJordan Rose }
7488bb563cSJordan Rose 
75f3c12ac3SJordan Rose void ExprEngine::VisitCXXConstructExpr(const CXXConstructExpr *CE,
7610e25031STed Kremenek                                        ExplodedNode *Pred,
7710e25031STed Kremenek                                        ExplodedNodeSet &destNodes) {
78b970505dSJordan Rose   const LocationContext *LCtx = Pred->getLocationContext();
7905375eb4SJordan Rose   ProgramStateRef State = Pred->getState();
8005375eb4SJordan Rose 
81b970505dSJordan Rose   const MemRegion *Target = 0;
8288bb563cSJordan Rose   bool IsArray = false;
83b970505dSJordan Rose 
84b970505dSJordan Rose   switch (CE->getConstructionKind()) {
85b970505dSJordan Rose   case CXXConstructExpr::CK_Complete: {
8605375eb4SJordan Rose     // See if we're constructing an existing region by looking at the next
8705375eb4SJordan Rose     // element in the CFG.
88d94854a4STed Kremenek     const CFGBlock *B = currBldrCtx->getBlock();
89d94854a4STed Kremenek     if (currStmtIdx + 1 < B->size()) {
90d94854a4STed Kremenek       CFGElement Next = (*B)[currStmtIdx+1];
9105375eb4SJordan Rose 
9205375eb4SJordan Rose       // Is this a constructor for a local variable?
932a01f5d4SDavid Blaikie       if (CFGStmt StmtElem = Next.getAs<CFGStmt>()) {
942a01f5d4SDavid Blaikie         if (const DeclStmt *DS = dyn_cast<DeclStmt>(StmtElem.getStmt())) {
9520edae87SJordan Rose           if (const VarDecl *Var = dyn_cast<VarDecl>(DS->getSingleDecl())) {
9620edae87SJordan Rose             if (Var->getInit()->IgnoreImplicit() == CE) {
9720edae87SJordan Rose               QualType Ty = Var->getType();
9820edae87SJordan Rose               if (const ArrayType *AT = getContext().getAsArrayType(Ty)) {
9920edae87SJordan Rose                 // FIXME: Handle arrays, which run the same constructor for
10020edae87SJordan Rose                 // every element. This workaround will just run the first
10120edae87SJordan Rose                 // constructor (which should still invalidate the entire array).
10220edae87SJordan Rose                 SVal Base = State->getLValue(Var, LCtx);
10320edae87SJordan Rose                 Target = State->getLValue(AT->getElementType(),
10420edae87SJordan Rose                                           getSValBuilder().makeZeroArrayIndex(),
10520edae87SJordan Rose                                           Base).getAsRegion();
10688bb563cSJordan Rose                 IsArray = true;
10720edae87SJordan Rose               } else {
10805375eb4SJordan Rose                 Target = State->getLValue(Var, LCtx).getAsRegion();
10920edae87SJordan Rose               }
11020edae87SJordan Rose             }
11120edae87SJordan Rose           }
11220edae87SJordan Rose         }
11320edae87SJordan Rose       }
11405375eb4SJordan Rose 
11554529a34SJordan Rose       // Is this a constructor for a member?
1162a01f5d4SDavid Blaikie       if (CFGInitializer InitElem = Next.getAs<CFGInitializer>()) {
1172a01f5d4SDavid Blaikie         const CXXCtorInitializer *Init = InitElem.getInitializer();
11854529a34SJordan Rose         assert(Init->isAnyMemberInitializer());
11954529a34SJordan Rose 
12054529a34SJordan Rose         const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl());
12154529a34SJordan Rose         Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor,
12254529a34SJordan Rose                                                   LCtx->getCurrentStackFrame());
12354529a34SJordan Rose         SVal ThisVal = State->getSVal(ThisPtr);
12454529a34SJordan Rose 
12554529a34SJordan Rose         if (Init->isIndirectMemberInitializer()) {
12654529a34SJordan Rose           SVal Field = State->getLValue(Init->getIndirectMember(), ThisVal);
12720edae87SJordan Rose           Target = Field.getAsRegion();
12854529a34SJordan Rose         } else {
12954529a34SJordan Rose           SVal Field = State->getLValue(Init->getMember(), ThisVal);
13020edae87SJordan Rose           Target = Field.getAsRegion();
13154529a34SJordan Rose         }
13254529a34SJordan Rose       }
13354529a34SJordan Rose 
13405375eb4SJordan Rose       // FIXME: This will eventually need to handle new-expressions as well.
13505375eb4SJordan Rose     }
13605375eb4SJordan Rose 
137c9318304SJordan Rose     // If we couldn't find an existing region to construct into, assume we're
138c9318304SJordan Rose     // constructing a temporary.
139c9318304SJordan Rose     if (!Target) {
140c9318304SJordan Rose       MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
141c9318304SJordan Rose       Target = MRMgr.getCXXTempObjectRegion(CE, LCtx);
142c9318304SJordan Rose     }
14305375eb4SJordan Rose 
144b970505dSJordan Rose     break;
145b970505dSJordan Rose   }
146b970505dSJordan Rose   case CXXConstructExpr::CK_NonVirtualBase:
147b970505dSJordan Rose   case CXXConstructExpr::CK_VirtualBase:
148b970505dSJordan Rose   case CXXConstructExpr::CK_Delegating: {
149b970505dSJordan Rose     const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl());
150b970505dSJordan Rose     Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor,
151b970505dSJordan Rose                                               LCtx->getCurrentStackFrame());
15205375eb4SJordan Rose     SVal ThisVal = State->getSVal(ThisPtr);
153b970505dSJordan Rose 
154b970505dSJordan Rose     if (CE->getConstructionKind() == CXXConstructExpr::CK_Delegating) {
155b970505dSJordan Rose       Target = ThisVal.getAsRegion();
156b970505dSJordan Rose     } else {
157b970505dSJordan Rose       // Cast to the base type.
158599f85abSJordan Rose       bool IsVirtual =
159599f85abSJordan Rose         (CE->getConstructionKind() == CXXConstructExpr::CK_VirtualBase);
160599f85abSJordan Rose       SVal BaseVal = getStoreManager().evalDerivedToBase(ThisVal, CE->getType(),
161599f85abSJordan Rose                                                          IsVirtual);
16220edae87SJordan Rose       Target = BaseVal.getAsRegion();
163b970505dSJordan Rose     }
164b970505dSJordan Rose     break;
165b970505dSJordan Rose   }
166b970505dSJordan Rose   }
167b970505dSJordan Rose 
168fcd016e5SJordan Rose   CallEventManager &CEMgr = getStateManager().getCallEventManager();
169fcd016e5SJordan Rose   CallEventRef<CXXConstructorCall> Call =
170fcd016e5SJordan Rose     CEMgr.getCXXConstructorCall(CE, Target, State, LCtx);
17110e25031STed Kremenek 
172f3c12ac3SJordan Rose   ExplodedNodeSet DstPreVisit;
173f3c12ac3SJordan Rose   getCheckerManager().runCheckersForPreStmt(DstPreVisit, Pred, CE, *this);
174afe7c2c2SJordan Rose   ExplodedNodeSet DstPreCall;
175afe7c2c2SJordan Rose   getCheckerManager().runCheckersForPreCall(DstPreCall, DstPreVisit,
176fcd016e5SJordan Rose                                             *Call, *this);
17710e25031STed Kremenek 
17888bb563cSJordan Rose   ExplodedNodeSet DstEvaluated;
17988bb563cSJordan Rose   StmtNodeBuilder Bldr(DstPreCall, DstEvaluated, *currBldrCtx);
18088bb563cSJordan Rose 
18188bb563cSJordan Rose   if (CE->getConstructor()->isTrivial() &&
18288bb563cSJordan Rose       CE->getConstructor()->isCopyOrMoveConstructor() &&
18388bb563cSJordan Rose       !IsArray) {
18488bb563cSJordan Rose     // FIXME: Handle other kinds of trivial constructors as well.
18588bb563cSJordan Rose     for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
18688bb563cSJordan Rose          I != E; ++I)
18788bb563cSJordan Rose       performTrivialCopy(Bldr, *I, *Call);
18888bb563cSJordan Rose 
18988bb563cSJordan Rose   } else {
190afe7c2c2SJordan Rose     for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
191f3c12ac3SJordan Rose          I != E; ++I)
192fcd016e5SJordan Rose       defaultEvalCall(Bldr, *I, *Call);
19388bb563cSJordan Rose   }
19410e25031STed Kremenek 
195afe7c2c2SJordan Rose   ExplodedNodeSet DstPostCall;
19688bb563cSJordan Rose   getCheckerManager().runCheckersForPostCall(DstPostCall, DstEvaluated,
197fcd016e5SJordan Rose                                              *Call, *this);
198afe7c2c2SJordan Rose   getCheckerManager().runCheckersForPostStmt(destNodes, DstPostCall, CE, *this);
19910e25031STed Kremenek }
20010e25031STed Kremenek 
201b970505dSJordan Rose void ExprEngine::VisitCXXDestructor(QualType ObjectType,
20210e25031STed Kremenek                                     const MemRegion *Dest,
20310e25031STed Kremenek                                     const Stmt *S,
2042bc9674bSJordan Rose                                     bool IsBaseDtor,
20510e25031STed Kremenek                                     ExplodedNode *Pred,
20610e25031STed Kremenek                                     ExplodedNodeSet &Dst) {
207fcd016e5SJordan Rose   const LocationContext *LCtx = Pred->getLocationContext();
208fcd016e5SJordan Rose   ProgramStateRef State = Pred->getState();
209fcd016e5SJordan Rose 
21020edae87SJordan Rose   // FIXME: We need to run the same destructor on every element of the array.
21120edae87SJordan Rose   // This workaround will just run the first destructor (which will still
21220edae87SJordan Rose   // invalidate the entire array).
2134cfdbff3SJordan Rose   // This is a loop because of multidimensional arrays.
2144cfdbff3SJordan Rose   while (const ArrayType *AT = getContext().getAsArrayType(ObjectType)) {
21520edae87SJordan Rose     ObjectType = AT->getElementType();
216fcd016e5SJordan Rose     Dest = State->getLValue(ObjectType, getSValBuilder().makeZeroArrayIndex(),
21720edae87SJordan Rose                             loc::MemRegionVal(Dest)).getAsRegion();
21820edae87SJordan Rose   }
21920edae87SJordan Rose 
220b970505dSJordan Rose   const CXXRecordDecl *RecordDecl = ObjectType->getAsCXXRecordDecl();
221b970505dSJordan Rose   assert(RecordDecl && "Only CXXRecordDecls should have destructors");
222b970505dSJordan Rose   const CXXDestructorDecl *DtorDecl = RecordDecl->getDestructor();
223b970505dSJordan Rose 
224fcd016e5SJordan Rose   CallEventManager &CEMgr = getStateManager().getCallEventManager();
225fcd016e5SJordan Rose   CallEventRef<CXXDestructorCall> Call =
2262bc9674bSJordan Rose     CEMgr.getCXXDestructorCall(DtorDecl, S, Dest, IsBaseDtor, State, LCtx);
227142adc49STed Kremenek 
22817a8757aSJordan Rose   PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
22917a8757aSJordan Rose                                 Call->getSourceRange().getBegin(),
23017a8757aSJordan Rose                                 "Error evaluating destructor");
23117a8757aSJordan Rose 
2324ee71b8aSJordan Rose   ExplodedNodeSet DstPreCall;
2334ee71b8aSJordan Rose   getCheckerManager().runCheckersForPreCall(DstPreCall, Pred,
234fcd016e5SJordan Rose                                             *Call, *this);
23510e25031STed Kremenek 
2364ee71b8aSJordan Rose   ExplodedNodeSet DstInvalidated;
237d94854a4STed Kremenek   StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
2384ee71b8aSJordan Rose   for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
2394ee71b8aSJordan Rose        I != E; ++I)
240fcd016e5SJordan Rose     defaultEvalCall(Bldr, *I, *Call);
2414ee71b8aSJordan Rose 
2424ee71b8aSJordan Rose   ExplodedNodeSet DstPostCall;
2434ee71b8aSJordan Rose   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
244fcd016e5SJordan Rose                                              *Call, *this);
24510e25031STed Kremenek }
24610e25031STed Kremenek 
24710e25031STed Kremenek void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
24810e25031STed Kremenek                                    ExplodedNodeSet &Dst) {
249a4ee064cSJordan Rose   // FIXME: Much of this should eventually migrate to CXXAllocatorCall.
250a4ee064cSJordan Rose   // Also, we need to decide how allocators actually work -- they're not
251a4ee064cSJordan Rose   // really part of the CXXNewExpr because they happen BEFORE the
252a4ee064cSJordan Rose   // CXXConstructExpr subexpression. See PR12014 for some discussion.
253d94854a4STed Kremenek   StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
25410e25031STed Kremenek 
255d94854a4STed Kremenek   unsigned blockCount = currBldrCtx->blockCount();
256d519cae8STed Kremenek   const LocationContext *LCtx = Pred->getLocationContext();
257d227833cSTed Kremenek   DefinedOrUnknownSVal symVal = svalBuilder.conjureSymbolVal(0, CNE, LCtx,
258d227833cSTed Kremenek                                                              CNE->getType(),
259d227833cSTed Kremenek                                                              blockCount);
26044320367SJordan Rose   ProgramStateRef State = Pred->getState();
26110e25031STed Kremenek 
262fcd016e5SJordan Rose   CallEventManager &CEMgr = getStateManager().getCallEventManager();
263fcd016e5SJordan Rose   CallEventRef<CXXAllocatorCall> Call =
264fcd016e5SJordan Rose     CEMgr.getCXXAllocatorCall(CNE, State, LCtx);
265fcd016e5SJordan Rose 
266a4ee064cSJordan Rose   // Invalidate placement args.
267fcd016e5SJordan Rose   // FIXME: Once we figure out how we want allocators to work,
268fcd016e5SJordan Rose   // we should be using the usual pre-/(default-)eval-/post-call checks here.
269fcd016e5SJordan Rose   State = Call->invalidateRegions(blockCount);
270a4ee064cSJordan Rose 
2713957fd58SJordan Rose   // If we're compiling with exceptions enabled, and this allocation function
2723957fd58SJordan Rose   // is not declared as non-throwing, failures /must/ be signalled by
2733957fd58SJordan Rose   // exceptions, and thus the return value will never be NULL.
2743957fd58SJordan Rose   // C++11 [basic.stc.dynamic.allocation]p3.
2753957fd58SJordan Rose   FunctionDecl *FD = CNE->getOperatorNew();
2763957fd58SJordan Rose   if (FD && getContext().getLangOpts().CXXExceptions) {
2773957fd58SJordan Rose     QualType Ty = FD->getType();
2783957fd58SJordan Rose     if (const FunctionProtoType *ProtoType = Ty->getAs<FunctionProtoType>())
2793957fd58SJordan Rose       if (!ProtoType->isNothrow(getContext()))
2803957fd58SJordan Rose         State = State->assume(symVal, true);
2813957fd58SJordan Rose   }
2823957fd58SJordan Rose 
28310e25031STed Kremenek   if (CNE->isArray()) {
28410e25031STed Kremenek     // FIXME: allocating an array requires simulating the constructors.
28510e25031STed Kremenek     // For now, just return a symbolicated region.
2862fdacbc5SDavid Blaikie     const MemRegion *NewReg = symVal.castAs<loc::MemRegionVal>().getRegion();
287a4ee064cSJordan Rose     QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType();
288a4ee064cSJordan Rose     const ElementRegion *EleReg =
289a4ee064cSJordan Rose       getStoreManager().GetElementZeroRegion(NewReg, ObjTy);
29044320367SJordan Rose     State = State->BindExpr(CNE, Pred->getLocationContext(),
291632e3b7eSTed Kremenek                             loc::MemRegionVal(EleReg));
29244320367SJordan Rose     Bldr.generateNode(CNE, Pred, State);
29310e25031STed Kremenek     return;
29410e25031STed Kremenek   }
29510e25031STed Kremenek 
296a4ee064cSJordan Rose   // FIXME: Once we have proper support for CXXConstructExprs inside
297a4ee064cSJordan Rose   // CXXNewExpr, we need to make sure that the constructed object is not
298a4ee064cSJordan Rose   // immediately invalidated here. (The placement call should happen before
299a4ee064cSJordan Rose   // the constructor call anyway.)
30044320367SJordan Rose   if (FD && FD->isReservedGlobalPlacementOperator()) {
30144320367SJordan Rose     // Non-array placement new should always return the placement location.
30244320367SJordan Rose     SVal PlacementLoc = State->getSVal(CNE->getPlacementArg(0), LCtx);
303aaf83184SJordan Rose     SVal Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(),
304aaf83184SJordan Rose                                        CNE->getPlacementArg(0)->getType());
305aaf83184SJordan Rose     State = State->BindExpr(CNE, LCtx, Result);
30644320367SJordan Rose   } else {
307a4ee064cSJordan Rose     State = State->BindExpr(CNE, LCtx, symVal);
30844320367SJordan Rose   }
30944320367SJordan Rose 
3105089f3b3SJordan Rose   // If the type is not a record, we won't have a CXXConstructExpr as an
3115089f3b3SJordan Rose   // initializer. Copy the value over.
3125089f3b3SJordan Rose   if (const Expr *Init = CNE->getInitializer()) {
3135089f3b3SJordan Rose     if (!isa<CXXConstructExpr>(Init)) {
3145089f3b3SJordan Rose       QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType();
3155089f3b3SJordan Rose       (void)ObjTy;
3165089f3b3SJordan Rose       assert(!ObjTy->isRecordType());
3175089f3b3SJordan Rose       SVal Location = State->getSVal(CNE, LCtx);
31805785d16SDavid Blaikie       if (Optional<Loc> LV = Location.getAs<Loc>())
3192fdacbc5SDavid Blaikie         State = State->bindLoc(*LV, State->getSVal(Init, LCtx));
3205089f3b3SJordan Rose     }
3215089f3b3SJordan Rose   }
3225089f3b3SJordan Rose 
32344320367SJordan Rose   Bldr.generateNode(CNE, Pred, State);
32410e25031STed Kremenek }
32510e25031STed Kremenek 
32610e25031STed Kremenek void ExprEngine::VisitCXXDeleteExpr(const CXXDeleteExpr *CDE,
32710e25031STed Kremenek                                     ExplodedNode *Pred, ExplodedNodeSet &Dst) {
328d94854a4STed Kremenek   StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
32964aea652SErik Verbruggen   ProgramStateRef state = Pred->getState();
33064aea652SErik Verbruggen   Bldr.generateNode(CDE, Pred, state);
33110e25031STed Kremenek }
33210e25031STed Kremenek 
3338fdb59f9STed Kremenek void ExprEngine::VisitCXXCatchStmt(const CXXCatchStmt *CS,
3348fdb59f9STed Kremenek                                    ExplodedNode *Pred,
3358fdb59f9STed Kremenek                                    ExplodedNodeSet &Dst) {
3368fdb59f9STed Kremenek   const VarDecl *VD = CS->getExceptionDecl();
337b1279b5cSTed Kremenek   if (!VD) {
338b1279b5cSTed Kremenek     Dst.Add(Pred);
339b1279b5cSTed Kremenek     return;
340b1279b5cSTed Kremenek   }
341b1279b5cSTed Kremenek 
3428fdb59f9STed Kremenek   const LocationContext *LCtx = Pred->getLocationContext();
343d227833cSTed Kremenek   SVal V = svalBuilder.conjureSymbolVal(CS, LCtx, VD->getType(),
344d94854a4STed Kremenek                                         currBldrCtx->blockCount());
3458fdb59f9STed Kremenek   ProgramStateRef state = Pred->getState();
3468fdb59f9STed Kremenek   state = state->bindLoc(state->getLValue(VD, LCtx), V);
3478fdb59f9STed Kremenek 
348d94854a4STed Kremenek   StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
3498fdb59f9STed Kremenek   Bldr.generateNode(CS, Pred, state);
3508fdb59f9STed Kremenek }
3518fdb59f9STed Kremenek 
35210e25031STed Kremenek void ExprEngine::VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred,
35310e25031STed Kremenek                                     ExplodedNodeSet &Dst) {
354d94854a4STed Kremenek   StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
355e594034fSAnna Zaks 
35610e25031STed Kremenek   // Get the this object region from StoreManager.
357632e3b7eSTed Kremenek   const LocationContext *LCtx = Pred->getLocationContext();
35810e25031STed Kremenek   const MemRegion *R =
35910e25031STed Kremenek     svalBuilder.getRegionManager().getCXXThisRegion(
36010e25031STed Kremenek                                   getContext().getCanonicalType(TE->getType()),
361632e3b7eSTed Kremenek                                                     LCtx);
36210e25031STed Kremenek 
36349b1e38eSTed Kremenek   ProgramStateRef state = Pred->getState();
36410e25031STed Kremenek   SVal V = state->getSVal(loc::MemRegionVal(R));
365632e3b7eSTed Kremenek   Bldr.generateNode(TE, Pred, state->BindExpr(TE, LCtx, V));
36610e25031STed Kremenek }
367