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

    <tr>
        <th>Summary</th>
        <td>
            Constant tracking foiled by an escaping reference
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    Something weird happens to Clang's tracking a variable's value once it is passed by reference - __builtin_assume-ing its value afterwards or even actually reassigning it does not help the compiler 'get its head together'.

Both __builtin_constant_p and the enable_if attribute then fail to 'detect' the 'obviously constant value' (which the compiler also obviously knows at compile-time since it generates code which stores the constant value directly into the function argument register ??).

https://godbolt.org/z/3M8nx6qE7

Tthis issue actually causes significant binary bloat (useless object cleanups being called for already destroyed objects)  in our production code which relies heavily on generated and generic C++ code.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxdU01zmzAQ_TVw2bEH44_AgUOc1Lee2rtnJS2gRJaoJOy6v74rKInTGWzYr6e3b1fCqXvzw10o9tp2cCPtFfQ4DGQDRAcvBm2XlU9seJTvKQfhil6jMDT5r2hGAmclgY6gAwwYAikQd_DUkqcUWcH5LEZtorZnDo8XWiUoHZd6bCP5G3oVwHmgK1lAGUc0JsFwie7sXAHKUQDrIvRkBog9gXSXQRvywIQ6ihNsT6i4ATZ78uxfZ8VrVjzP_0cX-wdG0tkQ0cbzAGjVBEk2NXjWLWCMXosxUvJbaFGbJAxDKookI39MFfx24qrdGJjygjh3l1Kysrr1WvZfCaMJDj7L3q27BT5xSVhFfSEI-p-4HVnyGLl96RTBjBei8-yZYR9PBaU982NYbZlwSmhHK6N2rK3veAac6anTISbptqf0lPUXofoYh5Btn7OSQ6fOKeFMXDvPK3H6w7_t98r-Pvz69vRY9JN3KfAmhDTXZYgSx8A0pzm2WiaWQlv0dxDGccesDycYCrwA4o15gzSEdhwCCEqTlwzDa9W6pBqvhLqDohC9u7N3LglMH7hbcKOHwTs1zt0-qOXJaJq246qZFQcXUdU0-8nSEl6y8sjPVLrOqdkcDlVR1Ju6zlWzVfW2xjzqaKh5WUT_uCCt02a-AGiBgsQheT8uQz560_wnrI79KNY8dTaMuS6vFTfxNu3YaZKTGzztq4pJ9I1sD-WurlBt5O4gN227qwl3SlUVIQmk3KAgE5psf8z2r7luyqIsNxvuYb_fbup1IUo2CokFHkSJKtsVdOHlXqeD04hz30wcxNgFDhrek_AZnK8k0YKPY-ydb4age8wnss3E9C8gcIT5">