2011-08-20 05:59:58 +00:00
|
|
|
//===- ExprEngineCXX.cpp - ExprEngine support for C++ -----------*- C++ -*-===//
|
2010-04-19 12:51:02 +00: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 01:03:03 +00:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
2010-04-19 12:51:02 +00:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2012-03-10 01:34:17 +00:00
|
|
|
#include "clang/AST/StmtCXX.h"
|
2012-08-03 23:31:15 +00:00
|
|
|
#include "clang/Basic/PrettyStackTrace.h"
|
2012-12-04 09:13:33 +00:00
|
|
|
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
2010-04-19 12:51:02 +00:00
|
|
|
|
|
|
|
using namespace clang;
|
2010-12-23 07:20:52 +00:00
|
|
|
using namespace ento;
|
2010-04-19 12:51:02 +00:00
|
|
|
|
2011-07-28 23:07:36 +00:00
|
|
|
void ExprEngine::CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2012-08-22 06:26:15 +00:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2011-10-02 00:54:48 +00:00
|
|
|
const Expr *tempExpr = ME->GetTemporaryExpr()->IgnoreParens();
|
2012-01-26 21:29:00 +00:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2012-01-06 22:09:28 +00:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2010-04-19 12:51:02 +00:00
|
|
|
|
2012-08-27 17:50:07 +00:00
|
|
|
SVal V = state->getSVal(tempExpr, LCtx);
|
2010-04-19 12:51:02 +00:00
|
|
|
|
2012-09-05 17:11:26 +00: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.
|
2013-02-26 01:21:27 +00:00
|
|
|
// This is an optimization for when an rvalue is constructed and then
|
|
|
|
// immediately materialized.
|
2012-09-05 17:11:26 +00:00
|
|
|
const MemRegion *MR = V.getAsRegion();
|
2013-02-26 01:21:27 +00:00
|
|
|
if (const CXXTempObjectRegion *TR =
|
|
|
|
dyn_cast_or_null<CXXTempObjectRegion>(MR)) {
|
|
|
|
if (getContext().hasSameUnqualifiedType(TR->getValueType(), ME->getType()))
|
|
|
|
state = state->BindExpr(ME, LCtx, V);
|
|
|
|
}
|
2010-04-19 12:51:02 +00:00
|
|
|
|
2013-02-26 01:21:27 +00:00
|
|
|
if (state == Pred->getState())
|
|
|
|
state = createTemporaryRegionIfNeeded(state, LCtx, tempExpr, ME);
|
2013-02-22 01:51:15 +00:00
|
|
|
Bldr.generateNode(ME, Pred, state);
|
2010-04-19 12:51:02 +00:00
|
|
|
}
|
|
|
|
|
2013-03-16 02:14:06 +00:00
|
|
|
// FIXME: This is the sort of code that should eventually live in a Core
|
|
|
|
// checker rather than as a special case in ExprEngine.
|
2013-02-15 00:32:15 +00:00
|
|
|
void ExprEngine::performTrivialCopy(NodeBuilder &Bldr, ExplodedNode *Pred,
|
2013-03-16 02:14:06 +00:00
|
|
|
const CallEvent &Call) {
|
|
|
|
SVal ThisVal;
|
|
|
|
bool AlwaysReturnsLValue;
|
|
|
|
if (const CXXConstructorCall *Ctor = dyn_cast<CXXConstructorCall>(&Call)) {
|
|
|
|
assert(Ctor->getDecl()->isTrivial());
|
|
|
|
assert(Ctor->getDecl()->isCopyOrMoveConstructor());
|
|
|
|
ThisVal = Ctor->getCXXThisVal();
|
|
|
|
AlwaysReturnsLValue = false;
|
|
|
|
} else {
|
|
|
|
assert(cast<CXXMethodDecl>(Call.getDecl())->isTrivial());
|
|
|
|
assert(cast<CXXMethodDecl>(Call.getDecl())->getOverloadedOperator() ==
|
|
|
|
OO_Equal);
|
|
|
|
ThisVal = cast<CXXInstanceCall>(Call).getCXXThisVal();
|
|
|
|
AlwaysReturnsLValue = true;
|
|
|
|
}
|
2013-02-15 00:32:15 +00:00
|
|
|
|
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
|
|
|
|
ExplodedNodeSet Dst;
|
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
|
|
|
|
SVal V = Call.getArgSVal(0);
|
|
|
|
|
2013-03-16 02:14:06 +00:00
|
|
|
// If the value being copied is not unknown, load from its location to get
|
|
|
|
// an aggregate rvalue.
|
2013-02-20 22:23:23 +00:00
|
|
|
if (Optional<Loc> L = V.getAs<Loc>())
|
2013-02-15 00:32:15 +00:00
|
|
|
V = Pred->getState()->getSVal(*L);
|
2013-03-16 02:14:06 +00:00
|
|
|
else
|
|
|
|
assert(V.isUnknown());
|
2013-02-15 00:32:15 +00:00
|
|
|
|
2013-03-16 02:14:06 +00:00
|
|
|
const Expr *CallExpr = Call.getOriginExpr();
|
|
|
|
evalBind(Dst, CallExpr, Pred, ThisVal, V, true);
|
2013-02-15 00:32:15 +00:00
|
|
|
|
2013-03-16 02:14:06 +00:00
|
|
|
PostStmt PS(CallExpr, LCtx);
|
2013-02-15 00:32:15 +00:00
|
|
|
for (ExplodedNodeSet::iterator I = Dst.begin(), E = Dst.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
ProgramStateRef State = (*I)->getState();
|
2013-03-16 02:14:06 +00:00
|
|
|
if (AlwaysReturnsLValue)
|
|
|
|
State = State->BindExpr(CallExpr, LCtx, ThisVal);
|
|
|
|
else
|
|
|
|
State = bindReturnValue(Call, LCtx, State);
|
2013-02-15 00:32:15 +00:00
|
|
|
Bldr.generateNode(PS, State, *I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-02 19:28:12 +00:00
|
|
|
void ExprEngine::VisitCXXConstructExpr(const CXXConstructExpr *CE,
|
2011-04-08 22:42:35 +00:00
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &destNodes) {
|
2012-07-26 20:04:13 +00:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2012-07-26 20:04:16 +00:00
|
|
|
ProgramStateRef State = Pred->getState();
|
|
|
|
|
2012-07-26 20:04:13 +00:00
|
|
|
const MemRegion *Target = 0;
|
2013-02-15 00:32:15 +00:00
|
|
|
bool IsArray = false;
|
2012-07-26 20:04:13 +00:00
|
|
|
|
|
|
|
switch (CE->getConstructionKind()) {
|
|
|
|
case CXXConstructExpr::CK_Complete: {
|
2012-07-26 20:04:16 +00:00
|
|
|
// See if we're constructing an existing region by looking at the next
|
|
|
|
// element in the CFG.
|
2012-08-22 06:26:15 +00:00
|
|
|
const CFGBlock *B = currBldrCtx->getBlock();
|
|
|
|
if (currStmtIdx + 1 < B->size()) {
|
|
|
|
CFGElement Next = (*B)[currStmtIdx+1];
|
2012-07-26 20:04:16 +00:00
|
|
|
|
|
|
|
// Is this a constructor for a local variable?
|
2013-02-23 00:29:34 +00:00
|
|
|
if (Optional<CFGStmt> StmtElem = Next.getAs<CFGStmt>()) {
|
|
|
|
if (const DeclStmt *DS = dyn_cast<DeclStmt>(StmtElem->getStmt())) {
|
2012-07-26 20:04:25 +00:00
|
|
|
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 00:32:15 +00:00
|
|
|
IsArray = true;
|
2012-07-26 20:04:25 +00:00
|
|
|
} else {
|
|
|
|
Target = State->getLValue(Var, LCtx).getAsRegion();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 20:04:21 +00:00
|
|
|
// Is this a constructor for a member?
|
2013-02-23 00:29:34 +00:00
|
|
|
if (Optional<CFGInitializer> InitElem = Next.getAs<CFGInitializer>()) {
|
|
|
|
const CXXCtorInitializer *Init = InitElem->getInitializer();
|
2012-07-26 20:04:21 +00:00
|
|
|
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-26 20:04:25 +00:00
|
|
|
Target = Field.getAsRegion();
|
2012-07-26 20:04:21 +00:00
|
|
|
} else {
|
|
|
|
SVal Field = State->getLValue(Init->getMember(), ThisVal);
|
2012-07-26 20:04:25 +00:00
|
|
|
Target = Field.getAsRegion();
|
2012-07-26 20:04:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 20:04:16 +00:00
|
|
|
// FIXME: This will eventually need to handle new-expressions as well.
|
|
|
|
}
|
|
|
|
|
2012-08-27 17:50:07 +00: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-26 20:04:16 +00:00
|
|
|
|
2012-07-26 20:04:13 +00: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-26 20:04:16 +00:00
|
|
|
SVal ThisVal = State->getSVal(ThisPtr);
|
2012-07-26 20:04:13 +00:00
|
|
|
|
|
|
|
if (CE->getConstructionKind() == CXXConstructExpr::CK_Delegating) {
|
|
|
|
Target = ThisVal.getAsRegion();
|
|
|
|
} else {
|
|
|
|
// Cast to the base type.
|
2013-02-21 03:12:32 +00:00
|
|
|
bool IsVirtual =
|
|
|
|
(CE->getConstructionKind() == CXXConstructExpr::CK_VirtualBase);
|
|
|
|
SVal BaseVal = getStoreManager().evalDerivedToBase(ThisVal, CE->getType(),
|
|
|
|
IsVirtual);
|
2012-07-26 20:04:25 +00:00
|
|
|
Target = BaseVal.getAsRegion();
|
2012-07-26 20:04:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 20:22:09 +00:00
|
|
|
CallEventManager &CEMgr = getStateManager().getCallEventManager();
|
|
|
|
CallEventRef<CXXConstructorCall> Call =
|
|
|
|
CEMgr.getCXXConstructorCall(CE, Target, State, LCtx);
|
2010-04-19 12:51:02 +00:00
|
|
|
|
2012-07-02 19:28:12 +00:00
|
|
|
ExplodedNodeSet DstPreVisit;
|
|
|
|
getCheckerManager().runCheckersForPreStmt(DstPreVisit, Pred, CE, *this);
|
2012-07-02 19:28:16 +00:00
|
|
|
ExplodedNodeSet DstPreCall;
|
|
|
|
getCheckerManager().runCheckersForPreCall(DstPreCall, DstPreVisit,
|
2012-07-30 20:22:09 +00:00
|
|
|
*Call, *this);
|
2011-04-08 22:42:35 +00:00
|
|
|
|
2013-02-15 00:32:15 +00: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-08 22:42:35 +00:00
|
|
|
|
2012-07-02 19:28:16 +00:00
|
|
|
ExplodedNodeSet DstPostCall;
|
2013-02-15 00:32:15 +00:00
|
|
|
getCheckerManager().runCheckersForPostCall(DstPostCall, DstEvaluated,
|
2012-07-30 20:22:09 +00:00
|
|
|
*Call, *this);
|
2012-07-02 19:28:16 +00:00
|
|
|
getCheckerManager().runCheckersForPostStmt(destNodes, DstPostCall, CE, *this);
|
2010-04-19 12:51:02 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 20:04:13 +00:00
|
|
|
void ExprEngine::VisitCXXDestructor(QualType ObjectType,
|
|
|
|
const MemRegion *Dest,
|
|
|
|
const Stmt *S,
|
2012-09-06 20:37:08 +00:00
|
|
|
bool IsBaseDtor,
|
2012-07-26 20:04:13 +00:00
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2012-07-30 20:22:09 +00:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
ProgramStateRef State = Pred->getState();
|
|
|
|
|
2012-07-26 20:04:25 +00: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-12 19:13:44 +00:00
|
|
|
// This is a loop because of multidimensional arrays.
|
|
|
|
while (const ArrayType *AT = getContext().getAsArrayType(ObjectType)) {
|
2012-07-26 20:04:25 +00:00
|
|
|
ObjectType = AT->getElementType();
|
2012-07-30 20:22:09 +00:00
|
|
|
Dest = State->getLValue(ObjectType, getSValBuilder().makeZeroArrayIndex(),
|
|
|
|
loc::MemRegionVal(Dest)).getAsRegion();
|
2012-07-26 20:04:25 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 20:04:13 +00:00
|
|
|
const CXXRecordDecl *RecordDecl = ObjectType->getAsCXXRecordDecl();
|
|
|
|
assert(RecordDecl && "Only CXXRecordDecls should have destructors");
|
|
|
|
const CXXDestructorDecl *DtorDecl = RecordDecl->getDestructor();
|
|
|
|
|
2012-07-30 20:22:09 +00:00
|
|
|
CallEventManager &CEMgr = getStateManager().getCallEventManager();
|
|
|
|
CallEventRef<CXXDestructorCall> Call =
|
2012-09-06 20:37:08 +00:00
|
|
|
CEMgr.getCXXDestructorCall(DtorDecl, S, Dest, IsBaseDtor, State, LCtx);
|
2011-10-23 02:31:52 +00:00
|
|
|
|
2012-08-03 23:31:15 +00:00
|
|
|
PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
|
|
|
|
Call->getSourceRange().getBegin(),
|
|
|
|
"Error evaluating destructor");
|
|
|
|
|
2012-07-10 22:07:47 +00:00
|
|
|
ExplodedNodeSet DstPreCall;
|
|
|
|
getCheckerManager().runCheckersForPreCall(DstPreCall, Pred,
|
2012-07-30 20:22:09 +00:00
|
|
|
*Call, *this);
|
2010-11-20 06:53:12 +00:00
|
|
|
|
2012-07-10 22:07:47 +00:00
|
|
|
ExplodedNodeSet DstInvalidated;
|
2012-08-22 06:26:15 +00:00
|
|
|
StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
|
2012-07-10 22:07:47 +00:00
|
|
|
for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
|
|
|
|
I != E; ++I)
|
2012-07-30 20:22:09 +00:00
|
|
|
defaultEvalCall(Bldr, *I, *Call);
|
2012-07-10 22:07:47 +00:00
|
|
|
|
|
|
|
ExplodedNodeSet DstPostCall;
|
|
|
|
getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
|
2012-07-30 20:22:09 +00:00
|
|
|
*Call, *this);
|
2010-11-20 06:53:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-22 18:53:44 +00:00
|
|
|
void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
|
2010-04-19 12:51:02 +00:00
|
|
|
ExplodedNodeSet &Dst) {
|
2012-07-02 22:21:47 +00: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 06:26:15 +00:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2011-03-31 04:04:48 +00:00
|
|
|
|
2012-08-22 06:26:15 +00:00
|
|
|
unsigned blockCount = currBldrCtx->blockCount();
|
2012-02-17 23:13:45 +00:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2012-08-22 06:26:06 +00:00
|
|
|
DefinedOrUnknownSVal symVal = svalBuilder.conjureSymbolVal(0, CNE, LCtx,
|
|
|
|
CNE->getType(),
|
|
|
|
blockCount);
|
2012-06-20 01:32:01 +00:00
|
|
|
ProgramStateRef State = Pred->getState();
|
2011-03-31 04:04:48 +00:00
|
|
|
|
2012-07-30 20:22:09 +00:00
|
|
|
CallEventManager &CEMgr = getStateManager().getCallEventManager();
|
|
|
|
CallEventRef<CXXAllocatorCall> Call =
|
|
|
|
CEMgr.getCXXAllocatorCall(CNE, State, LCtx);
|
|
|
|
|
2012-07-02 22:21:47 +00:00
|
|
|
// Invalidate placement args.
|
2012-07-30 20:22:09 +00: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-02 22:21:47 +00:00
|
|
|
|
2012-10-20 02:32:51 +00: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 04:04:48 +00:00
|
|
|
if (CNE->isArray()) {
|
|
|
|
// FIXME: allocating an array requires simulating the constructors.
|
|
|
|
// For now, just return a symbolicated region.
|
2013-02-20 05:52:05 +00:00
|
|
|
const MemRegion *NewReg = symVal.castAs<loc::MemRegionVal>().getRegion();
|
2012-07-02 22:21:47 +00:00
|
|
|
QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType();
|
|
|
|
const ElementRegion *EleReg =
|
|
|
|
getStoreManager().GetElementZeroRegion(NewReg, ObjTy);
|
2012-06-20 01:32:01 +00:00
|
|
|
State = State->BindExpr(CNE, Pred->getLocationContext(),
|
2012-01-06 22:09:28 +00:00
|
|
|
loc::MemRegionVal(EleReg));
|
2012-06-20 01:32:01 +00:00
|
|
|
Bldr.generateNode(CNE, Pred, State);
|
2011-03-31 04:04:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-04-19 12:51:02 +00:00
|
|
|
|
2012-07-02 22:21:47 +00: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 01:32:01 +00: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 01:24:38 +00:00
|
|
|
SVal Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(),
|
|
|
|
CNE->getPlacementArg(0)->getType());
|
|
|
|
State = State->BindExpr(CNE, LCtx, Result);
|
2012-07-02 22:21:47 +00:00
|
|
|
} else {
|
|
|
|
State = State->BindExpr(CNE, LCtx, symVal);
|
2012-06-20 01:32:01 +00:00
|
|
|
}
|
|
|
|
|
2013-03-27 18:10:35 +00:00
|
|
|
Bldr.generateNode(CNE, Pred, State);
|
|
|
|
|
2012-07-16 23:38:09 +00: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)) {
|
2013-03-27 18:10:35 +00:00
|
|
|
assert(Bldr.getResults().size() == 1);
|
|
|
|
ExplodedNode *TmpN = *Bldr.getResults().begin();
|
|
|
|
Bldr.takeNodes(TmpN);
|
|
|
|
|
|
|
|
assert(!CNE->getType()->getPointeeCXXRecordDecl());
|
|
|
|
|
2012-07-16 23:38:09 +00:00
|
|
|
SVal Location = State->getSVal(CNE, LCtx);
|
2013-03-27 18:10:35 +00:00
|
|
|
bool FirstInit = (Location == symVal);
|
|
|
|
evalBind(Dst, CNE, TmpN, Location, State->getSVal(Init, LCtx), FirstInit);
|
2012-07-16 23:38:09 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-19 12:51:02 +00:00
|
|
|
}
|
|
|
|
|
2010-12-22 18:53:44 +00:00
|
|
|
void ExprEngine::VisitCXXDeleteExpr(const CXXDeleteExpr *CDE,
|
2011-10-24 18:26:19 +00:00
|
|
|
ExplodedNode *Pred, ExplodedNodeSet &Dst) {
|
2012-08-22 06:26:15 +00:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2012-02-29 08:42:57 +00:00
|
|
|
ProgramStateRef state = Pred->getState();
|
|
|
|
Bldr.generateNode(CDE, Pred, state);
|
2010-04-21 02:17:31 +00:00
|
|
|
}
|
2010-04-19 12:51:02 +00:00
|
|
|
|
2012-03-10 01:34:17 +00:00
|
|
|
void ExprEngine::VisitCXXCatchStmt(const CXXCatchStmt *CS,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
|
|
|
const VarDecl *VD = CS->getExceptionDecl();
|
2012-03-16 05:58:15 +00:00
|
|
|
if (!VD) {
|
|
|
|
Dst.Add(Pred);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-10 01:34:17 +00:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2012-08-22 06:26:06 +00:00
|
|
|
SVal V = svalBuilder.conjureSymbolVal(CS, LCtx, VD->getType(),
|
2012-08-22 06:26:15 +00:00
|
|
|
currBldrCtx->blockCount());
|
2012-03-10 01:34:17 +00:00
|
|
|
ProgramStateRef state = Pred->getState();
|
|
|
|
state = state->bindLoc(state->getLValue(VD, LCtx), V);
|
|
|
|
|
2012-08-22 06:26:15 +00:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2012-03-10 01:34:17 +00:00
|
|
|
Bldr.generateNode(CS, Pred, state);
|
|
|
|
}
|
|
|
|
|
2010-12-22 18:53:44 +00:00
|
|
|
void ExprEngine::VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred,
|
2010-04-21 02:17:31 +00:00
|
|
|
ExplodedNodeSet &Dst) {
|
2012-08-22 06:26:15 +00:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2011-10-24 18:26:19 +00:00
|
|
|
|
2010-04-19 12:51:02 +00:00
|
|
|
// Get the this object region from StoreManager.
|
2012-01-06 22:09:28 +00:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2010-04-19 12:51:02 +00:00
|
|
|
const MemRegion *R =
|
2010-12-02 07:49:45 +00:00
|
|
|
svalBuilder.getRegionManager().getCXXThisRegion(
|
2010-04-19 12:51:02 +00:00
|
|
|
getContext().getCanonicalType(TE->getType()),
|
2012-01-06 22:09:28 +00:00
|
|
|
LCtx);
|
2010-04-19 12:51:02 +00:00
|
|
|
|
2012-01-26 21:29:00 +00:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2010-04-19 12:51:02 +00:00
|
|
|
SVal V = state->getSVal(loc::MemRegionVal(R));
|
2012-01-06 22:09:28 +00:00
|
|
|
Bldr.generateNode(TE, Pred, state->BindExpr(TE, LCtx, V));
|
2010-04-19 12:51:02 +00:00
|
|
|
}
|