[PATCH] D46823: [analyzer] const init: handle non-explicit cases more accurately

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 14 16:33:27 PDT 2018


NoQ added a comment.

Yay thanks!

I think some cornercases would need to be dealt with.



================
Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1650
+
+            // If there is a list, but no init, it must be zero.
+            if (i >= InitList->getNumInits())
----------------
NoQ wrote:
> Would this work correctly if the element is not of an integral or enumeration type? I think this needs an explicit check.
What if we have an out-of-bounds access to a variable-length array? I don't think it'd yield zero.


================
Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1650-1652
+            // If there is a list, but no init, it must be zero.
+            if (i >= InitList->getNumInits())
+              return svalBuilder.makeZeroVal(R->getElementType());
----------------
Would this work correctly if the element is not of an integral or enumeration type? I think this needs an explicit check.


================
Comment at: lib/StaticAnalyzer/Core/RegionStore.cpp:1733
+          } else {
+            return svalBuilder.makeZeroVal(Ty);
+          }
----------------
Same: would this work correctly if the field is not of an integral or enumeration type?


================
Comment at: test/Analysis/initialization.c:3
+
+void clang_analyzer_dump(int);
 
----------------
We try to avoid using `dump()` on tests because it makes tests test the dump syntax, which isn't the point.

For checking constants, it's easier to do something like `clang_analyzer_eval(parr[i] == 2); // expected-warning{{TRUE}}`.

For finding undefined values, you can enable `core.uninitialized` checkers and receive warnings when the argument of `clang_analyzer_eval` is an uninitialized value. Or just increment the value.


Repository:
  rC Clang

https://reviews.llvm.org/D46823





More information about the cfe-commits mailing list