================
@@ -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() ||
+            (getContext().getLangOpts().getCPlusPlusLangStd() &&
+             !VD->getType()->isReferenceType())) {
----------------
steakhal wrote:

I think the canonical way of check if we are C++ is using the 
`getContext().getLangOpts().CPlusPlus`.
For C it should be the `C99` or maybe the negation of CPlusPlus.

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