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. 37*861a1740SJordan Rose // This is an optimization for when an rvalue is constructed and then 38*861a1740SJordan Rose // immediately materialized. 39fcdda361SJordan Rose const MemRegion *MR = V.getAsRegion(); 40*861a1740SJordan Rose if (const CXXTempObjectRegion *TR = 41*861a1740SJordan Rose dyn_cast_or_null<CXXTempObjectRegion>(MR)) { 42*861a1740SJordan Rose if (getContext().hasSameUnqualifiedType(TR->getValueType(), ME->getType())) 435772f82dSJordan Rose state = state->BindExpr(ME, LCtx, V); 44*861a1740SJordan Rose } 4510e25031STed Kremenek 46*861a1740SJordan Rose if (state == Pred->getState()) 47*861a1740SJordan Rose state = createTemporaryRegionIfNeeded(state, LCtx, tempExpr, ME); 485772f82dSJordan Rose Bldr.generateNode(ME, Pred, state); 4910e25031STed Kremenek } 5010e25031STed Kremenek 5188bb563cSJordan Rose void ExprEngine::performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred, 5288bb563cSJordan Rose const CXXConstructorCall &Call) { 5388bb563cSJordan Rose const CXXConstructExpr *CtorExpr = Call.getOriginExpr(); 5488bb563cSJordan Rose assert(CtorExpr->getConstructor()->isCopyOrMoveConstructor()); 5588bb563cSJordan Rose assert(CtorExpr->getConstructor()->isTrivial()); 5688bb563cSJordan Rose 5788bb563cSJordan Rose SVal ThisVal = Call.getCXXThisVal(); 5888bb563cSJordan Rose const LocationContext *LCtx = Pred->getLocationContext(); 5988bb563cSJordan Rose 6088bb563cSJordan Rose ExplodedNodeSet Dst; 6188bb563cSJordan Rose Bldr.takeNodes(Pred); 6288bb563cSJordan Rose 6388bb563cSJordan Rose SVal V = Call.getArgSVal(0); 6488bb563cSJordan Rose 6588bb563cSJordan Rose // Make sure the value being copied is not unknown. 6605785d16SDavid Blaikie if (Optional<Loc> L = V.getAs<Loc>()) 6788bb563cSJordan Rose V = Pred->getState()->getSVal(*L); 6888bb563cSJordan Rose 6988bb563cSJordan Rose evalBind(Dst, CtorExpr, Pred, ThisVal, V, true); 7088bb563cSJordan Rose 7188bb563cSJordan Rose PostStmt PS(CtorExpr, LCtx); 7288bb563cSJordan Rose for (ExplodedNodeSet::iterator I = Dst.begin(), E = Dst.end(); 7388bb563cSJordan Rose I != E; ++I) { 7488bb563cSJordan Rose ProgramStateRef State = (*I)->getState(); 7588bb563cSJordan Rose State = bindReturnValue(Call, LCtx, State); 7688bb563cSJordan Rose Bldr.generateNode(PS, State, *I); 7788bb563cSJordan Rose } 7888bb563cSJordan Rose } 7988bb563cSJordan Rose 80f3c12ac3SJordan Rose void ExprEngine::VisitCXXConstructExpr(const CXXConstructExpr *CE, 8110e25031STed Kremenek ExplodedNode *Pred, 8210e25031STed Kremenek ExplodedNodeSet &destNodes) { 83b970505dSJordan Rose const LocationContext *LCtx = Pred->getLocationContext(); 8405375eb4SJordan Rose ProgramStateRef State = Pred->getState(); 8505375eb4SJordan Rose 86b970505dSJordan Rose const MemRegion *Target = 0; 8788bb563cSJordan Rose bool IsArray = false; 88b970505dSJordan Rose 89b970505dSJordan Rose switch (CE->getConstructionKind()) { 90b970505dSJordan Rose case CXXConstructExpr::CK_Complete: { 9105375eb4SJordan Rose // See if we're constructing an existing region by looking at the next 9205375eb4SJordan Rose // element in the CFG. 93d94854a4STed Kremenek const CFGBlock *B = currBldrCtx->getBlock(); 94d94854a4STed Kremenek if (currStmtIdx + 1 < B->size()) { 95d94854a4STed Kremenek CFGElement Next = (*B)[currStmtIdx+1]; 9605375eb4SJordan Rose 9705375eb4SJordan Rose // Is this a constructor for a local variable? 9800be69abSDavid Blaikie if (Optional<CFGStmt> StmtElem = Next.getAs<CFGStmt>()) { 9900be69abSDavid Blaikie if (const DeclStmt *DS = dyn_cast<DeclStmt>(StmtElem->getStmt())) { 10020edae87SJordan Rose if (const VarDecl *Var = dyn_cast<VarDecl>(DS->getSingleDecl())) { 10120edae87SJordan Rose if (Var->getInit()->IgnoreImplicit() == CE) { 10220edae87SJordan Rose QualType Ty = Var->getType(); 10320edae87SJordan Rose if (const ArrayType *AT = getContext().getAsArrayType(Ty)) { 10420edae87SJordan Rose // FIXME: Handle arrays, which run the same constructor for 10520edae87SJordan Rose // every element. This workaround will just run the first 10620edae87SJordan Rose // constructor (which should still invalidate the entire array). 10720edae87SJordan Rose SVal Base = State->getLValue(Var, LCtx); 10820edae87SJordan Rose Target = State->getLValue(AT->getElementType(), 10920edae87SJordan Rose getSValBuilder().makeZeroArrayIndex(), 11020edae87SJordan Rose Base).getAsRegion(); 11188bb563cSJordan Rose IsArray = true; 11220edae87SJordan Rose } else { 11305375eb4SJordan Rose Target = State->getLValue(Var, LCtx).getAsRegion(); 11420edae87SJordan Rose } 11520edae87SJordan Rose } 11620edae87SJordan Rose } 11720edae87SJordan Rose } 11820edae87SJordan Rose } 11905375eb4SJordan Rose 12054529a34SJordan Rose // Is this a constructor for a member? 12100be69abSDavid Blaikie if (Optional<CFGInitializer> InitElem = Next.getAs<CFGInitializer>()) { 12200be69abSDavid Blaikie const CXXCtorInitializer *Init = InitElem->getInitializer(); 12354529a34SJordan Rose assert(Init->isAnyMemberInitializer()); 12454529a34SJordan Rose 12554529a34SJordan Rose const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl()); 12654529a34SJordan Rose Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor, 12754529a34SJordan Rose LCtx->getCurrentStackFrame()); 12854529a34SJordan Rose SVal ThisVal = State->getSVal(ThisPtr); 12954529a34SJordan Rose 13054529a34SJordan Rose if (Init->isIndirectMemberInitializer()) { 13154529a34SJordan Rose SVal Field = State->getLValue(Init->getIndirectMember(), ThisVal); 13220edae87SJordan Rose Target = Field.getAsRegion(); 13354529a34SJordan Rose } else { 13454529a34SJordan Rose SVal Field = State->getLValue(Init->getMember(), ThisVal); 13520edae87SJordan Rose Target = Field.getAsRegion(); 13654529a34SJordan Rose } 13754529a34SJordan Rose } 13854529a34SJordan Rose 13905375eb4SJordan Rose // FIXME: This will eventually need to handle new-expressions as well. 14005375eb4SJordan Rose } 14105375eb4SJordan Rose 142c9318304SJordan Rose // If we couldn't find an existing region to construct into, assume we're 143c9318304SJordan Rose // constructing a temporary. 144c9318304SJordan Rose if (!Target) { 145c9318304SJordan Rose MemRegionManager &MRMgr = getSValBuilder().getRegionManager(); 146c9318304SJordan Rose Target = MRMgr.getCXXTempObjectRegion(CE, LCtx); 147c9318304SJordan Rose } 14805375eb4SJordan Rose 149b970505dSJordan Rose break; 150b970505dSJordan Rose } 151b970505dSJordan Rose case CXXConstructExpr::CK_NonVirtualBase: 152b970505dSJordan Rose case CXXConstructExpr::CK_VirtualBase: 153b970505dSJordan Rose case CXXConstructExpr::CK_Delegating: { 154b970505dSJordan Rose const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl()); 155b970505dSJordan Rose Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor, 156b970505dSJordan Rose LCtx->getCurrentStackFrame()); 15705375eb4SJordan Rose SVal ThisVal = State->getSVal(ThisPtr); 158b970505dSJordan Rose 159b970505dSJordan Rose if (CE->getConstructionKind() == CXXConstructExpr::CK_Delegating) { 160b970505dSJordan Rose Target = ThisVal.getAsRegion(); 161b970505dSJordan Rose } else { 162b970505dSJordan Rose // Cast to the base type. 163599f85abSJordan Rose bool IsVirtual = 164599f85abSJordan Rose (CE->getConstructionKind() == CXXConstructExpr::CK_VirtualBase); 165599f85abSJordan Rose SVal BaseVal = getStoreManager().evalDerivedToBase(ThisVal, CE->getType(), 166599f85abSJordan Rose IsVirtual); 16720edae87SJordan Rose Target = BaseVal.getAsRegion(); 168b970505dSJordan Rose } 169b970505dSJordan Rose break; 170b970505dSJordan Rose } 171b970505dSJordan Rose } 172b970505dSJordan Rose 173fcd016e5SJordan Rose CallEventManager &CEMgr = getStateManager().getCallEventManager(); 174fcd016e5SJordan Rose CallEventRef<CXXConstructorCall> Call = 175fcd016e5SJordan Rose CEMgr.getCXXConstructorCall(CE, Target, State, LCtx); 17610e25031STed Kremenek 177f3c12ac3SJordan Rose ExplodedNodeSet DstPreVisit; 178f3c12ac3SJordan Rose getCheckerManager().runCheckersForPreStmt(DstPreVisit, Pred, CE, *this); 179afe7c2c2SJordan Rose ExplodedNodeSet DstPreCall; 180afe7c2c2SJordan Rose getCheckerManager().runCheckersForPreCall(DstPreCall, DstPreVisit, 181fcd016e5SJordan Rose *Call, *this); 18210e25031STed Kremenek 18388bb563cSJordan Rose ExplodedNodeSet DstEvaluated; 18488bb563cSJordan Rose StmtNodeBuilder Bldr(DstPreCall, DstEvaluated, *currBldrCtx); 18588bb563cSJordan Rose 18688bb563cSJordan Rose if (CE->getConstructor()->isTrivial() && 18788bb563cSJordan Rose CE->getConstructor()->isCopyOrMoveConstructor() && 18888bb563cSJordan Rose !IsArray) { 18988bb563cSJordan Rose // FIXME: Handle other kinds of trivial constructors as well. 19088bb563cSJordan Rose for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end(); 19188bb563cSJordan Rose I != E; ++I) 19288bb563cSJordan Rose performTrivialCopy(Bldr, *I, *Call); 19388bb563cSJordan Rose 19488bb563cSJordan Rose } else { 195afe7c2c2SJordan Rose for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end(); 196f3c12ac3SJordan Rose I != E; ++I) 197fcd016e5SJordan Rose defaultEvalCall(Bldr, *I, *Call); 19888bb563cSJordan Rose } 19910e25031STed Kremenek 200afe7c2c2SJordan Rose ExplodedNodeSet DstPostCall; 20188bb563cSJordan Rose getCheckerManager().runCheckersForPostCall(DstPostCall, DstEvaluated, 202fcd016e5SJordan Rose *Call, *this); 203afe7c2c2SJordan Rose getCheckerManager().runCheckersForPostStmt(destNodes, DstPostCall, CE, *this); 20410e25031STed Kremenek } 20510e25031STed Kremenek 206b970505dSJordan Rose void ExprEngine::VisitCXXDestructor(QualType ObjectType, 20710e25031STed Kremenek const MemRegion *Dest, 20810e25031STed Kremenek const Stmt *S, 2092bc9674bSJordan Rose bool IsBaseDtor, 21010e25031STed Kremenek ExplodedNode *Pred, 21110e25031STed Kremenek ExplodedNodeSet &Dst) { 212fcd016e5SJordan Rose const LocationContext *LCtx = Pred->getLocationContext(); 213fcd016e5SJordan Rose ProgramStateRef State = Pred->getState(); 214fcd016e5SJordan Rose 21520edae87SJordan Rose // FIXME: We need to run the same destructor on every element of the array. 21620edae87SJordan Rose // This workaround will just run the first destructor (which will still 21720edae87SJordan Rose // invalidate the entire array). 2184cfdbff3SJordan Rose // This is a loop because of multidimensional arrays. 2194cfdbff3SJordan Rose while (const ArrayType *AT = getContext().getAsArrayType(ObjectType)) { 22020edae87SJordan Rose ObjectType = AT->getElementType(); 221fcd016e5SJordan Rose Dest = State->getLValue(ObjectType, getSValBuilder().makeZeroArrayIndex(), 22220edae87SJordan Rose loc::MemRegionVal(Dest)).getAsRegion(); 22320edae87SJordan Rose } 22420edae87SJordan Rose 225b970505dSJordan Rose const CXXRecordDecl *RecordDecl = ObjectType->getAsCXXRecordDecl(); 226b970505dSJordan Rose assert(RecordDecl && "Only CXXRecordDecls should have destructors"); 227b970505dSJordan Rose const CXXDestructorDecl *DtorDecl = RecordDecl->getDestructor(); 228b970505dSJordan Rose 229fcd016e5SJordan Rose CallEventManager &CEMgr = getStateManager().getCallEventManager(); 230fcd016e5SJordan Rose CallEventRef<CXXDestructorCall> Call = 2312bc9674bSJordan Rose CEMgr.getCXXDestructorCall(DtorDecl, S, Dest, IsBaseDtor, State, LCtx); 232142adc49STed Kremenek 23317a8757aSJordan Rose PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(), 23417a8757aSJordan Rose Call->getSourceRange().getBegin(), 23517a8757aSJordan Rose "Error evaluating destructor"); 23617a8757aSJordan Rose 2374ee71b8aSJordan Rose ExplodedNodeSet DstPreCall; 2384ee71b8aSJordan Rose getCheckerManager().runCheckersForPreCall(DstPreCall, Pred, 239fcd016e5SJordan Rose *Call, *this); 24010e25031STed Kremenek 2414ee71b8aSJordan Rose ExplodedNodeSet DstInvalidated; 242d94854a4STed Kremenek StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx); 2434ee71b8aSJordan Rose for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end(); 2444ee71b8aSJordan Rose I != E; ++I) 245fcd016e5SJordan Rose defaultEvalCall(Bldr, *I, *Call); 2464ee71b8aSJordan Rose 2474ee71b8aSJordan Rose ExplodedNodeSet DstPostCall; 2484ee71b8aSJordan Rose getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated, 249fcd016e5SJordan Rose *Call, *this); 25010e25031STed Kremenek } 25110e25031STed Kremenek 25210e25031STed Kremenek void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred, 25310e25031STed Kremenek ExplodedNodeSet &Dst) { 254a4ee064cSJordan Rose // FIXME: Much of this should eventually migrate to CXXAllocatorCall. 255a4ee064cSJordan Rose // Also, we need to decide how allocators actually work -- they're not 256a4ee064cSJordan Rose // really part of the CXXNewExpr because they happen BEFORE the 257a4ee064cSJordan Rose // CXXConstructExpr subexpression. See PR12014 for some discussion. 258d94854a4STed Kremenek StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); 25910e25031STed Kremenek 260d94854a4STed Kremenek unsigned blockCount = currBldrCtx->blockCount(); 261d519cae8STed Kremenek const LocationContext *LCtx = Pred->getLocationContext(); 262d227833cSTed Kremenek DefinedOrUnknownSVal symVal = svalBuilder.conjureSymbolVal(0, CNE, LCtx, 263d227833cSTed Kremenek CNE->getType(), 264d227833cSTed Kremenek blockCount); 26544320367SJordan Rose ProgramStateRef State = Pred->getState(); 26610e25031STed Kremenek 267fcd016e5SJordan Rose CallEventManager &CEMgr = getStateManager().getCallEventManager(); 268fcd016e5SJordan Rose CallEventRef<CXXAllocatorCall> Call = 269fcd016e5SJordan Rose CEMgr.getCXXAllocatorCall(CNE, State, LCtx); 270fcd016e5SJordan Rose 271a4ee064cSJordan Rose // Invalidate placement args. 272fcd016e5SJordan Rose // FIXME: Once we figure out how we want allocators to work, 273fcd016e5SJordan Rose // we should be using the usual pre-/(default-)eval-/post-call checks here. 274fcd016e5SJordan Rose State = Call->invalidateRegions(blockCount); 275a4ee064cSJordan Rose 2763957fd58SJordan Rose // If we're compiling with exceptions enabled, and this allocation function 2773957fd58SJordan Rose // is not declared as non-throwing, failures /must/ be signalled by 2783957fd58SJordan Rose // exceptions, and thus the return value will never be NULL. 2793957fd58SJordan Rose // C++11 [basic.stc.dynamic.allocation]p3. 2803957fd58SJordan Rose FunctionDecl *FD = CNE->getOperatorNew(); 2813957fd58SJordan Rose if (FD && getContext().getLangOpts().CXXExceptions) { 2823957fd58SJordan Rose QualType Ty = FD->getType(); 2833957fd58SJordan Rose if (const FunctionProtoType *ProtoType = Ty->getAs<FunctionProtoType>()) 2843957fd58SJordan Rose if (!ProtoType->isNothrow(getContext())) 2853957fd58SJordan Rose State = State->assume(symVal, true); 2863957fd58SJordan Rose } 2873957fd58SJordan Rose 28810e25031STed Kremenek if (CNE->isArray()) { 28910e25031STed Kremenek // FIXME: allocating an array requires simulating the constructors. 29010e25031STed Kremenek // For now, just return a symbolicated region. 2912fdacbc5SDavid Blaikie const MemRegion *NewReg = symVal.castAs<loc::MemRegionVal>().getRegion(); 292a4ee064cSJordan Rose QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType(); 293a4ee064cSJordan Rose const ElementRegion *EleReg = 294a4ee064cSJordan Rose getStoreManager().GetElementZeroRegion(NewReg, ObjTy); 29544320367SJordan Rose State = State->BindExpr(CNE, Pred->getLocationContext(), 296632e3b7eSTed Kremenek loc::MemRegionVal(EleReg)); 29744320367SJordan Rose Bldr.generateNode(CNE, Pred, State); 29810e25031STed Kremenek return; 29910e25031STed Kremenek } 30010e25031STed Kremenek 301a4ee064cSJordan Rose // FIXME: Once we have proper support for CXXConstructExprs inside 302a4ee064cSJordan Rose // CXXNewExpr, we need to make sure that the constructed object is not 303a4ee064cSJordan Rose // immediately invalidated here. (The placement call should happen before 304a4ee064cSJordan Rose // the constructor call anyway.) 30544320367SJordan Rose if (FD && FD->isReservedGlobalPlacementOperator()) { 30644320367SJordan Rose // Non-array placement new should always return the placement location. 30744320367SJordan Rose SVal PlacementLoc = State->getSVal(CNE->getPlacementArg(0), LCtx); 308aaf83184SJordan Rose SVal Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(), 309aaf83184SJordan Rose CNE->getPlacementArg(0)->getType()); 310aaf83184SJordan Rose State = State->BindExpr(CNE, LCtx, Result); 31144320367SJordan Rose } else { 312a4ee064cSJordan Rose State = State->BindExpr(CNE, LCtx, symVal); 31344320367SJordan Rose } 31444320367SJordan Rose 3155089f3b3SJordan Rose // If the type is not a record, we won't have a CXXConstructExpr as an 3165089f3b3SJordan Rose // initializer. Copy the value over. 3175089f3b3SJordan Rose if (const Expr *Init = CNE->getInitializer()) { 3185089f3b3SJordan Rose if (!isa<CXXConstructExpr>(Init)) { 3195089f3b3SJordan Rose QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType(); 3205089f3b3SJordan Rose (void)ObjTy; 3215089f3b3SJordan Rose assert(!ObjTy->isRecordType()); 3225089f3b3SJordan Rose SVal Location = State->getSVal(CNE, LCtx); 32305785d16SDavid Blaikie if (Optional<Loc> LV = Location.getAs<Loc>()) 3242fdacbc5SDavid Blaikie State = State->bindLoc(*LV, State->getSVal(Init, LCtx)); 3255089f3b3SJordan Rose } 3265089f3b3SJordan Rose } 3275089f3b3SJordan Rose 32844320367SJordan Rose Bldr.generateNode(CNE, Pred, State); 32910e25031STed Kremenek } 33010e25031STed Kremenek 33110e25031STed Kremenek void ExprEngine::VisitCXXDeleteExpr(const CXXDeleteExpr *CDE, 33210e25031STed Kremenek ExplodedNode *Pred, ExplodedNodeSet &Dst) { 333d94854a4STed Kremenek StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); 33464aea652SErik Verbruggen ProgramStateRef state = Pred->getState(); 33564aea652SErik Verbruggen Bldr.generateNode(CDE, Pred, state); 33610e25031STed Kremenek } 33710e25031STed Kremenek 3388fdb59f9STed Kremenek void ExprEngine::VisitCXXCatchStmt(const CXXCatchStmt *CS, 3398fdb59f9STed Kremenek ExplodedNode *Pred, 3408fdb59f9STed Kremenek ExplodedNodeSet &Dst) { 3418fdb59f9STed Kremenek const VarDecl *VD = CS->getExceptionDecl(); 342b1279b5cSTed Kremenek if (!VD) { 343b1279b5cSTed Kremenek Dst.Add(Pred); 344b1279b5cSTed Kremenek return; 345b1279b5cSTed Kremenek } 346b1279b5cSTed Kremenek 3478fdb59f9STed Kremenek const LocationContext *LCtx = Pred->getLocationContext(); 348d227833cSTed Kremenek SVal V = svalBuilder.conjureSymbolVal(CS, LCtx, VD->getType(), 349d94854a4STed Kremenek currBldrCtx->blockCount()); 3508fdb59f9STed Kremenek ProgramStateRef state = Pred->getState(); 3518fdb59f9STed Kremenek state = state->bindLoc(state->getLValue(VD, LCtx), V); 3528fdb59f9STed Kremenek 353d94854a4STed Kremenek StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); 3548fdb59f9STed Kremenek Bldr.generateNode(CS, Pred, state); 3558fdb59f9STed Kremenek } 3568fdb59f9STed Kremenek 35710e25031STed Kremenek void ExprEngine::VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred, 35810e25031STed Kremenek ExplodedNodeSet &Dst) { 359d94854a4STed Kremenek StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); 360e594034fSAnna Zaks 36110e25031STed Kremenek // Get the this object region from StoreManager. 362632e3b7eSTed Kremenek const LocationContext *LCtx = Pred->getLocationContext(); 36310e25031STed Kremenek const MemRegion *R = 36410e25031STed Kremenek svalBuilder.getRegionManager().getCXXThisRegion( 36510e25031STed Kremenek getContext().getCanonicalType(TE->getType()), 366632e3b7eSTed Kremenek LCtx); 36710e25031STed Kremenek 36849b1e38eSTed Kremenek ProgramStateRef state = Pred->getState(); 36910e25031STed Kremenek SVal V = state->getSVal(loc::MemRegionVal(R)); 370632e3b7eSTed Kremenek Bldr.generateNode(TE, Pred, state->BindExpr(TE, LCtx, V)); 37110e25031STed Kremenek } 372