[PATCH] D111542: [analyzer] Retrieve incomplete array extent from its redeclaration.

Denys Petrov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 12 09:55:43 PDT 2021


ASDenysPetrov added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1661-1663
     // Check if the containing array has an initialized value that we can trust.
     // We can trust a const value or a value of a global initializer in main().
+    const VarDecl *VD = VR->getDecl()->getMostRecentDecl();
----------------
martong wrote:
> 
Thnx, I'll try this approach.


================
Comment at: clang/test/Analysis/initialization.c:101-102
+
+const int glob_arr3[];              // Incomplete array declaration
+const int glob_arr3[4] = {1, 2, 3}; // Incomplete Array redeclaration
+void foo() {
----------------
martong wrote:
> I'd like to see some more elaborate test cases. Notably
> ```
> const int glob_arr3[];              // Incomplete array declaration
> const int glob_arr3[4] = {1, 2, 3}; // Incomplete Array redeclaration
> const int glob_arr3[];              // Incomplete array redeclaration
> ```
> here neither the canonical nor the most recent decl have the initexpr.
> And I think this is what @balazske tried to point out.
Exactly. I'll add this particular case, but I should mention that **AST** surprisingly shows the third redeclaration as `ConstantArrayType` with the extent. Thus, it works for the current fix.
```
|-VarDecl 0xc0725b0 <line:6:1, col:21> col:11 glob_arr3 'const int []'
|-VarDecl 0xc072700 prev 0xc0725b0 <line:7:1, col:34> col:11 glob_arr3 'const int [4]' cinit
| `-InitListExpr 0xc072830 <col:26, col:34> 'const int [4]'
|   |-array_filler: ImplicitValueInitExpr 0xc0728a8 <<invalid sloc>> 'const int'
|   |-IntegerLiteral 0xc072768 <col:27> 'int' 1
|   |-IntegerLiteral 0xc072788 <col:30> 'int' 2
|   `-IntegerLiteral 0xc0727a8 <col:33> 'int' 3
`-VarDecl 0xc0728e0 prev 0xc072700 <line:8:1, col:21> col:11 glob_arr3 'const int [4]'
```


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

https://reviews.llvm.org/D111542



More information about the cfe-commits mailing list