Skip to content

Commit 28cbc68

Browse files
authored
[NFC][analyzer] Remove NodeBuilders: part I (llvm#183354)
This commit simplifies some parts of the engine by replacing short-lived `NodeBuilder`s with `CoreEngine::makeNode`. Additionally, the three-argument overload of `CoreEngine::enqueue` is renamed to `enqueueStmtNodes` to highlight that it just calls `enqueueStmtNode` in a loop.
1 parent 4147cd2 commit 28cbc68

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ class CoreEngine {
177177

178178
/// Enqueue nodes that were created as a result of processing
179179
/// a statement onto the work list.
180-
void enqueue(ExplodedNodeSet &Set, const CFGBlock *Block, unsigned Idx);
180+
void enqueueStmtNodes(ExplodedNodeSet &Set, const CFGBlock *Block,
181+
unsigned Idx);
181182

182183
/// enqueue the nodes corresponding to the end of function onto the
183184
/// end of path / work list.

clang/lib/StaticAnalyzer/Core/CoreEngine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,8 @@ void CoreEngine::enqueue(ExplodedNodeSet &Set) {
655655
WList->enqueue(I);
656656
}
657657

658-
void CoreEngine::enqueue(ExplodedNodeSet &Set,
659-
const CFGBlock *Block, unsigned Idx) {
658+
void CoreEngine::enqueueStmtNodes(ExplodedNodeSet &Set, const CFGBlock *Block,
659+
unsigned Idx) {
660660
for (const auto I : Set)
661661
enqueueStmtNode(I, Block, Idx);
662662
}

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,25 +1144,22 @@ void ExprEngine::ProcessStmt(const Stmt *currStmt, ExplodedNode *Pred) {
11441144
}
11451145

11461146
// Enqueue the new nodes onto the work list.
1147-
Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx);
1147+
Engine.enqueueStmtNodes(Dst, currBldrCtx->getBlock(), currStmtIdx);
11481148
}
11491149

11501150
void ExprEngine::ProcessLoopExit(const Stmt* S, ExplodedNode *Pred) {
11511151
PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
11521152
S->getBeginLoc(),
11531153
"Error evaluating end of the loop");
1154-
ExplodedNodeSet Dst;
1155-
Dst.Add(Pred);
1156-
NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
11571154
ProgramStateRef NewState = Pred->getState();
11581155

11591156
if(AMgr.options.ShouldUnrollLoops)
11601157
NewState = processLoopEnd(S, NewState);
11611158

11621159
LoopExit PP(S, Pred->getLocationContext());
1163-
Bldr.generateNode(PP, NewState, Pred);
1164-
// Enqueue the new nodes onto the work list.
1165-
Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx);
1160+
ExplodedNode *N = Engine.makeNode(PP, NewState, Pred);
1161+
if (N && !N->isSink())
1162+
Engine.enqueueStmtNode(N, currBldrCtx->getBlock(), currStmtIdx);
11661163
}
11671164

11681165
void ExprEngine::ProcessInitializer(const CFGInitializer CFGInit,
@@ -1193,9 +1190,8 @@ void ExprEngine::ProcessInitializer(const CFGInitializer CFGInit,
11931190
// The field was directly constructed, so there is no need to bind.
11941191
// But we still need to stop tracking the object under construction.
11951192
State = finishObjectConstruction(State, BMI, LC);
1196-
NodeBuilder Bldr(Pred, Tmp, *currBldrCtx);
11971193
PostStore PS(Init, LC, /*Loc*/ nullptr, /*tag*/ nullptr);
1198-
Bldr.generateNode(PS, State, Pred);
1194+
Tmp.Add(Engine.makeNode(PS, State, Pred));
11991195
} else {
12001196
const ValueDecl *Field;
12011197
if (BMI->isIndirectMemberInitializer()) {
@@ -1247,15 +1243,12 @@ void ExprEngine::ProcessInitializer(const CFGInitializer CFGInit,
12471243
// Construct PostInitializer nodes whether the state changed or not,
12481244
// so that the diagnostics don't get confused.
12491245
PostInitializer PP(BMI, FieldLoc.getAsRegion(), stackFrame);
1250-
ExplodedNodeSet Dst;
1251-
NodeBuilder Bldr(Tmp, Dst, *currBldrCtx);
1252-
for (const auto I : Tmp) {
1253-
ProgramStateRef State = I->getState();
1254-
Bldr.generateNode(PP, State, I);
1255-
}
12561246

1247+
ExplodedNodeSet Dst;
1248+
for (ExplodedNode *Pred : Tmp)
1249+
Dst.Add(Engine.makeNode(PP, Pred->getState(), Pred));
12571250
// Enqueue the new nodes onto the work list.
1258-
Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx);
1251+
Engine.enqueueStmtNodes(Dst, currBldrCtx->getBlock(), currStmtIdx);
12591252
}
12601253

12611254
std::pair<ProgramStateRef, uint64_t>
@@ -1319,7 +1312,7 @@ void ExprEngine::ProcessImplicitDtor(const CFGImplicitDtor D,
13191312
}
13201313

13211314
// Enqueue the new nodes onto the work list.
1322-
Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx);
1315+
Engine.enqueueStmtNodes(Dst, currBldrCtx->getBlock(), currStmtIdx);
13231316
}
13241317

13251318
void ExprEngine::ProcessNewAllocator(const CXXNewExpr *NE,
@@ -1333,13 +1326,12 @@ void ExprEngine::ProcessNewAllocator(const CXXNewExpr *NE,
13331326
if (Opts.MayInlineCXXAllocator)
13341327
VisitCXXNewAllocatorCall(NE, Pred, Dst);
13351328
else {
1336-
NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
13371329
const LocationContext *LCtx = Pred->getLocationContext();
13381330
PostImplicitCall PP(NE->getOperatorNew(), NE->getBeginLoc(), LCtx,
13391331
getCFGElementRef());
1340-
Bldr.generateNode(PP, Pred->getState(), Pred);
1332+
Dst.Add(Engine.makeNode(PP, Pred->getState(), Pred));
13411333
}
1342-
Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx);
1334+
Engine.enqueueStmtNodes(Dst, currBldrCtx->getBlock(), currStmtIdx);
13431335
}
13441336

13451337
void ExprEngine::ProcessAutomaticObjDtor(const CFGAutomaticObjDtor Dtor,

0 commit comments

Comments
 (0)