Author: DonĂ¡t Nagy Date: 2026-09-01T16:15:43+02:00 New Revision: 9e25ecd7dbb06d0af6faa461af033c5ca3ecc590
URL: https://github.com/llvm/llvm-project/commit/9e25ecd7dbb06d0af6faa461af033c5ca3ecc590 DIFF: https://github.com/llvm/llvm-project/commit/9e25ecd7dbb06d0af6faa461af033c5ca3ecc590.diff LOG: [analyzer] Use makeNode instead of ExplodedGraph::getNode (#218462) The method `CoreEngine::makeNode` is the canonical way of creating a new node in the exploded graph and connecting it to its predecessor. Apply it in two locations that previously duplicated its logic. Note that `ExplodedGraph::getNode` always returns a non-null `ExplodedNode *` (that points to either an old node or the freshly created node); `inlineCall` had no reason to check whether it returns a nullpointer. This change is very close to being NFC, but could technically change the behavior if the state is `PosteriorlyOverconstrained` (which is vanishingly rare). Added: Modified: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 530fae9ee2dee..f0f7d78fc5d50 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -2377,6 +2377,9 @@ bool ExprEngine::replayWithoutInlining(ExplodedNode *N, ExplodedNode *NewNode = G.getNode(NewNodeLoc, NewNodeState, false, &IsNew); // We cached out at this point. Caching out is common due to us backtracking // from the inlined function, which might spawn several paths. + // NOTE: We must return before the `addPredecessor()` call, otherwise the + // node vectors `NewNode->Preds` and `BeforeProcessingCall->Succs` would + // end up containing multiple copies of `BeforeProcessingCall` / `NewNode`. if (!IsNew) return true; diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp index 66fdb6d117a96..511bb036c5b68 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp @@ -53,14 +53,10 @@ void ExprEngine::processCallEnter(CallEnter CE, ExplodedNode *Pred) { // Construct an edge representing the starting location in the callee. BlockEdge Loc(Entry, Succ, CE.getCalleeStackFrame()); - ProgramStateRef state = Pred->getState(); - // Construct a new node, notify checkers that analysis of the function has // begun, and add the resultant nodes to the worklist. - bool isNew; - ExplodedNode *Node = G.getNode(Loc, state, false, &isNew); - Node->addPredecessor(Pred, G); - if (isNew) { + ExplodedNode *Node = Engine.makeNode(Loc, Pred->getState(), Pred); + if (Node) { // FIXME: In the `processBeginOfFunction` callback // `ExprEngine::getCurrStackFrame()` can be diff erent from the // `StackFrame` queried from e.g. the `ExplodedNode`s. I'm not @@ -545,12 +541,8 @@ void ExprEngine::inlineCall(WorkList *WList, const CallEvent &Call, // formal arguments. State = State->enterStackFrame(Call, CalleeSF); - bool isNew; - if (ExplodedNode *N = G.getNode(Loc, State, false, &isNew)) { - N->addPredecessor(Pred, G); - if (isNew) - WList->enqueue(N); - } + if (ExplodedNode *N = Engine.makeNode(Loc, State, Pred)) + WList->enqueue(N); NumInlinedCalls++; Engine.FunctionSummaries->bumpNumTimesInlined(D); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
