[clang] [analyzer] Adjust ExprEngine::VisitDeclStmt to ignore `T v=v;` idiom cases for C code (PR #187530)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 20 09:46:32 PDT 2026
steakhal wrote:
To me the more interesting case is if we have side-effects in the constructor. https://godbolt.org/z/jPEa4sfeM
The compiler is allowed to elide everything that doesn't violate the as-if rule.
Consequently, both GCC and clang are right, and it doesn't matter if we emit or not emit reads from the freshly declaerd variable while its getting initialized. So we may as well also just elide it.
To me, it doesn't matter if it's C or C++. What matters is if it has side-effect or not.
That said, we can just take the constructor decl and check if it's trivial. If so, we can elide; otherwise we can't.
https://github.com/llvm/llvm-project/pull/187530
More information about the cfe-commits
mailing list