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

    <tr>
        <th>Summary</th>
        <td>
            ASan misses a stack-bufferoverflow at -O2 and above (since clang12).
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          shao-hua-li
      </td>
    </tr>
</table>

<pre>
    For the following code, `clang -O2 -fsanitize=address` missed the buffer-overflow in line 4. I checked the assembly code, since the array `a` is volatile, `a[i]=1` would not be optimized aways by the optimizer. So this is probably an Asan issue. This issue only existed since clang12.*.

https://godbolt.org/z/1x4vdshhh
 
```c
int foo(int j) {
  volatile int a[2];
  for (int i = 0; i < j; i++)
        a[i] = 1;
}
int main() {
  foo(3);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxlU01zozAM_TXmooEB8xE4cEia6cye9tD9AzY2wa1jZ2yTNP31K0xCZ7uMSWTJenp-EtyKe_9qHYRJwmi1tjdlTjBYIQl9AdLkg2boSH9TSEfPjArqS5LyyIRw0ns8AGflvRQRgc_jKF1qr9KNCAXKgFZGQpXBLxgmOXw8DjJMOXN93yp5ZQa5hpxj96UyW8CVh6vVLCj9JMRIfVCkPiKJYjlxs7MWYGwALsFegjojQwHsxu4e-D1iPt0ugzeLHkTFdXGWs4UEM7DHu6HPzzKDP2scbbAGw_JT-YCQK8coSEEzQvcZyY8k36-_UwgXT8o9oa-4TlZwq0Nm3Ql3X_gWn9VV-Gma1uPwyG3ydQ3rXpmAfbCEtov1TmgHZHd4pGxSwBJchKBRiC0-YicfqQpQIMgxGM0XxFpMQg9xdc-U9XmKGpOKDZHsjt-0zkwZBP9BaSVbLoj_ZW2XS0Rfiq7sWBJU0LLfv6HacW48MPCBDR_pOjvb6LAQh44ZbCVH73KvfxqAFbNkdrr_IbwK08yzwZ5xo_X1-Zdit9_lEHAbW-vRqOumKZKpb3e7ijajLJuxKnlV1UVFhWhEnldFLeiQaMal9j2KRCg18rZOB9ooWaJ6mlOa17Qs6mJXd1lVtaJuu1yWrWy7eiRVLlE8nS08lolIXB8p8fnkMahxvPx3EL8NdTJSxnKIz-YwWdf7idl0mlmqVRLL95H-X2YfI1E">