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

Aleksei Sidorin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 29 06:51:54 PDT 2018


a.sidorin added a subscriber: NoQ.
a.sidorin added a comment.

There are some results for clang and gcc max value for x86 and x64.
Source code:

  const unsigned long long SIZE_MAX = (unsigned long long)(unsigned long)(-1);
  const unsigned long long size = SIZE_MAX/2;
  char arr[size+1];

Compiler output:

  % g++ -c cast-comp.cpp -m32
  cast-comp.cpp:6:16: error: size of array ‘arr’ is negative
   char arr[size+1];
                  ^
  % clang++-6.0 -c cast-comp.cpp -m32
  % g++ -c cast-comp.cpp -m32        
  cast-comp.cpp:6:16: error: size of array ‘arr’ is negative
   char arr[size+1];
                  ^
  % g++ -c cast-comp.cpp
  cast-comp.cpp:6:16: error: size of array ‘arr’ is negative
   char arr[size+1];
                  ^
  % clang++-6.0 -c cast-comp.cpp
  cast-comp.cpp:6:10: error: array is too large (9223372036854775808 elements)
  char arr[size+1];
           ^~~~~~

So, clang accepts indices > SIZE_MAX/2 for x86.
For `arr[size]`, only clang-x64 fails with error.
I think this means that we need to use LongLongTy as index type, not SizeType. @NoQ, what do you think?


https://reviews.llvm.org/D46944





More information about the cfe-commits mailing list