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

    <tr>
        <th>Summary</th>
        <td>
            clang aggresively optimized away UBs
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </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, ASan with clang -O2 and above did not produce any warning of the buffer overflow in function a. I understand that optimizers could assume UBs never happen and do whatever they want to optimize the code. But I do concern that such aggressiveness would hinder the effectiveness of sanitizers. A similar issue is discussed in https://github.com/llvm/llvm-project/issues/53972 and current belief is that this should not be an issue.

On this specific case, gcc however tends to be less aggressive than Clang.
https://godbolt.org/z/9MTWeGjzM

```c
int a() {
    int b[7];
    for (int e = 0; e < 8; e++)
        b[e] = 6;
    return b[1];
}
int main() { 
    return a(); 
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylU8tu2zAQ_BrqsrCgSJZtHXTwAyl6CHJoi54paiUxoEmDjwjO13dJOXGaHivoQXK5M7PDVWf6a_toLPgJYTBKmVnqEYTpkZVH2P_gGmbpJxCK0_rquQSue-CdeUXoZQ_aeLhY0weBFLnCzK2OCGZIkF0YBrRAu-1A2CA1DEELL40GnsN3CLpH63wE9RP3YC5enuUbrZGIoIjKuXBG-HVwoJFgYOKXC-okozcwU1JaJrbIrj1484GSNMRicjgET3SUIYwWaPVC54KYgI-jRefkK2r6wJx4JxmVJQCkGkjyLUyVOa6lTyJz2IMjKsUtSFKK9CZfnAjOYR_Lnby_OFbtWflI90hehi4X5kwTpV7fPyvy8IVIaJpgHA3qqtkudotgLVJlHSqJQ6RI4v1EIzclufEcungEi4ycFSdW7Jf3s75tvaCQgxQguEvHOwoBk5kX_1D3LnpHKCrWeXclsmk4xg644X4pyvSdUT43dqTZGz3N08_f-O3l7emzDLYpllssc0kVcVbuWNkA2x6WRaArBjpWH7asPrHqU2CgRqWEGEdg1QkKCqfhEXZpyMpDupt7UrwiGhJaStr8hWnRB-qGuOPhMx_bnu4yz1zqu1L4J_tWRpTwJfuj6Kxvq76pGp556RW2yw-1mEweq-tH01LPz_waOz4LVrX_0UD1ZrvJprartmW5Frty6IRomk3RrEU1iKqpt9WG1jPFqbNcSxaQA5lsy6Isi7pcP5RFVa_zrt9VjXhoqqJAgbsdWxdIjqg8EsdTz2ybNHRhdBRU0nl3D9IfLEeN-I7Pg5-Mbd3EzWoKfKVkliS3Se8f3ptzOA">