[clang] 48d5c3e - [analyzer][NFC] Remove unused ProgramStateRef local variables (#211517)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 23 04:26:21 PDT 2026
Author: Balázs Benics
Date: 2026-07-23T11:26:17Z
New Revision: 48d5c3edb02a950c58a25711f729f3e6a7f3b624
URL: https://github.com/llvm/llvm-project/commit/48d5c3edb02a950c58a25711f729f3e6a7f3b624
DIFF: https://github.com/llvm/llvm-project/commit/48d5c3edb02a950c58a25711f729f3e6a7f3b624.diff
LOG: [analyzer][NFC] Remove unused ProgramStateRef local variables (#211517)
Several checkers and ExprEngine declare a ProgramStateRef local that is
never read (typically `State = C.getState();` immediately followed by
code that re-fetches the state directly). These are not flagged by
-Wunused-variable because ProgramStateRef has a non-trivial destructor.
Found with a clang-query matcher over clang/lib/StaticAnalyzer.
Assisted-by: claude
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
clang/lib/StaticAnalyzer/Checkers/VAListChecker.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index 9081e977a099c..13e40b79df0e0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -424,8 +424,7 @@ static const char* GetCFNumberTypeStr(uint64_t i) {
#endif
void CFNumberChecker::checkPreStmt(const CallExpr *CE,
- CheckerContext &C) const {
- ProgramStateRef state = C.getState();
+ CheckerContext &C) const {
const FunctionDecl *FD = C.getCalleeDecl(CE);
if (!FD)
return;
diff --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
index 8a5c205b6efba..93e3e3ca2322a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -456,8 +456,6 @@ void ExprInspectionChecker::analyzerDenote(const CallExpr *CE,
return;
}
- ProgramStateRef State = C.getState();
-
C.addTransition(C.getState()->set<DenotedSymbols>(Sym, E));
}
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index df911f3ce3d0e..32c767d89dd55 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -3554,7 +3554,6 @@ void MallocChecker::checkEscapeOnReturn(const ReturnStmt *S,
return;
// Check if we are returning a symbol.
- ProgramStateRef State = C.getState();
SVal RetVal = C.getSVal(E);
SymbolRef Sym = RetVal.getAsSymbol();
if (!Sym)
diff --git a/clang/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp
index aaa8a77ae6b18..9df070b98fe66 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp
@@ -242,8 +242,6 @@ SuperDeallocBRVisitor::VisitNode(const ExplodedNode *Succ,
if (Satisfied)
return nullptr;
- ProgramStateRef State = Succ->getState();
-
bool CalledNow =
Succ->getState()->contains<CalledSuperDealloc>(ReceiverSymbol);
bool CalledBefore =
diff --git a/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
index f2fc9219912ad..5d10c9603fd88 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
@@ -168,7 +168,6 @@ void PointerArithChecker::reportPointerArithMisuse(const Expr *E,
if (SR.isInvalid())
return;
- ProgramStateRef State = C.getState();
const MemRegion *Region = C.getSVal(E).getAsRegion();
if (!Region)
return;
diff --git a/clang/lib/StaticAnalyzer/Checkers/VAListChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/VAListChecker.cpp
index c1ac601569dfc..09197a85e439c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/VAListChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/VAListChecker.cpp
@@ -197,7 +197,6 @@ const MemRegion *VAListChecker::getVAListAsRegion(SVal SV, const Expr *E,
void VAListChecker::checkPreStmt(const VAArgExpr *VAA,
CheckerContext &C) const {
- ProgramStateRef State = C.getState();
const Expr *ArgExpr = VAA->getSubExpr();
const MemRegion *VAList = getVAListAsRegion(C.getSVal(ArgExpr), ArgExpr, C);
if (!VAList)
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 678b07ebba1b0..7669b65818272 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2664,7 +2664,6 @@ assumeCondition(const Stmt *ConditionStmt, ExplodedNode *N) {
DefinedSVal V = X.castAs<DefinedSVal>();
- ProgramStateRef StTrue, StFalse;
return State->assume(V);
}
More information about the cfe-commits
mailing list