<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55668>55668</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Static analyzer misses array index out-of-bounds
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          superjamie
      </td>
    </tr>
</table>

<pre>
    Using the Clang 14.0 package in Ubuntu 22.04.

A basic index out-of-bounds, our array has 3 members (`[0]` to `[2]`) but we try to access up to `[5]` with a loop:

```c
int main(void)
{
        int my_array[3] = { 0 };

        for(int i = 0; i < 6; i++)
                my_array[i] = i;

        return 0;
}
```

cppcheck picks up the error correctly:

```
$ cppcheck array-out-of-bounds.c
Checking array-out-of-bounds.c ...
array-out-of-bounds.c:6:11: error: Array 'my_array[3]' accessed at index 5, which is out of bounds. [arrayIndexOutOfBounds]
  my_array[i] = i;
          ^
array-out-of-bounds.c:5:19: note: Assuming that condition 'i<6' is not redundant
 for(int i = 0; i < 6; i++)
                  ^
array-out-of-bounds.c:6:11: note: Array index out of bounds
  my_array[i] = i;
          ^
```

However, `scan-build` reports no problems:

```
$ scan-build gcc array-out-of-bounds.c -std=c99 -o array-out-of-bounds
scan-build: Using '/usr/lib/llvm-14/bin/clang' for static analysis
scan-build: Analysis run complete.
scan-build: Removing directory '/tmp/scan-build-2022-05-24-112127-34339-1' because it contains no reports.
scan-build: No bugs found.
```

The expectation is that it picks up the error like cppcheck did.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVduOmzAQ_RryMgKBgWR54CHJNmpfulIvz5UxJngXMPJlt-nXd2zIZVu6VRsRy-DxzJkzx-NK1qfyqxbDEUzLYd9RnCVZFMNI2RM9chADfK3sYCwQEsVZFMT3Qbydxi1UVAuGNjX_DtKaUDZhJe1Q64Ds8YMCqhQ9QUs1pNDzvuJKQ0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