[PATCH] D99262: [analyzer] Fix dead store checker false positive

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 6 14:39:06 PDT 2021


NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Looks great and I'm also curious about nested initializers.



================
Comment at: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp:420-421
+              // We should also allow defensive initialization of structs.
+              if (const auto *ILE =
+                      dyn_cast<InitListExpr>(E->IgnoreParenCasts())) {
+                // We can use exactly the same logic here.
----------------
vsavchenko wrote:
> martong wrote:
> > What about nested InitListExpr's?
> > ```
> > std::array<int, 3> a1{ {1, 2, 3} };
> > ```
> > 
> > ```
> > VarDecl 0x561b200333a0 </home/egbomrt/tmp/aaa.cc:2:1, col:34> col:20 a1 'std::array<int, 3>':'std::array<int, 3>' listinit
> > `-InitListExpr 0x561b20036d78 <col:22, col:34> 'std::array<int, 3>':'std::array<int, 3>'
> >   `-InitListExpr 0x561b20036dc0 <col:24, col:32> 'typename _AT_Type::_Type':'int [3]'
> >     |-IntegerLiteral 0x561b20033408 <col:25> 'int' 1
> >     |-IntegerLiteral 0x561b20033428 <col:28> 'int' 2
> >     `-IntegerLiteral 0x561b20033448 <col:31> 'int' 3
> > ```
> I'm not sure that we'll report anything on that
We probably won't because it's a C++ object, even though it's an aggregate so we should probably warn(?) What about a plain C object like
```lang=c++
int x[2][2] = { { 0, 0 }, { 0, 0 } };
```
?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99262/new/

https://reviews.llvm.org/D99262



More information about the cfe-commits mailing list