@@ -274,7 +274,6 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
274
274
// Also, we need to decide how allocators actually work -- they're not
275
275
// really part of the CXXNewExpr because they happen BEFORE the
276
276
// CXXConstructExpr subexpression. See PR12014 for some discussion.
277
- StmtNodeBuilder Bldr (Pred, Dst, *currBldrCtx);
278
277
279
278
unsigned blockCount = currBldrCtx->blockCount ();
280
279
const LocationContext *LCtx = Pred->getLocationContext ();
@@ -312,6 +311,8 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
312
311
// FIXME: Once we figure out how we want allocators to work,
313
312
// we should be using the usual pre-/(default-)eval-/post-call checks here.
314
313
State = Call->invalidateRegions (blockCount);
314
+ if (!State)
315
+ return ;
315
316
316
317
// If we're compiling with exceptions enabled, and this allocation function
317
318
// is not declared as non-throwing, failures /must/ be signalled by
@@ -324,6 +325,8 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
324
325
State = State->assume (symVal, true );
325
326
}
326
327
328
+ StmtNodeBuilder Bldr (Pred, Dst, *currBldrCtx);
329
+
327
330
if (CNE->isArray ()) {
328
331
// FIXME: allocating an array requires simulating the constructors.
329
332
// For now, just return a symbolicated region.
@@ -341,16 +344,16 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
341
344
// CXXNewExpr, we need to make sure that the constructed object is not
342
345
// immediately invalidated here. (The placement call should happen before
343
346
// the constructor call anyway.)
347
+ SVal Result = symVal;
344
348
if (FD && FD->isReservedGlobalPlacementOperator ()) {
345
349
// Non-array placement new should always return the placement location.
346
350
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 ());
352
353
}
353
354
355
+ // Bind the address of the object, then check to see if we cached out.
356
+ State = State->BindExpr (CNE, LCtx, Result);
354
357
ExplodedNode *NewN = Bldr.generateNode (CNE, Pred, State);
355
358
if (!NewN)
356
359
return ;
@@ -363,10 +366,8 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
363
366
Bldr.takeNodes (NewN);
364
367
365
368
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);
370
371
}
371
372
}
372
373
}
0 commit comments