[PATCH] D135920: [clang][Sema] Use correct array size for diagnostic

Kees Cook via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 17 12:35:39 PDT 2022


kees added inline comments.


================
Comment at: clang/test/SemaCXX/array-bounds.cpp:240
 
-    ((char*)foo)[sizeof(foo)] = '\0';  // expected-warning {{array index 32768 is past the end of the array (which contains 32768 elements)}}
+    ((char*)foo)[sizeof(foo)] = '\0';  // expected-warning {{array index 32768 is past the end of the array (which contains 4096 elements)}}
 
----------------
serge-sans-paille wrote:
> I find this new message quite confusing, because the array index is given in terms of char elements, while the array size is given in terms of double elements. I actually find the original message more consistent to that respect.
Perhaps show both element count and byte offset?

`array index $count is $(bytes - end_of_array_in_bytes) past the end of the array (which contains $end_of_array_in_bytes bytes of $array_max_index elements)`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135920



More information about the cfe-commits mailing list