[clang] [analyzer] Ignoring `T v=v; ` idiom for uninitialized variable checker and dead store checker (PR #187530)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 19 04:44:57 PDT 2026
================
@@ -620,6 +620,21 @@ void ExprEngine::VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred,
return;
}
+ // Self-assignment initialization in variable declaration,
+ // i.e., `int x = x;`,
+ // is a C idiom to suppress warnings of unused variables.
+ // This filter will not match variables of C++ record types, but will match
+ // C++ references. Allow references continuing here to make the undefined
+ // value checker report self-assignments of C++ references.
+ if (const Expr *EI = VD->getInit()) {
+ if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(EI->IgnoreImpCasts()))
+ if (VD == DR->getDecl())
+ if (!VD->getType()->isReferenceType()) {
+ Dst.insert(Pred);
+ return;
+ }
+ }
----------------
steakhal wrote:
I'll resolve this as I already had an open thread about this.
https://github.com/llvm/llvm-project/pull/187530
More information about the cfe-commits
mailing list