================
@@ -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:

```suggestion
          Dst.Add(Pred);
```
The methods of 
[`ExplodedNodeSet`](https://clang.llvm.org/doxygen/ExplodedGraph_8h_source.html#l00443)
 have idiosyncratic names: use `Add` to add a single node and `insert` to 
insert all nodes from another `ExplodedNodeSet`.

What you wrote also works, because `ExplodedNodeSet` is implicitly 
constructible from an `ExplodedNode *`, but I think `Add` would be more elegant.

🤔 By the way, perhaps we should clean up the names of the methods of 
ExplodedNodeSet...

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