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

Commit e6f2bf8

Browse files
committed
[analyzer] Handle caching out while evaluating a C++ new expression.
Evaluating a C++ new expression now includes generating an intermediate ExplodedNode, and this node could very well represent a previously- reachable state in the ExplodedGraph. If so, we can short-circuit the rest of the evaluation. Caught by the assertion a few lines later. <rdar://problem/13510065> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178401 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 75f8bd0 commit e6f2bf8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Diff for: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,16 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
351351
State = State->BindExpr(CNE, LCtx, symVal);
352352
}
353353

354-
Bldr.generateNode(CNE, Pred, State);
354+
ExplodedNode *NewN = Bldr.generateNode(CNE, Pred, State);
355+
if (!NewN)
356+
return;
355357

356358
// If the type is not a record, we won't have a CXXConstructExpr as an
357359
// initializer. Copy the value over.
358360
if (const Expr *Init = CNE->getInitializer()) {
359361
if (!isa<CXXConstructExpr>(Init)) {
360362
assert(Bldr.getResults().size() == 1);
361-
ExplodedNode *TmpN = *Bldr.getResults().begin();
362-
Bldr.takeNodes(TmpN);
363+
Bldr.takeNodes(NewN);
363364

364365
assert(!CNE->getType()->getPointeeCXXRecordDecl());
365366

Diff for: test/Analysis/new.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ void testNewInvalidationScalarPlacement(int **p) {
9494
new (p) (int *)(static_cast<int *>(malloc(4))); // no-warning
9595
}
9696

97+
void testCacheOut(PtrWrapper w) {
98+
extern bool coin();
99+
if (coin())
100+
w.x = 0;
101+
new (&w.x) (int*)(0); // we cache out here; don't crash
102+
}
103+
104+
97105
//--------------------------------------------------------------------
98106
// Check for intersection with other checkers from MallocChecker.cpp
99107
// bounded with unix.Malloc

0 commit comments

Comments
 (0)