[clang] 98413f4 - [NFC][analyzer] Replace `CheckerContext::generateSink` with `addSink` (#234351)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 26 03:50:33 PDT 2026
Author: Donát Nagy
Date: 2026-10-26T11:50:28+01:00
New Revision: 98413f4192e3497f51ca52f4d8c267fd44d90dd5
URL: https://github.com/llvm/llvm-project/commit/98413f4192e3497f51ca52f4d8c267fd44d90dd5
DIFF: https://github.com/llvm/llvm-project/commit/98413f4192e3497f51ca52f4d8c267fd44d90dd5.diff
LOG: [NFC][analyzer] Replace `CheckerContext::generateSink` with `addSink` (#234351)
This change generalizes `addSink` to match the signature and behavior of
`generateSink` (but with comfortable default values for all three
parameters), then replaces use of `generateSink` with `addSink` and
deletes `generateSink`. Textually replacing `generateSink` with
`addSink` is a correct way to update downstream checkers; but it is
often possible to remove arguments that were mandatory for
`generateSink` but match the defaults of `addSink`.
This change was motivated by the fact that `CheckerContext` had three
sink-making methods (`generateSink`, `addSink` and `generateErrorNode`)
which all do the same thing and cause lots of confusion with their
separate existence. They all had their advantages and drawbacks:
- `generateErrorNode` is the most widespread (85 uses in checkers), but
it cannot be THE sink-making function, because the name is not suitable
for the dozens of cases where the sink is not used for an "error" (bug
report). It also creates the unfortunate illusion that "error nodes" are
somehow different from regular nodes.
- `generateSink` was the least common (14 uses in checkers), its
parametrization was awkward (not enough defaults) and its name was
misleading when it was contrasted with `addTransition`: some developers
thought that it just _generates_ a sink node and a separate
`addTransition` call is needed to add it to the exploded graph.
- `addSink` had 24 uses in checkers (before this change) and had a very
limited signature (only took a `State`, did not return the new sink
node) but its name is a fitting counterpart for `addTransition`, so I
selected it as the method that I want to keep.
None of the upstream checkers passes an explicit `Tag` to any
sink-making method (of `CheckerContext`), and only two call sites (in
`RetainCountChecker` and in `StdLibraryFunctionsChecker`) pass a
non-default `Pred` node – but I still decided to support these
parameters in `addSink` for the sake of completeness.
As `generateErrorNode` is more widespread, I intend to remove it in a
separate follow-up change.
Added:
Modified:
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
clang/www/analyzer/checker_dev_manual.html
Removed:
################################################################################
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
index e6b62ac2fba6b5..be2a6350ed14b5 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -229,49 +229,43 @@ class CheckerContext {
}
/// Creates a new ExplodedNode which is marked as a sink and adds it to the
- /// ExplodedGraph as a child of the parameter \p Pred. A sink node terminates
- /// the execution path: it cannot have children and prevents the default
- /// behavior that the path "passes through" the checker callback without
- /// changes if the checker doesn't create any node.
+ /// ExplodedGraph.
+ /// A sink node terminates the execution path: it cannot have children and
+ /// prevents the default behavior that the path "passes through" the checker
+ /// callback without changes if the checker doesn't create any node.
/// Can return nullptr if the node creation fails (when it would recreate
/// an existing node or when the state is posteriorly overconstrained).
///
- /// @param State The state of the generated sink node.
- /// @param Pred The node that will become the predecessor of the new node.
- /// @param Tag A ProgramPointTag that will be attached to the node. This is
- /// doesn't have any compelling use case, but could perhaps be used
- /// debugging purposes. When \p Tag is nullptr, node creation will
- /// default to using the active checker as the tag.
- ExplodedNode *generateSink(ProgramStateRef State, ExplodedNode *Pred,
- const ProgramPointTag *Tag = nullptr) {
+ /// @param State The state of the generated sink node; nullptr (the default)
+ /// means keeping the state of the parent node.
+ /// @param Pred The node that will become the predecessor of the new node;
+ /// nullptr (the default) means the node that was passed to the
+ /// constructor of CheckerContext.
+ /// @param Tag A ProgramPointTag that will be attached to the node; nullptr
+ /// (the default) means using the active checker as the tag. Using
+ /// another tag has no compelling use case (apart from debugging).
+ ExplodedNode *addSink(ProgramStateRef State = nullptr,
+ ExplodedNode *Pred = nullptr,
+ const ProgramPointTag *Tag = nullptr) {
return addTransitionImpl(State, true, Pred, Tag);
}
- /// Calls generateSink, passing getPredecessor() (i.e. as the node that was
- /// passed to the constructor of CheckerContext) to its 'Pred' argument and
- /// not returning its result.
- ///
- /// FIXME: This should be unified with generateSink().
- void addSink(ProgramStateRef State = nullptr) {
- generateSink(State, getPredecessor());
- }
-
- /// Calls generateSink, passing getPredecessor() (i.e. as the node that was
+ /// Calls addSink, passing getPredecessor() (i.e. as the node that was
/// passed to the constructor of CheckerContext) to its 'Pred' argument.
///
- /// FIXME: This should be unified with generateSink().
+ /// FIXME: This should be unified with addSink().
ExplodedNode *generateErrorNode(ProgramStateRef State = nullptr,
const ProgramPointTag *Tag = nullptr) {
- return generateSink(State, getPredecessor(), Tag);
+ return addSink(State, getPredecessor(), Tag);
}
- /// Calls generateSink, forwarding all argument without any
diff erence.
+ /// Calls addSink, forwarding all argument without any
diff erence.
///
- /// FIXME: This should be unified with generateSink().
+ /// FIXME: This should be unified with addSink().
ExplodedNode *generateErrorNode(ProgramStateRef State,
ExplodedNode *Pred,
const ProgramPointTag *Tag = nullptr) {
- return generateSink(State, Pred, Tag);
+ return addSink(State, Pred, Tag);
}
/// Creates a new ExplodedNode and adds it to the ExplodedGraph as a child of
diff --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index 13e40b79df0e0b..6b2e02c41ea96f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -144,7 +144,7 @@ void NilArgChecker::warnIfNilExpr(const Expr *E,
// If it might be null, assume that it cannot after this operation.
if (Null) {
// One needs to make sure the pointer is non-null to be used here.
- if (ExplodedNode *N = C.generateSink(Null, C.getPredecessor())) {
+ if (ExplodedNode *N = C.addSink(Null)) {
dispatchEvent({*Location, /*IsLoad=*/false, N, &C.getBugReporter(),
/*IsDirectDereference=*/false});
}
@@ -977,7 +977,7 @@ void ObjCLoopChecker::checkPostStmt(const ObjCForCollectionStmt *FCS,
}
if (!State)
- C.generateSink(C.getState(), C.getPredecessor());
+ C.addSink();
else if (State != C.getState())
C.addTransition(State);
}
diff --git a/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
index 0f67ac5a6ff934..2b774435ab552f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
@@ -239,7 +239,7 @@ static void addCastTransition(const CallEvent &Call, DefinedOrUnknownSVal DV,
// Check for infeasible casts.
if (isInfeasibleCast(CastInfo, CastSucceeds)) {
- C.generateSink(State, C.getPredecessor());
+ C.addSink(State);
return;
}
@@ -321,7 +321,7 @@ static void addInstanceOfTransition(const CallEvent &Call,
if (IsKnownCast)
return;
} else if (CastInfo && CastInfo->succeeds()) {
- C.generateSink(NewState, C.getPredecessor());
+ C.addSink(NewState);
return;
}
}
@@ -437,7 +437,7 @@ void CastValueChecker::evalIsa(const CallEvent &Call, DefinedOrUnknownSVal DV,
}
if (NullState) {
- C.generateSink(NullState, C.getPredecessor());
+ C.addSink(NullState);
}
}
diff --git a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
index 979d12f1e967c7..2a956af0ceb138 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
@@ -303,7 +303,7 @@ void DereferenceChecker::checkLocation(SVal l, bool isLoad, const Stmt* S,
// Otherwise, we have the case where the location could either be
// null or not-null. Record the error node as an "implicit" null
// dereference.
- if (ExplodedNode *N = C.generateSink(nullState, C.getPredecessor())) {
+ if (ExplodedNode *N = C.addSink(nullState)) {
ImplicitNullDerefEvent event = {l, isLoad, N, &C.getBugReporter(),
/*IsDirectDereference=*/true};
dispatchEvent(event);
@@ -358,7 +358,7 @@ void DereferenceChecker::checkBind(SVal L, SVal V, const Stmt *S,
// At this point the value could be either null or non-null.
// Record this as an "implicit" null dereference.
- if (ExplodedNode *N = C.generateSink(StNull, C.getPredecessor())) {
+ if (ExplodedNode *N = C.addSink(StNull)) {
ImplicitNullDerefEvent event = {V, /*isLoad=*/true, N,
&C.getBugReporter(),
/*IsDirectDereference=*/true};
diff --git a/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
index 9f84f0a962e762..bb3920bd17762d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
@@ -516,7 +516,7 @@ void IteratorModeling::processComparison(CheckerContext &C,
(TruthVal->getValue()->getBoolValue())))) {
C.addTransition(State);
} else {
- C.generateSink(State, C.getPredecessor());
+ C.addSink(State);
}
return;
}
diff --git a/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
index 9c616a2d177834..3e6a19cca5aa96 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
@@ -386,7 +386,7 @@ void MoveChecker::modelUse(ProgramStateRef State, const MemRegion *Region,
// And still finalize changes made by the caller.
if (isAnyBaseRegionReported(State, Region)) {
if (misuseCausesCrash(MK)) {
- C.generateSink(State, C.getPredecessor());
+ C.addSink(State);
} else {
C.addTransition(State);
}
diff --git a/clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp
index 17c3cb4e9e04c1..909a4f49ad714b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/NoReturnFunctionChecker.cpp
@@ -83,7 +83,7 @@ void NoReturnFunctionChecker::checkPostCall(const CallEvent &CE,
}
if (BuildSinks)
- C.generateSink(C.getState(), C.getPredecessor());
+ C.addSink();
}
void NoReturnFunctionChecker::checkPostObjCMessage(const ObjCMethodCall &Msg,
@@ -92,7 +92,7 @@ void NoReturnFunctionChecker::checkPostObjCMessage(const ObjCMethodCall &Msg,
if (const ObjCMethodDecl *MD = Msg.getDecl()) {
MD = MD->getCanonicalDecl();
if (MD->hasAttr<AnalyzerNoReturnAttr>()) {
- C.generateSink(C.getState(), C.getPredecessor());
+ C.addSink();
return;
}
}
@@ -138,7 +138,7 @@ void NoReturnFunctionChecker::checkPostObjCMessage(const ObjCMethodCall &Msg,
}
// If we got here, it's one of the messages we care about.
- C.generateSink(C.getState(), C.getPredecessor());
+ C.addSink();
}
void ento::registerNoReturnFunctionChecker(CheckerManager &mgr) {
diff --git a/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
index 2cc633fa5649f9..b415490bc1d2f5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
@@ -198,7 +198,7 @@ void NonNullParamChecker::checkPreCall(const CallEvent &Call,
}
if (stateNull) {
- if (ExplodedNode *N = C.generateSink(stateNull, C.getPredecessor())) {
+ if (ExplodedNode *N = C.addSink(stateNull)) {
ImplicitNullDerefEvent event = {
V, false, N, &C.getBugReporter(),
/*IsDirectDereference=*/HasRefTypeParam};
diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
index 1ebf4787da67c0..df93183702e745 100644
--- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
@@ -1257,7 +1257,7 @@ ProgramStateRef RetainCountChecker::handleAutoreleaseCounts(
V = V ^ RefVal::ErrorOverAutorelease;
state = setRefBinding(state, Sym, V);
- ExplodedNode *N = Ctx.generateSink(state, Pred);
+ ExplodedNode *N = Ctx.addSink(state, Pred);
if (N) {
SmallString<128> sbuf;
llvm::raw_svector_ostream os(sbuf);
diff --git a/clang/www/analyzer/checker_dev_manual.html b/clang/www/analyzer/checker_dev_manual.html
index 21fd96480bf354..a5cc63af802311 100644
--- a/clang/www/analyzer/checker_dev_manual.html
+++ b/clang/www/analyzer/checker_dev_manual.html
@@ -509,8 +509,8 @@ <h2 id=bugs>Bug Reports</h2>
<p>If analysis can not continue, then the current state should be transitioned
into a so-called <i>sink node</i>, a node from which no further analysis will be
performed. This is done by calling the <a
-href="https://clang.llvm.org/doxygen/classclang_1_1ento_1_1CheckerContext.html#a249245cdf2384738921f134c8d7d909a">
-CheckerContext::generateSink</a> function; this function is the same as the
+href="https://clang.llvm.org/doxygen/classclang_1_1ento_1_1CheckerContext.html#ab85fa7cc6b81e482f2565ff4cdb0a728">
+CheckerContext::addSink</a> function; this function is the same as the
<tt>addTransition</tt> function, but marks the state as a sink node. Like
<tt>addTransition</tt>, this returns an <tt>ExplodedNode</tt> with the updated
state, which can then be passed to the <tt>BugReport</tt> constructor.
@@ -714,7 +714,7 @@ <h2 id=links>Making Your Checker Better</h2>
call was modeled, eg. <tt>SymbolConjured::getStmt</tt> is nullable.</li>
<li><tt>CallEvent::getDecl</tt> is nullable - for example, it returns null for a
call of symbolic function pointer.</li>
- <li><tt>addTransition</tt>, <tt>generateSink</tt>, <tt>generateNonFatalErrorNode</tt>,
+ <li><tt>addTransition</tt>, <tt>addSink</tt>, <tt>generateNonFatalErrorNode</tt>,
<tt>generateErrorNode</tt> are nullable because you can transition to a node that you have already visited.</li>
<li>Methods of <tt>CallExpr</tt>/<tt>FunctionDecl</tt>/<tt>CallEvent</tt> that
return arguments crash when the argument is out-of-bounds. If you checked the function name,
More information about the cfe-commits
mailing list