2011-08-20 13:59:58 +08:00
|
|
|
//===- ExprEngineCXX.cpp - ExprEngine support for C++ -----------*- C++ -*-===//
|
2010-04-19 20:51:02 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the C++ expression evaluation engine.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-02-10 09:03:03 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
2010-04-19 20:51:02 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2012-03-10 09:34:17 +08:00
|
|
|
#include "clang/AST/StmtCXX.h"
|
2012-08-04 07:31:15 +08:00
|
|
|
#include "clang/Basic/PrettyStackTrace.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
2010-04-19 20:51:02 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
2010-12-23 15:20:52 +08:00
|
|
|
using namespace ento;
|
2010-04-19 20:51:02 +08:00
|
|
|
|
2011-07-29 07:07:36 +08:00
|
|
|
void ExprEngine::CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2011-10-02 08:54:48 +08:00
|
|
|
const Expr *tempExpr = ME->GetTemporaryExpr()->IgnoreParens();
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2012-01-07 06:09:28 +08:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2010-04-19 20:51:02 +08:00
|
|
|
|
2011-10-02 08:54:48 +08:00
|
|
|
// Bind the temporary object to the value of the expression. Then bind
|
|
|
|
// the expression to the location of the object.
|
2012-08-28 01:50:07 +08:00
|
|
|
SVal V = state->getSVal(tempExpr, LCtx);
|
2010-04-19 20:51:02 +08:00
|
|
|
|
2012-09-06 01:11:26 +08:00
|
|
|
// If the value is already a CXXTempObjectRegion, it is fine as it is.
|
|
|
|
// Otherwise, create a new CXXTempObjectRegion, and copy the value into it.
|
|
|
|
const MemRegion *MR = V.getAsRegion();
|
|
|
|
if (!MR || !isa<CXXTempObjectRegion>(MR)) {
|
2012-08-28 01:50:07 +08:00
|
|
|
const MemRegion *R =
|
|
|
|
svalBuilder.getRegionManager().getCXXTempObjectRegion(ME, LCtx);
|
2010-04-19 20:51:02 +08:00
|
|
|
|
2012-08-28 01:50:07 +08:00
|
|
|
SVal L = loc::MemRegionVal(R);
|
|
|
|
state = state->bindLoc(L, V);
|
|
|
|
V = L;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bldr.generateNode(ME, Pred, state->BindExpr(ME, LCtx, V));
|
2010-04-19 20:51:02 +08:00
|
|
|
}
|
|
|
|
|
2013-02-15 08:32:15 +08:00
|
|
|
void ExprEngine::performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
|
|
|
|
const CXXConstructorCall &Call) {
|
|
|
|
const CXXConstructExpr *CtorExpr = Call.getOriginExpr();
|
|
|
|
assert(CtorExpr->getConstructor()->isCopyOrMoveConstructor());
|
|
|
|
assert(CtorExpr->getConstructor()->isTrivial());
|
|
|
|
|
|
|
|
SVal ThisVal = Call.getCXXThisVal();
|
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
|
|
|
|
ExplodedNodeSet Dst;
|
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
|
|
|
|
SVal V = Call.getArgSVal(0);
|
|
|
|
|
|
|
|
// Make sure the value being copied is not unknown.
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<Loc> L = V.getAs<Loc>())
|
2013-02-15 08:32:15 +08:00
|
|
|
V = Pred->getState()->getSVal(*L);
|
|
|
|
|
|
|
|
evalBind(Dst, CtorExpr, Pred, ThisVal, V, true);
|
|
|
|
|
|
|
|
PostStmt PS(CtorExpr, LCtx);
|
|
|
|
for (ExplodedNodeSet::iterator I = Dst.begin(), E = Dst.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
ProgramStateRef State = (*I)->getState();
|
|
|
|
State = bindReturnValue(Call, LCtx, State);
|
|
|
|
Bldr.generateNode(PS, State, *I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-03 03:28:12 +08:00
|
|
|
void ExprEngine::VisitCXXConstructExpr(const CXXConstructExpr *CE,
|
2011-04-09 06:42:35 +08:00
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &destNodes) {
|
2012-07-27 04:04:13 +08:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2012-07-27 04:04:16 +08:00
|
|
|
ProgramStateRef State = Pred->getState();
|
|
|
|
|
2012-07-27 04:04:13 +08:00
|
|
|
const MemRegion *Target = 0;
|
2013-02-15 08:32:15 +08:00
|
|
|
bool IsArray = false;
|
2012-07-27 04:04:13 +08:00
|
|
|
|
|
|
|
switch (CE->getConstructionKind()) {
|
|
|
|
case CXXConstructExpr::CK_Complete: {
|
2012-07-27 04:04:16 +08:00
|
|
|
// See if we're constructing an existing region by looking at the next
|
|
|
|
// element in the CFG.
|
2012-08-22 14:26:15 +08:00
|
|
|
const CFGBlock *B = currBldrCtx->getBlock();
|
|
|
|
if (currStmtIdx + 1 < B->size()) {
|
|
|
|
CFGElement Next = (*B)[currStmtIdx+1];
|
2012-07-27 04:04:16 +08:00
|
|
|
|
|
|
|
// Is this a constructor for a local variable?
|
2012-07-27 04:04:25 +08:00
|
|
|
if (const CFGStmt *StmtElem = dyn_cast<CFGStmt>(&Next)) {
|
|
|
|
if (const DeclStmt *DS = dyn_cast<DeclStmt>(StmtElem->getStmt())) {
|
|
|
|
if (const VarDecl *Var = dyn_cast<VarDecl>(DS->getSingleDecl())) {
|
|
|
|
if (Var->getInit()->IgnoreImplicit() == CE) {
|
|
|
|
QualType Ty = Var->getType();
|
|
|
|
if (const ArrayType *AT = getContext().getAsArrayType(Ty)) {
|
|
|
|
// FIXME: Handle arrays, which run the same constructor for
|
|
|
|
// every element. This workaround will just run the first
|
|
|
|
// constructor (which should still invalidate the entire array).
|
|
|
|
SVal Base = State->getLValue(Var, LCtx);
|
|
|
|
Target = State->getLValue(AT->getElementType(),
|
|
|
|
getSValBuilder().makeZeroArrayIndex(),
|
|
|
|
Base).getAsRegion();
|
2013-02-15 08:32:15 +08:00
|
|
|
IsArray = true;
|
2012-07-27 04:04:25 +08:00
|
|
|
} else {
|
|
|
|
Target = State->getLValue(Var, LCtx).getAsRegion();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-27 04:04:21 +08:00
|
|
|
// Is this a constructor for a member?
|
|
|
|
if (const CFGInitializer *InitElem = dyn_cast<CFGInitializer>(&Next)) {
|
|
|
|
const CXXCtorInitializer *Init = InitElem->getInitializer();
|
|
|
|
assert(Init->isAnyMemberInitializer());
|
|
|
|
|
|
|
|
const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl());
|
|
|
|
Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor,
|
|
|
|
LCtx->getCurrentStackFrame());
|
|
|
|
SVal ThisVal = State->getSVal(ThisPtr);
|
|
|
|
|
|
|
|
if (Init->isIndirectMemberInitializer()) {
|
|
|
|
SVal Field = State->getLValue(Init->getIndirectMember(), ThisVal);
|
2012-07-27 04:04:25 +08:00
|
|
|
Target = Field.getAsRegion();
|
2012-07-27 04:04:21 +08:00
|
|
|
} else {
|
|
|
|
SVal Field = State->getLValue(Init->getMember(), ThisVal);
|
2012-07-27 04:04:25 +08:00
|
|
|
Target = Field.getAsRegion();
|
2012-07-27 04:04:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-27 04:04:16 +08:00
|
|
|
// FIXME: This will eventually need to handle new-expressions as well.
|
|
|
|
}
|
|
|
|
|
2012-08-28 01:50:07 +08:00
|
|
|
// If we couldn't find an existing region to construct into, assume we're
|
|
|
|
// constructing a temporary.
|
|
|
|
if (!Target) {
|
|
|
|
MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
|
|
|
|
Target = MRMgr.getCXXTempObjectRegion(CE, LCtx);
|
|
|
|
}
|
2012-07-27 04:04:16 +08:00
|
|
|
|
2012-07-27 04:04:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CXXConstructExpr::CK_NonVirtualBase:
|
|
|
|
case CXXConstructExpr::CK_VirtualBase:
|
|
|
|
case CXXConstructExpr::CK_Delegating: {
|
|
|
|
const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl());
|
|
|
|
Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor,
|
|
|
|
LCtx->getCurrentStackFrame());
|
2012-07-27 04:04:16 +08:00
|
|
|
SVal ThisVal = State->getSVal(ThisPtr);
|
2012-07-27 04:04:13 +08:00
|
|
|
|
|
|
|
if (CE->getConstructionKind() == CXXConstructExpr::CK_Delegating) {
|
|
|
|
Target = ThisVal.getAsRegion();
|
|
|
|
} else {
|
|
|
|
// Cast to the base type.
|
|
|
|
QualType BaseTy = CE->getType();
|
|
|
|
SVal BaseVal = getStoreManager().evalDerivedToBase(ThisVal, BaseTy);
|
2012-07-27 04:04:25 +08:00
|
|
|
Target = BaseVal.getAsRegion();
|
2012-07-27 04:04:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 04:22:09 +08:00
|
|
|
CallEventManager &CEMgr = getStateManager().getCallEventManager();
|
|
|
|
CallEventRef<CXXConstructorCall> Call =
|
|
|
|
CEMgr.getCXXConstructorCall(CE, Target, State, LCtx);
|
2010-04-19 20:51:02 +08:00
|
|
|
|
2012-07-03 03:28:12 +08:00
|
|
|
ExplodedNodeSet DstPreVisit;
|
|
|
|
getCheckerManager().runCheckersForPreStmt(DstPreVisit, Pred, CE, *this);
|
2012-07-03 03:28:16 +08:00
|
|
|
ExplodedNodeSet DstPreCall;
|
|
|
|
getCheckerManager().runCheckersForPreCall(DstPreCall, DstPreVisit,
|
2012-07-31 04:22:09 +08:00
|
|
|
*Call, *this);
|
2011-04-09 06:42:35 +08:00
|
|
|
|
2013-02-15 08:32:15 +08:00
|
|
|
ExplodedNodeSet DstEvaluated;
|
|
|
|
StmtNodeBuilder Bldr(DstPreCall, DstEvaluated, *currBldrCtx);
|
|
|
|
|
|
|
|
if (CE->getConstructor()->isTrivial() &&
|
|
|
|
CE->getConstructor()->isCopyOrMoveConstructor() &&
|
|
|
|
!IsArray) {
|
|
|
|
// FIXME: Handle other kinds of trivial constructors as well.
|
|
|
|
for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
|
|
|
|
I != E; ++I)
|
|
|
|
performTrivialCopy(Bldr, *I, *Call);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
|
|
|
|
I != E; ++I)
|
|
|
|
defaultEvalCall(Bldr, *I, *Call);
|
|
|
|
}
|
2011-04-09 06:42:35 +08:00
|
|
|
|
2012-07-03 03:28:16 +08:00
|
|
|
ExplodedNodeSet DstPostCall;
|
2013-02-15 08:32:15 +08:00
|
|
|
getCheckerManager().runCheckersForPostCall(DstPostCall, DstEvaluated,
|
2012-07-31 04:22:09 +08:00
|
|
|
*Call, *this);
|
2012-07-03 03:28:16 +08:00
|
|
|
getCheckerManager().runCheckersForPostStmt(destNodes, DstPostCall, CE, *this);
|
2010-04-19 20:51:02 +08:00
|
|
|
}
|
|
|
|
|
2012-07-27 04:04:13 +08:00
|
|
|
void ExprEngine::VisitCXXDestructor(QualType ObjectType,
|
|
|
|
const MemRegion *Dest,
|
|
|
|
const Stmt *S,
|
2012-09-07 04:37:08 +08:00
|
|
|
bool IsBaseDtor,
|
2012-07-27 04:04:13 +08:00
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2012-07-31 04:22:09 +08:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
ProgramStateRef State = Pred->getState();
|
|
|
|
|
2012-07-27 04:04:25 +08:00
|
|
|
// FIXME: We need to run the same destructor on every element of the array.
|
|
|
|
// This workaround will just run the first destructor (which will still
|
|
|
|
// invalidate the entire array).
|
2012-12-13 03:13:44 +08:00
|
|
|
// This is a loop because of multidimensional arrays.
|
|
|
|
while (const ArrayType *AT = getContext().getAsArrayType(ObjectType)) {
|
2012-07-27 04:04:25 +08:00
|
|
|
ObjectType = AT->getElementType();
|
2012-07-31 04:22:09 +08:00
|
|
|
Dest = State->getLValue(ObjectType, getSValBuilder().makeZeroArrayIndex(),
|
|
|
|
loc::MemRegionVal(Dest)).getAsRegion();
|
2012-07-27 04:04:25 +08:00
|
|
|
}
|
|
|
|
|
2012-07-27 04:04:13 +08:00
|
|
|
const CXXRecordDecl *RecordDecl = ObjectType->getAsCXXRecordDecl();
|
|
|
|
assert(RecordDecl && "Only CXXRecordDecls should have destructors");
|
|
|
|
const CXXDestructorDecl *DtorDecl = RecordDecl->getDestructor();
|
|
|
|
|
2012-07-31 04:22:09 +08:00
|
|
|
CallEventManager &CEMgr = getStateManager().getCallEventManager();
|
|
|
|
CallEventRef<CXXDestructorCall> Call =
|
2012-09-07 04:37:08 +08:00
|
|
|
CEMgr.getCXXDestructorCall(DtorDecl, S, Dest, IsBaseDtor, State, LCtx);
|
2011-10-23 10:31:52 +08:00
|
|
|
|
2012-08-04 07:31:15 +08:00
|
|
|
PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
|
|
|
|
Call->getSourceRange().getBegin(),
|
|
|
|
"Error evaluating destructor");
|
|
|
|
|
2012-07-11 06:07:47 +08:00
|
|
|
ExplodedNodeSet DstPreCall;
|
|
|
|
getCheckerManager().runCheckersForPreCall(DstPreCall, Pred,
|
2012-07-31 04:22:09 +08:00
|
|
|
*Call, *this);
|
2010-11-20 14:53:12 +08:00
|
|
|
|
2012-07-11 06:07:47 +08:00
|
|
|
ExplodedNodeSet DstInvalidated;
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
|
2012-07-11 06:07:47 +08:00
|
|
|
for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
|
|
|
|
I != E; ++I)
|
2012-07-31 04:22:09 +08:00
|
|
|
defaultEvalCall(Bldr, *I, *Call);
|
2012-07-11 06:07:47 +08:00
|
|
|
|
|
|
|
ExplodedNodeSet DstPostCall;
|
|
|
|
getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
|
2012-07-31 04:22:09 +08:00
|
|
|
*Call, *this);
|
2010-11-20 14:53:12 +08:00
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
|
2010-04-19 20:51:02 +08:00
|
|
|
ExplodedNodeSet &Dst) {
|
2012-07-03 06:21:47 +08:00
|
|
|
// FIXME: Much of this should eventually migrate to CXXAllocatorCall.
|
|
|
|
// Also, we need to decide how allocators actually work -- they're not
|
|
|
|
// really part of the CXXNewExpr because they happen BEFORE the
|
|
|
|
// CXXConstructExpr subexpression. See PR12014 for some discussion.
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2011-03-31 12:04:48 +08:00
|
|
|
|
2012-08-22 14:26:15 +08:00
|
|
|
unsigned blockCount = currBldrCtx->blockCount();
|
2012-02-18 07:13:45 +08:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2012-08-22 14:26:06 +08:00
|
|
|
DefinedOrUnknownSVal symVal = svalBuilder.conjureSymbolVal(0, CNE, LCtx,
|
|
|
|
CNE->getType(),
|
|
|
|
blockCount);
|
2012-06-20 09:32:01 +08:00
|
|
|
ProgramStateRef State = Pred->getState();
|
2011-03-31 12:04:48 +08:00
|
|
|
|
2012-07-31 04:22:09 +08:00
|
|
|
CallEventManager &CEMgr = getStateManager().getCallEventManager();
|
|
|
|
CallEventRef<CXXAllocatorCall> Call =
|
|
|
|
CEMgr.getCXXAllocatorCall(CNE, State, LCtx);
|
|
|
|
|
2012-07-03 06:21:47 +08:00
|
|
|
// Invalidate placement args.
|
2012-07-31 04:22:09 +08:00
|
|
|
// FIXME: Once we figure out how we want allocators to work,
|
|
|
|
// we should be using the usual pre-/(default-)eval-/post-call checks here.
|
|
|
|
State = Call->invalidateRegions(blockCount);
|
2012-07-03 06:21:47 +08:00
|
|
|
|
2012-10-20 10:32:51 +08:00
|
|
|
// If we're compiling with exceptions enabled, and this allocation function
|
|
|
|
// is not declared as non-throwing, failures /must/ be signalled by
|
|
|
|
// exceptions, and thus the return value will never be NULL.
|
|
|
|
// C++11 [basic.stc.dynamic.allocation]p3.
|
|
|
|
FunctionDecl *FD = CNE->getOperatorNew();
|
|
|
|
if (FD && getContext().getLangOpts().CXXExceptions) {
|
|
|
|
QualType Ty = FD->getType();
|
|
|
|
if (const FunctionProtoType *ProtoType = Ty->getAs<FunctionProtoType>())
|
|
|
|
if (!ProtoType->isNothrow(getContext()))
|
|
|
|
State = State->assume(symVal, true);
|
|
|
|
}
|
|
|
|
|
2011-03-31 12:04:48 +08:00
|
|
|
if (CNE->isArray()) {
|
|
|
|
// FIXME: allocating an array requires simulating the constructors.
|
|
|
|
// For now, just return a symbolicated region.
|
2013-02-20 13:52:05 +08:00
|
|
|
const MemRegion *NewReg = symVal.castAs<loc::MemRegionVal>().getRegion();
|
2012-07-03 06:21:47 +08:00
|
|
|
QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType();
|
|
|
|
const ElementRegion *EleReg =
|
|
|
|
getStoreManager().GetElementZeroRegion(NewReg, ObjTy);
|
2012-06-20 09:32:01 +08:00
|
|
|
State = State->BindExpr(CNE, Pred->getLocationContext(),
|
2012-01-07 06:09:28 +08:00
|
|
|
loc::MemRegionVal(EleReg));
|
2012-06-20 09:32:01 +08:00
|
|
|
Bldr.generateNode(CNE, Pred, State);
|
2011-03-31 12:04:48 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-04-19 20:51:02 +08:00
|
|
|
|
2012-07-03 06:21:47 +08:00
|
|
|
// FIXME: Once we have proper support for CXXConstructExprs inside
|
|
|
|
// CXXNewExpr, we need to make sure that the constructed object is not
|
|
|
|
// immediately invalidated here. (The placement call should happen before
|
|
|
|
// the constructor call anyway.)
|
2012-06-20 09:32:01 +08:00
|
|
|
if (FD && FD->isReservedGlobalPlacementOperator()) {
|
|
|
|
// Non-array placement new should always return the placement location.
|
|
|
|
SVal PlacementLoc = State->getSVal(CNE->getPlacementArg(0), LCtx);
|
2012-09-08 09:24:38 +08:00
|
|
|
SVal Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(),
|
|
|
|
CNE->getPlacementArg(0)->getType());
|
|
|
|
State = State->BindExpr(CNE, LCtx, Result);
|
2012-07-03 06:21:47 +08:00
|
|
|
} else {
|
|
|
|
State = State->BindExpr(CNE, LCtx, symVal);
|
2012-06-20 09:32:01 +08:00
|
|
|
}
|
|
|
|
|
2012-07-17 07:38:09 +08:00
|
|
|
// If the type is not a record, we won't have a CXXConstructExpr as an
|
|
|
|
// initializer. Copy the value over.
|
|
|
|
if (const Expr *Init = CNE->getInitializer()) {
|
|
|
|
if (!isa<CXXConstructExpr>(Init)) {
|
|
|
|
QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType();
|
|
|
|
(void)ObjTy;
|
|
|
|
assert(!ObjTy->isRecordType());
|
|
|
|
SVal Location = State->getSVal(CNE, LCtx);
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<Loc> LV = Location.getAs<Loc>())
|
2013-02-20 13:52:05 +08:00
|
|
|
State = State->bindLoc(*LV, State->getSVal(Init, LCtx));
|
2012-07-17 07:38:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 09:32:01 +08:00
|
|
|
Bldr.generateNode(CNE, Pred, State);
|
2010-04-19 20:51:02 +08:00
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::VisitCXXDeleteExpr(const CXXDeleteExpr *CDE,
|
2011-10-25 02:26:19 +08:00
|
|
|
ExplodedNode *Pred, ExplodedNodeSet &Dst) {
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2012-02-29 16:42:57 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
|
|
|
Bldr.generateNode(CDE, Pred, state);
|
2010-04-21 10:17:31 +08:00
|
|
|
}
|
2010-04-19 20:51:02 +08:00
|
|
|
|
2012-03-10 09:34:17 +08:00
|
|
|
void ExprEngine::VisitCXXCatchStmt(const CXXCatchStmt *CS,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
|
|
|
const VarDecl *VD = CS->getExceptionDecl();
|
2012-03-16 13:58:15 +08:00
|
|
|
if (!VD) {
|
|
|
|
Dst.Add(Pred);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-10 09:34:17 +08:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2012-08-22 14:26:06 +08:00
|
|
|
SVal V = svalBuilder.conjureSymbolVal(CS, LCtx, VD->getType(),
|
2012-08-22 14:26:15 +08:00
|
|
|
currBldrCtx->blockCount());
|
2012-03-10 09:34:17 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
|
|
|
state = state->bindLoc(state->getLValue(VD, LCtx), V);
|
|
|
|
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2012-03-10 09:34:17 +08:00
|
|
|
Bldr.generateNode(CS, Pred, state);
|
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred,
|
2010-04-21 10:17:31 +08:00
|
|
|
ExplodedNodeSet &Dst) {
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2011-10-25 02:26:19 +08:00
|
|
|
|
2010-04-19 20:51:02 +08:00
|
|
|
// Get the this object region from StoreManager.
|
2012-01-07 06:09:28 +08:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2010-04-19 20:51:02 +08:00
|
|
|
const MemRegion *R =
|
2010-12-02 15:49:45 +08:00
|
|
|
svalBuilder.getRegionManager().getCXXThisRegion(
|
2010-04-19 20:51:02 +08:00
|
|
|
getContext().getCanonicalType(TE->getType()),
|
2012-01-07 06:09:28 +08:00
|
|
|
LCtx);
|
2010-04-19 20:51:02 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2010-04-19 20:51:02 +08:00
|
|
|
SVal V = state->getSVal(loc::MemRegionVal(R));
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(TE, Pred, state->BindExpr(TE, LCtx, V));
|
2010-04-19 20:51:02 +08:00
|
|
|
}
|