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

    <tr>
        <th>Summary</th>
        <td>
            libc++ and __builtin_assume behavior don't mix well
        </td>
    </tr>

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

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

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

<pre>
    depending on macro definitions like _LIBCPP_ENABLE_ASSERTIONS, libc++ can end up using `__builtin_assume` and if the assumption is false at compiler time it results in 0 instructions being generated from that point forward without any error or warning.

The example below illustrates the issue. This is a case I hit but in a much less obvious way since input's size was coming from a series of template expansions.

This generates zero instructions, not even the normal `xor eax, eax;ret` because 22 != 256 which ends up with __builtin_assume(false) and anything below that is unreachable. This can result in half compiled functions and again without a single compiler warning or error.

Example:

https://godbolt.org/z/Kq5qq4Tn8 

```

#include <array>
#include <span>

int main()
{
    std::array<int, 256> chunk{};
    span<int, 256> input{chunk.data(), 22};

    return 0;
}
```

This can be categorized as diagnostics bug by llvm but I think libc++ team should know about it given `__builtin_assume`'s behavior.

I hit this issue after using libc++ from llvm-15's release but __builtin_assume has always behaved this way.


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VV1v4joQ_TXmZbQoOEDggYfSglTd1d7V3b6jSTxJ5taxs_5oSn_9lRO60O7qSihBtmfOmXNmHPSeG0O0E6u9WD3MMIbWul2LGs-aZ6VV552inoxi04A10GHlLCiq2XBgazxofiY4fX3c33__fjp8u9t_PZzufvw4_PP0-Pe3H0Leg-ayEnIv5B4qNEBGQewh-pRSrLPTqYysA5sTeh87EusM0CjgGkJLMC72CQvYQ43aE2CAynY9a3IQuCPgAI581MEDG8iAjQ8uVhPDkhJSQ4YcBlJQO9tBaDFAb9kEqK0b0CkYOLQ2BkBzBnLOOrAOBnSGTTMX2YPI7qbnU0tAr9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