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

    <tr>
        <th>Summary</th>
        <td>
            UBsan misses the shift index is negative
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          Vanish-Zeng
      </td>
    </tr>
</table>

<pre>
    Compiler explorer: https://godbolt.org/z/dnTzPMY93

For the following code, all opt levels of clang's UBSan can not capture the runtime error (i.e. the shift index is negative), while gcc can.


\% cat bug.c
```c
int printf(const char *, ...);
int main()
{
    unsigned short a, b = 35204;
    a = 96 << -17658 ? 796349297U : b;
    printf("%u\n", a);
}
```
\%
\% clang -fsanitize=undefined bug.c && ./a.out
35204
\%
\% gcc -fsanitize=undefined bug.c && ./a.out
/app/bug.c:5:12: runtime error: shift exponent -17658 is negative
21361
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycU8uK5DoM_RplIyokcp6LLOpBdhcu3NsDMzvHcRIPLjvYTndPf_3gVE2_YGYxULhiyTo60pG492o2UnZQnqC8JHwLi3XdF26UXw7fpJmTwY4_urO9rkpLh_J51dZJB-yISwirB3YE6oH62Y6D1SG1bgbqX4D60fz_8u8_X1sG2QWy4-3srcOwSJys1vZJmRmFHSXQGbnWaNeAWj5K7dFOKDQ3M1Dt8eH0HzcouEFjAwq-hs3JHcdtJqirROmcdQjUqFSmu8cvagqozCifUXk0cuZBPUqgNmZ7WpSWOAsRUdP3DO9neQYqUfCAwzan4m6tstvvflcm4OqUCRNQI6zxAcXCI49jTJKmaUzHTm-vr1wZoCaab4j13YmIuJldjhH9Yl1AHjEGBHZBVlJWvALFt3y3txUCOwM74yGvq7JBYD3WbcWKltr6AaNOw4e4V7pABFRuUJ7N_nmO-d7IQn35VPP7xnxsUtQJD5PnRgX1IoFdNjPKScVS9u4hUAVUYQrU89Ru4RZ_q-p3sFGcvwCNt3UF6m-6sWMJ7JhT7MSHYYmG24zI59UaacKvHr6flh2SclblydixsWUtT2SXVy1RmTWsTZZOTGNRZM00NiWbqG4rmgY28CrLmaiqgiWqo4xY1uR1VhYZa9NmyvjYijqvqqxtiKDI5JUrnWr9eI0blCjvN9lVRV3WieaD1H5fUSIjn3B3Rs3KS-K6GHMYttlDkWnlg39DCSpo2T2cPDd4Vd5L_6fNSDanu09LrcKyDamwV6A-wt7_Dquz36UIQP1OxgP1O9mfAQAA___Ph0Jw">