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

    <tr>
        <th>Summary</th>
        <td>
            UBsan trunk misses an out-of-bound at -O0
        </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's UBsan at -O0 misses the out-of-bound bug. This is probably a recent regression since clang-15 and before can detect it.

Compiler explorer: https://godbolt.org/z/4Mhcce9a7

```shell
% cat a.c
struct a {
  signed b

c() {
  struct a d[0];
  d[1].b;
}
void main() { c(); }
%
% clang-tk -O0 -fsanitize=undefined a.c && ./a.out
%
% clang-15 -O0 -fsanitize=undefined a.c && ./a.out
/a.c:5:3: runtime error: index 1 out of bounds for type 'struct a[0]'
%
% clang-tk -v
Ubuntu clang version 17.0.0 (++20230307052914+8fa1e5e673f9-1~exp1~20230307173046.561)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VU2v2zYQ_DX0ZSGBIi3JOujgD6jooeihybmgyJXFhiINfrw4OeS3F5Ts95IUzaFoAMMSlruj4exwKULQV4vYk_pE6stOpDg734dZuGJOojB6Nzr1qR-chzgjTM4Y91HbK0inkLAznI2wV8LaAO9PQVgQEYrfKSw6BAxrjUuxcFMxumQVjOlawrtZB9ABbt6NYjSfQIBHiTaC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