Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 76f7761

Browse files
committed
[analyzer] Restructure ExprEngine::VisitCXXNewExpr to do a bit less work.
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178402 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e6f2bf8 commit 76f7761

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
274274
// Also, we need to decide how allocators actually work -- they're not
275275
// really part of the CXXNewExpr because they happen BEFORE the
276276
// CXXConstructExpr subexpression. See PR12014 for some discussion.
277-
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
278277

279278
unsigned blockCount = currBldrCtx->blockCount();
280279
const LocationContext *LCtx = Pred->getLocationContext();
@@ -312,6 +311,8 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
312311
// FIXME: Once we figure out how we want allocators to work,
313312
// we should be using the usual pre-/(default-)eval-/post-call checks here.
314313
State = Call->invalidateRegions(blockCount);
314+
if (!State)
315+
return;
315316

316317
// If we're compiling with exceptions enabled, and this allocation function
317318
// is not declared as non-throwing, failures /must/ be signalled by
@@ -324,6 +325,8 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
324325
State = State->assume(symVal, true);
325326
}
326327

328+
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
329+
327330
if (CNE->isArray()) {
328331
// FIXME: allocating an array requires simulating the constructors.
329332
// For now, just return a symbolicated region.
@@ -341,16 +344,16 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
341344
// CXXNewExpr, we need to make sure that the constructed object is not
342345
// immediately invalidated here. (The placement call should happen before
343346
// the constructor call anyway.)
347+
SVal Result = symVal;
344348
if (FD && FD->isReservedGlobalPlacementOperator()) {
345349
// Non-array placement new should always return the placement location.
346350
SVal PlacementLoc = State->getSVal(CNE->getPlacementArg(0), LCtx);
347-
SVal Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(),
348-
CNE->getPlacementArg(0)->getType());
349-
State = State->BindExpr(CNE, LCtx, Result);
350-
} else {
351-
State = State->BindExpr(CNE, LCtx, symVal);
351+
Result = svalBuilder.evalCast(PlacementLoc, CNE->getType(),
352+
CNE->getPlacementArg(0)->getType());
352353
}
353354

355+
// Bind the address of the object, then check to see if we cached out.
356+
State = State->BindExpr(CNE, LCtx, Result);
354357
ExplodedNode *NewN = Bldr.generateNode(CNE, Pred, State);
355358
if (!NewN)
356359
return;
@@ -363,10 +366,8 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
363366
Bldr.takeNodes(NewN);
364367

365368
assert(!CNE->getType()->getPointeeCXXRecordDecl());
366-
367-
SVal Location = State->getSVal(CNE, LCtx);
368-
bool FirstInit = (Location == symVal);
369-
evalBind(Dst, CNE, TmpN, Location, State->getSVal(Init, LCtx), FirstInit);
369+
evalBind(Dst, CNE, NewN, Result, State->getSVal(Init, LCtx),
370+
/*FirstInit=*/IsStandardGlobalOpNewFunction);
370371
}
371372
}
372373
}

0 commit comments

Comments
 (0)