[clang] [analyzer] Adjust ExprEngine::VisitDeclStmt to ignore `T v=v;` idiom cases for C code (PR #187530)
Donát Nagy via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 20 09:29:26 PDT 2026
================
@@ -624,6 +624,20 @@ void ExprEngine::VisitDeclStmt(const DeclStmt *DS, ExplodedNode *Pred,
return;
}
+ // Bypass a nop initialization that assign to itself at variable declaration.
+ // I.e., int x = x;
+ // This is an idiom in C code and GCC will not generate any assemblies for
+ // this self initialization, even under -O0, but Clang will.
+ // Since the frontend will warn in C++ code, and it is ill-formed for C++
+ // reference types, the bypass is effected to C code only.
+ if (getContext().getLangOpts().getCLangStd())
+ if (const Expr *EI = VD->getInit())
+ if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(EI->IgnoreImpCasts()))
+ if (VD == DR->getDecl()) {
+ Dst.insert(Pred);
----------------
NagyDonat wrote:
Actually, never mind this suggestion – I thought about this and now I'm leaning towards renaming `ExplodedNodeSet::Add` to `insert`.
https://github.com/llvm/llvm-project/pull/187530
More information about the cfe-commits
mailing list