r178402 - [analyzer] Restructure ExprEngine::VisitCXXNewExpr to do a bit less work.
Jordan Rose
jordan_rose at apple.com
Fri Mar 29 18:31:48 PDT 2013
Author: jrose
Date: Fri Mar 29 20:31:48 2013
New Revision: 178402
URL: http://llvm.org/viewvc/llvm-project?rev=178402&view=rev
Log:
[analyzer] Restructure ExprEngine::VisitCXXNewExpr to do a bit less work.
No functionality change.
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=178402&r1=178401&r2=178402&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp Fri Mar 29 20:31:48 2013
@@ -274,7 +274,6 @@ void ExprEngine::VisitCXXNewExpr(const C
// 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.
- StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
unsigned blockCount = currBldrCtx->blockCount();
const LocationContext *LCtx = Pred->getLocationContext();
@@ -312,6 +311,8 @@ void ExprEngine::VisitCXXNewExpr(const C
// 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);
+ if (!State)
+ return;
// If we're compiling with exceptions enabled, and this allocation function
// is not declared as non-throwing, failures /must/ be signalled by
@@ -324,6 +325,8 @@ void ExprEngine::VisitCXXNewExpr(const C
State = State->assume(symVal, true);
}
+ StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
+
if (CNE->isArray()) {
// FIXME: allocating an array requires simulating the constructors.
// For now, just return a symbolicated region.
@@ -341,16 +344,16 @@ void ExprEngine::VisitCXXNewExpr(const C
// 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.)
+ SVal Result = symVal;
if (FD && FD->isReservedGlobalPlacementOperator()) {
// Non-array placement new should always return the placement location.
SVal PlacementLoc = State->getSVal(CNE->getPlacementArg(0), LCtx);
- SVal Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(),
- CNE->getPlacementArg(0)->getType());
- State = State->BindExpr(CNE, LCtx, Result);
- } else {
- State = State->BindExpr(CNE, LCtx, symVal);
+ Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(),
+ CNE->getPlacementArg(0)->getType());
}
+ // Bind the address of the object, then check to see if we cached out.
+ State = State->BindExpr(CNE, LCtx, Result);
ExplodedNode *NewN = Bldr.generateNode(CNE, Pred, State);
if (!NewN)
return;
@@ -363,10 +366,8 @@ void ExprEngine::VisitCXXNewExpr(const C
Bldr.takeNodes(NewN);
assert(!CNE->getType()->getPointeeCXXRecordDecl());
-
- SVal Location = State->getSVal(CNE, LCtx);
- bool FirstInit = (Location == symVal);
- evalBind(Dst, CNE, TmpN, Location, State->getSVal(Init, LCtx), FirstInit);
+ evalBind(Dst, CNE, NewN, Result, State->getSVal(Init, LCtx),
+ /*FirstInit=*/IsStandardGlobalOpNewFunction);
}
}
}
More information about the cfe-commits
mailing list