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. 6705785d16SDavid 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. 164*599f85abSJordan Rose bool IsVirtual = 165*599f85abSJordan Rose (CE->getConstructionKind() == CXXConstructExpr::CK_VirtualBase); 166*599f85abSJordan Rose SVal BaseVal = getStoreManager().evalDerivedToBase(ThisVal, CE->getType(), 167*599f85abSJordan Rose IsVirtual); 16820edae87SJordan Rose Target = BaseVal.getAsRegion(); 169b970505dSJordan Rose } 170b970505dSJordan Rose break; 171b970505dSJordan Rose } 172b970505dSJordan Rose } 173b970505dSJordan Rose 174fcd016e5SJordan Rose CallEventManager &CEMgr = getStateManager().getCallEventManager(); 175fcd016e5SJordan Rose CallEventRef<CXXConstructorCall> Call = 176fcd016e5SJordan Rose CEMgr.getCXXConstructorCall(CE, Target, State, LCtx); 17710e25031STed Kremenek 178f3c12ac3SJordan Rose ExplodedNodeSet DstPreVisit; 179f3c12ac3SJordan Rose getCheckerManager().runCheckersForPreStmt(DstPreVisit, Pred, CE, *this); 180afe7c2c2SJordan Rose ExplodedNodeSet DstPreCall; 181afe7c2c2SJordan Rose getCheckerManager().runCheckersForPreCall(DstPreCall, DstPreVisit, 182fcd016e5SJordan Rose *Call, *this); 18310e25031STed Kremenek 18488bb563cSJordan Rose ExplodedNodeSet DstEvaluated; 18588bb563cSJordan Rose StmtNodeBuilder Bldr(DstPreCall, DstEvaluated, *currBldrCtx); 18688bb563cSJordan Rose 18788bb563cSJordan Rose if (CE->getConstructor()->isTrivial() && 18888bb563cSJordan Rose CE->getConstructor()->isCopyOrMoveConstructor() && 18988bb563cSJordan Rose !IsArray) { 19088bb563cSJordan Rose // FIXME: Handle other kinds of trivial constructors as well. 19188bb563cSJordan Rose for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end(); 19288bb563cSJordan Rose I != E; ++I) 19388bb563cSJordan Rose performTrivialCopy(Bldr, *I, *Call); 19488bb563cSJordan Rose 19588bb563cSJordan Rose } else { 196afe7c2c2SJordan Rose for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end(); 197f3c12ac3SJordan Rose I != E; ++I) 198fcd016e5SJordan Rose defaultEvalCall(Bldr, *I, *Call); 19988bb563cSJordan Rose } 20010e25031STed Kremenek 201afe7c2c2SJordan Rose ExplodedNodeSet DstPostCall; 20288bb563cSJordan Rose getCheckerManager().runCheckersForPostCall(DstPostCall, DstEvaluated, 203fcd016e5SJordan Rose *Call, *this); 204afe7c2c2SJordan Rose getCheckerManager().runCheckersForPostStmt(destNodes, DstPostCall, CE, *this); 20510e25031STed Kremenek } 20610e25031STed Kremenek 207b970505dSJordan Rose void ExprEngine::VisitCXXDestructor(QualType ObjectType, 20810e25031STed Kremenek const MemRegion *Dest, 20910e25031STed Kremenek const Stmt *S, 2102bc9674bSJordan Rose bool IsBaseDtor, 21110e25031STed Kremenek ExplodedNode *Pred, 21210e25031STed Kremenek ExplodedNodeSet &Dst) { 213fcd016e5SJordan Rose const LocationContext *LCtx = Pred->getLocationContext(); 214fcd016e5SJordan Rose ProgramStateRef State = Pred->getState(); 215fcd016e5SJordan Rose 21620edae87SJordan Rose // FIXME: We need to run the same destructor on every element of the array. 21720edae87SJordan Rose // This workaround will just run the first destructor (which will still 21820edae87SJordan Rose // invalidate the entire array). 2194cfdbff3SJordan Rose // This is a loop because of multidimensional arrays. 2204cfdbff3SJordan Rose while (const ArrayType *AT = getContext().getAsArrayType(ObjectType)) { 22120edae87SJordan Rose ObjectType = AT->getElementType(); 222fcd016e5SJordan Rose Dest = State->getLValue(ObjectType, getSValBuilder().makeZeroArrayIndex(), 22320edae87SJordan Rose loc::MemRegionVal(Dest)).getAsRegion(); 22420edae87SJordan Rose } 22520edae87SJordan Rose 226b970505dSJordan Rose const CXXRecordDecl *RecordDecl = ObjectType->getAsCXXRecordDecl(); 227b970505dSJordan Rose assert(RecordDecl && "Only CXXRecordDecls should have destructors"); 228b970505dSJordan Rose const CXXDestructorDecl *DtorDecl = RecordDecl->getDestructor(); 229b970505dSJordan Rose 230fcd016e5SJordan Rose CallEventManager &CEMgr = getStateManager().getCallEventManager(); 231fcd016e5SJordan Rose CallEventRef<CXXDestructorCall> Call = 2322bc9674bSJordan Rose CEMgr.getCXXDestructorCall(DtorDecl, S, Dest, IsBaseDtor, State, LCtx); 233142adc49STed Kremenek 23417a8757aSJordan Rose PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(), 23517a8757aSJordan Rose Call->getSourceRange().getBegin(), 23617a8757aSJordan Rose "Error evaluating destructor"); 23717a8757aSJordan Rose 2384ee71b8aSJordan Rose ExplodedNodeSet DstPreCall; 2394ee71b8aSJordan Rose getCheckerManager().runCheckersForPreCall(DstPreCall, Pred, 240fcd016e5SJordan Rose *Call, *this); 24110e25031STed Kremenek 2424ee71b8aSJordan Rose ExplodedNodeSet DstInvalidated; 243d94854a4STed Kremenek StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx); 2444ee71b8aSJordan Rose for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end(); 2454ee71b8aSJordan Rose I != E; ++I) 246fcd016e5SJordan Rose defaultEvalCall(Bldr, *I, *Call); 2474ee71b8aSJordan Rose 2484ee71b8aSJordan Rose ExplodedNodeSet DstPostCall; 2494ee71b8aSJordan Rose getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated, 250fcd016e5SJordan Rose *Call, *this); 25110e25031STed Kremenek } 25210e25031STed Kremenek 25310e25031STed Kremenek void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred, 25410e25031STed Kremenek ExplodedNodeSet &Dst) { 255a4ee064cSJordan Rose // FIXME: Much of this should eventually migrate to CXXAllocatorCall. 256a4ee064cSJordan Rose // Also, we need to decide how allocators actually work -- they're not 257a4ee064cSJordan Rose // really part of the CXXNewExpr because they happen BEFORE the 258a4ee064cSJordan Rose // CXXConstructExpr subexpression. See PR12014 for some discussion. 259d94854a4STed Kremenek StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); 26010e25031STed Kremenek 261d94854a4STed Kremenek unsigned blockCount = currBldrCtx->blockCount(); 262d519cae8STed Kremenek const LocationContext *LCtx = Pred->getLocationContext(); 263d227833cSTed Kremenek DefinedOrUnknownSVal symVal = svalBuilder.conjureSymbolVal(0, CNE, LCtx, 264d227833cSTed Kremenek CNE->getType(), 265d227833cSTed Kremenek blockCount); 26644320367SJordan Rose ProgramStateRef State = Pred->getState(); 26710e25031STed Kremenek 268fcd016e5SJordan Rose CallEventManager &CEMgr = getStateManager().getCallEventManager(); 269fcd016e5SJordan Rose CallEventRef<CXXAllocatorCall> Call = 270fcd016e5SJordan Rose CEMgr.getCXXAllocatorCall(CNE, State, LCtx); 271fcd016e5SJordan Rose 272a4ee064cSJordan Rose // Invalidate placement args. 273fcd016e5SJordan Rose // FIXME: Once we figure out how we want allocators to work, 274fcd016e5SJordan Rose // we should be using the usual pre-/(default-)eval-/post-call checks here. 275fcd016e5SJordan Rose State = Call->invalidateRegions(blockCount); 276a4ee064cSJordan Rose 2773957fd58SJordan Rose // If we're compiling with exceptions enabled, and this allocation function 2783957fd58SJordan Rose // is not declared as non-throwing, failures /must/ be signalled by 2793957fd58SJordan Rose // exceptions, and thus the return value will never be NULL. 2803957fd58SJordan Rose // C++11 [basic.stc.dynamic.allocation]p3. 2813957fd58SJordan Rose FunctionDecl *FD = CNE->getOperatorNew(); 2823957fd58SJordan Rose if (FD && getContext().getLangOpts().CXXExceptions) { 2833957fd58SJordan Rose QualType Ty = FD->getType(); 2843957fd58SJordan Rose if (const FunctionProtoType *ProtoType = Ty->getAs<FunctionProtoType>()) 2853957fd58SJordan Rose if (!ProtoType->isNothrow(getContext())) 2863957fd58SJordan Rose State = State->assume(symVal, true); 2873957fd58SJordan Rose } 2883957fd58SJordan Rose 28910e25031STed Kremenek if (CNE->isArray()) { 29010e25031STed Kremenek // FIXME: allocating an array requires simulating the constructors. 29110e25031STed Kremenek // For now, just return a symbolicated region. 2922fdacbc5SDavid Blaikie const MemRegion *NewReg = symVal.castAs<loc::MemRegionVal>().getRegion(); 293a4ee064cSJordan Rose QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType(); 294a4ee064cSJordan Rose const ElementRegion *EleReg = 295a4ee064cSJordan Rose getStoreManager().GetElementZeroRegion(NewReg, ObjTy); 29644320367SJordan Rose State = State->BindExpr(CNE, Pred->getLocationContext(), 297632e3b7eSTed Kremenek loc::MemRegionVal(EleReg)); 29844320367SJordan Rose Bldr.generateNode(CNE, Pred, State); 29910e25031STed Kremenek return; 30010e25031STed Kremenek } 30110e25031STed Kremenek 302a4ee064cSJordan Rose // FIXME: Once we have proper support for CXXConstructExprs inside 303a4ee064cSJordan Rose // CXXNewExpr, we need to make sure that the constructed object is not 304a4ee064cSJordan Rose // immediately invalidated here. (The placement call should happen before 305a4ee064cSJordan Rose // the constructor call anyway.) 30644320367SJordan Rose if (FD && FD->isReservedGlobalPlacementOperator()) { 30744320367SJordan Rose // Non-array placement new should always return the placement location. 30844320367SJordan Rose SVal PlacementLoc = State->getSVal(CNE->getPlacementArg(0), LCtx); 309aaf83184SJordan Rose SVal Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(), 310aaf83184SJordan Rose CNE->getPlacementArg(0)->getType()); 311aaf83184SJordan Rose State = State->BindExpr(CNE, LCtx, Result); 31244320367SJordan Rose } else { 313a4ee064cSJordan Rose State = State->BindExpr(CNE, LCtx, symVal); 31444320367SJordan Rose } 31544320367SJordan Rose 3165089f3b3SJordan Rose // If the type is not a record, we won't have a CXXConstructExpr as an 3175089f3b3SJordan Rose // initializer. Copy the value over. 3185089f3b3SJordan Rose if (const Expr *Init = CNE->getInitializer()) { 3195089f3b3SJordan Rose if (!isa<CXXConstructExpr>(Init)) { 3205089f3b3SJordan Rose QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType(); 3215089f3b3SJordan Rose (void)ObjTy; 3225089f3b3SJordan Rose assert(!ObjTy->isRecordType()); 3235089f3b3SJordan Rose SVal Location = State->getSVal(CNE, LCtx); 32405785d16SDavid Blaikie if (Optional<Loc> LV = Location.getAs<Loc>()) 3252fdacbc5SDavid Blaikie State = State->bindLoc(*LV, State->getSVal(Init, LCtx)); 3265089f3b3SJordan Rose } 3275089f3b3SJordan Rose } 3285089f3b3SJordan Rose 32944320367SJordan Rose Bldr.generateNode(CNE, Pred, State); 33010e25031STed Kremenek } 33110e25031STed Kremenek 33210e25031STed Kremenek void ExprEngine::VisitCXXDeleteExpr(const CXXDeleteExpr *CDE, 33310e25031STed Kremenek ExplodedNode *Pred, ExplodedNodeSet &Dst) { 334d94854a4STed Kremenek StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); 33564aea652SErik Verbruggen ProgramStateRef state = Pred->getState(); 33664aea652SErik Verbruggen Bldr.generateNode(CDE, Pred, state); 33710e25031STed Kremenek } 33810e25031STed Kremenek 3398fdb59f9STed Kremenek void ExprEngine::VisitCXXCatchStmt(const CXXCatchStmt *CS, 3408fdb59f9STed Kremenek ExplodedNode *Pred, 3418fdb59f9STed Kremenek ExplodedNodeSet &Dst) { 3428fdb59f9STed Kremenek const VarDecl *VD = CS->getExceptionDecl(); 343b1279b5cSTed Kremenek if (!VD) { 344b1279b5cSTed Kremenek Dst.Add(Pred); 345b1279b5cSTed Kremenek return; 346b1279b5cSTed Kremenek } 347b1279b5cSTed Kremenek 3488fdb59f9STed Kremenek const LocationContext *LCtx = Pred->getLocationContext(); 349d227833cSTed Kremenek SVal V = svalBuilder.conjureSymbolVal(CS, LCtx, VD->getType(), 350d94854a4STed Kremenek currBldrCtx->blockCount()); 3518fdb59f9STed Kremenek ProgramStateRef state = Pred->getState(); 3528fdb59f9STed Kremenek state = state->bindLoc(state->getLValue(VD, LCtx), V); 3538fdb59f9STed Kremenek 354d94854a4STed Kremenek StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); 3558fdb59f9STed Kremenek Bldr.generateNode(CS, Pred, state); 3568fdb59f9STed Kremenek } 3578fdb59f9STed Kremenek 35810e25031STed Kremenek void ExprEngine::VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred, 35910e25031STed Kremenek ExplodedNodeSet &Dst) { 360d94854a4STed Kremenek StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx); 361e594034fSAnna Zaks 36210e25031STed Kremenek // Get the this object region from StoreManager. 363632e3b7eSTed Kremenek const LocationContext *LCtx = Pred->getLocationContext(); 36410e25031STed Kremenek const MemRegion *R = 36510e25031STed Kremenek svalBuilder.getRegionManager().getCXXThisRegion( 36610e25031STed Kremenek getContext().getCanonicalType(TE->getType()), 367632e3b7eSTed Kremenek LCtx); 36810e25031STed Kremenek 36949b1e38eSTed Kremenek ProgramStateRef state = Pred->getState(); 37010e25031STed Kremenek SVal V = state->getSVal(loc::MemRegionVal(R)); 371632e3b7eSTed Kremenek Bldr.generateNode(TE, Pred, state->BindExpr(TE, LCtx, V)); 37210e25031STed Kremenek } 373