[PATCH] D111654: [analyzer] Retrieve a value from list initialization of multi-dimensional array declaration.

Denys Petrov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 26 08:10:20 PDT 2021


ASDenysPetrov added inline comments.


================
Comment at: clang/test/Analysis/initialization.cpp:17-23
-int const arr[2][2] = {};
-void arr2init() {
-  int i = 1;
-  // FIXME: Should recognize that it is 0.
-  clang_analyzer_eval(arr[i][0]); // expected-warning{{UNKNOWN}}
-}
-
----------------
steakhal wrote:
> Sorry If I was misunderstood in the previous patches.
> I think, for this instance, the key is that `arr` is `const`, so this TU is supposed to provide this linker symbol, thus any other definitions would violate the ODR.
> So, the `FIXME` is actually accurate, and we should report `0` here.
Right. FALSE expected. And it is fixed with the patch. But this case duplicates some more detailed cases I've added below. So I decide to remove it.


================
Comment at: clang/test/Analysis/initialization.cpp:56
 
-// TODO: Support multidimensional array.
 int const glob_arr4[4][2] = {};
 void glob_array_index2() {
----------------
steakhal wrote:
> Does this work if the ` = {}` is not present?
The compiler (AST) doesn't pass you through without an initializer by emitting a warning. But still there is a case without initializer at the end of the file. Yes, it does work.


================
Comment at: clang/test/Analysis/initialization.cpp:89
+  // FIXME: Should be TRUE
+  clang_analyzer_eval(ptr[0] == 3); // expected-warning{{UNDEFINED}}
+  // FIXME: Should be TRUE
----------------
steakhal wrote:
> Uh, this would be a regression.
> Accessing `Unknown` is not a bug, unlike accessing `Undefined` - which is a clear indication that we must have had UB in the calculation previously, to get this. So, this is slightly similar to llvm poison on that sense.
This is a big problem with casts (in `SValBuilder::evalCast`). I've investigated it. Relates to D89055. IMO the solution will take a separate patch stack. I'm going to fix this next.


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

https://reviews.llvm.org/D111654



More information about the cfe-commits mailing list