[llvm-bugs] [Bug 44343] New: -Warray-bounds false negative when casting an out-of-bounds array item

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 19 08:49:50 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=44343

            Bug ID: 44343
           Summary: -Warray-bounds false negative when casting an
                    out-of-bounds array item
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ilya.mirsky at ericsson.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

For the following code in array-bounds.cpp

  unsigned int arr[2] = {0, 1};
  int i1 = arr[4];
  int i2 = (int)(arr[4]);
  int i3 = static_cast<int>(arr[4]);

Clang warns only for `i1`'s assignment. When the array item is casted, no out
of bounds warning is presented.

  $ clang -cc1 -Warray-bounds array-bounds.cpp
  array-bounds.cpp:2:10: warning: array index 4 is past the end of the array 
  (which contains 2 elements)
  int i1 = arr[4];
           ^   ~
  array-bounds.cpp:1:1: note: array 'arr' declared here
  unsigned int arr[2] = {0, 1};
  ^
  1 warning generated.


This is not a duplicate of PR10771, as in the latter the subscript operator is
applied on the casted array, whereas in this case, the subscript operator is
applied first and then casting applied on the result.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191219/07e2c532/attachment-0001.html>


More information about the llvm-bugs mailing list