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

    <tr>
        <th>Summary</th>
        <td>
            UBSan fails to detect an out-of-bound access
        </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-trunk -O0 -fsanitize=undefined` fails to detect the out-of-bound access in line 3. `clang-trunk -O3 -fsanitize=undefined` however succeeds.


```console
$ cat a.c
int a[]; 
int main() {
 if (a[4])
  ;
 return 0;
}
$
$ clang-trunk -O0 -fsanitize=undefined a.c && ./a.out
$
$ clang-trunk -O3 -fsanitize=undefined a.c && ./a.out
a.c:3:6: runtime error: index 4 out of bounds for type 'int[1]'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior a.c:3:6 in 
$
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNUk2PmzAU_DXm8gQC85UcOCSN9raq1FUOPRp4BreOHdkm6fbX90E-drvbbisZ8Bv7jYfxtLZ_bh6sgzAiSKu1PSszQGd7ZPwTsCrttDBDHNxkvkP8OYVYemFUUD-R5bvJ9CiVwZ42ghRKewgWegzYhYXSTiG2Mm4t7QTRdeg9KAOaeiBP3vPnH_CP9owndOAn4sHeJyzdsXTz27tKL6OzxluNV5QX0IkAIukugDJUsHLLyh3Lt_ACHoQyjK8YXwOrtxcclATC5v3F3MDXVxyo9zp1GCZnIL0jrN7dz34l4r-8nHXSiRUNSBh_EAm5-E-2vzn3AdvsR77J6anoASIK6oCAzlk3A4o4fkAxXyJYCcslekoJpeX5iERak2dkS7bYUl9In_aPj5svX-f-_U3DFkdxUtY9XfUt7HeFcXtdhleC5pS8_efb5V7KqG_yfp2vRRRU0Njst0T_LoQE_SGD0eR0M4Zw9HQWmUJjUGGc2qSzByq0Pt0-8dHZb8REpfJ-Qk-TsqryLBqbUnb1CmVdd7zLs1JmqyrDMs1aRFHknEdatKh9M0eNc4NnWChoTo5FquEp52nN06xIVzxLZEtVXZZSVDWu2pYVKVIidTLrSKwbItcsktpp8LSolQ_-ZVF4rwaD2FySHYkpjNY1fhQ2HicRaxUtxzeL_F9RNjRN">