================
@@ -624,6 +624,26 @@ 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, although Clang will.
+  // We therefore ignore all types for C code.
+  // For C++ code, Sema will not report for fundamental types and pointers.
+  // We hence also ignore them as in C, but leave the uninitialized variable
+  // report of references to the checker. For record types, as their AST
+  // structures are different in C++, they will not hit the filter here and
+  // will be checked by the checker.
+  if (const Expr *EI = VD->getInit())
+    if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(EI->IgnoreImpCasts()))
+      if (VD == DR->getDecl())
+        if (getContext().getLangOpts().getCLangStd() ||
----------------
steakhal wrote:

I don't think it's easy to automatically do this. It's a matter of taste. There 
was recently a thread about something similar:
https://discourse.llvm.org/t/rfc-clarify-brace-omission-for-wrapped-single-statement-bodies/90739

However, that discussion I think went a bit sideways, and I disagree with where 
it was going. I've expressed my subjective opinion there if you are interested.

https://github.com/llvm/llvm-project/pull/187530
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to