[clang] [analyzer] Ignoring `T v=v; ` idiom for uninitialized variable checker and dead store checker (PR #187530)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 1 04:21:04 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()))
----------------
AaronBallman wrote:
The kind of situation where this comes up is macro expansions because it's idiomatic to wrap macro arguments in parens. Consider:
```
#define INIT(x) (x)
int v = INIT(v);
```
That ends up expanding to the parenthesized form. I don't think it's the most critical thing to support, but given that it should be low effort, it seems like a nice-to-have.
https://github.com/llvm/llvm-project/pull/187530
More information about the cfe-commits
mailing list