[PATCH] D46944: [analyzer] Use sufficiently large types for index/size calculation.

Aleksei Sidorin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 23 10:31:12 PDT 2018


a.sidorin added a comment.

Hi Bevin,

Could you please address these comments?



================
Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h:89
         SymMgr(context, BasicVals, alloc), MemMgr(context, alloc),
-        StateMgr(stateMgr), ArrayIndexTy(context.LongLongTy),
+        StateMgr(stateMgr), ArrayIndexTy(context.getSignedSizeType()),
         ArrayIndexWidth(context.getTypeSize(ArrayIndexTy)) {}
----------------
As you correctly pointed, ssize_t is 32-bit on 32-bit systems. Therefore, it is too short. So, we can leave this line as-is.


================
Comment at: test/Analysis/index-type.c:13
   char arr[X86_ARRAY_SIZE];
-  char *ptr = arr + UINT_MAX/2;
+  char *ptr = arr + UINT_MAX/4;
   ptr += 2;  // index shouldn't overflow
----------------
We don't need to fix the test - it is correct. We have to fix the type instead.


================
Comment at: test/Analysis/index-type.c:25
+void testOutOfBounds() {
+  // not out of bounds
+  buf[SIZE-1] = 1; // no-warning
----------------
The comments should be normal sentences: "Not out of bounds."


https://reviews.llvm.org/D46944





More information about the cfe-commits mailing list