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

    <tr>
        <th>Summary</th>
        <td>
            UBsan instrumentation missing in constexpr function
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          uecker
      </td>
    </tr>
</table>

<pre>
    In the following example, a constexpr function does not have to be evaluated at compile time, so the signed integer overflow is not diagnosed. Yet, it is folded at compile time which then prevents the UBsan instrumentation do be applied, so the signed overflow ends up  being detected neither at compile-time nor runtime.

static constexpr int foo(int a, int b) { return a * b; }
int n = foo(INT_MAX, 4);
int main() { return n; }

https://godbolt.org/z/7e9e9zddh

The constexpr function is folded even without optimization and apparently before UBsan instrumentation. GCC does get it right.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0k81u2zoQhZ-G2gwiyJStn4UWdgxfZHG7SoF2VVDiSGJLDQVyZCd5-oKy0aRJuqEIiPPN4ZxDFYIZCLERu4PYHRO18Oh8s2D3C33SOv3cPBDwiNA7a93F0AD4pKbZopD3oKBzFBifZg_9Qh0bR6AdBiDHMKozAjtoEfCs7KIYNSiGzk2zsQhsppUS3NphVaLBEOOAHtwZfW_dBcyVpo0ayAXUKXxHjnWG47_eWf2RC5fRdGPkEswez0gc1i5fD0ERGArslwmJ1U1zVKnm2RrUHzX90YKkAywzQItxFBoZu3grQsMj-jcq7lYV5Dz4heI-FdlRZPvrGmLf7s30DDH0zglZxZ1ar0cMrZA1iPIAHnnxBAqE3EMr8gOI8nhlxXMEIj_eAA9fHn_8v_8WEVsha5EfXs9NypCQ1Tsq_cW7riPzHES-F_Ik5GlwunWWU-cHIU8vQp5KrLF-0Xp8W_Q44meJeHUpGgEXw6NbGNzMZjIvVwcU6Th_5ZHYPkOLvfP_cCuF_-7vrzEbkGMMvBlGThPd5LrOa5VgsyllUcqi2MlkbIp2Wym9qfqiLMui6nbbtqrrqpIl9lmXY2IamcltVm_qrNiU-SYtttj1KqtKbLuy7WqxzXBSxqbWnqc4hcSEsGCzyWqZ14lVLdqwPiIpCWNmw4JCyvimfBOL7tplCGKbWRM4vGLYsMXm81BOJoSYMkOfDDVZvG3emWR4XNq0c5OQp9jh9rmbvfuJHQt5WnUFIU834edG_g4AAP__I2ZXOg">