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

    <tr>
        <th>Summary</th>
        <td>
            [libc] bsearch, qsort, qsort_r declared noexcept incorrectly
        </td>
    </tr>

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

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

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

<pre>
    In our generated headers (`<build dir>/projects/libc/include/stdlib.h`) I see the following:

```c
void * bsearch(const void *, const void *, size_t, size_t, __bsearchcompare_t) __NOEXCEPT;
void qsort(void *, size_t, size_t, __qsortcompare_t) __NOEXCEPT;
void qsort_r(void *, size_t, size_t, __qsortrcompare_t, void *) __NOEXCEPT;
```

https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes mentions:

```
nothrow
The nothrow attribute is used to inform the compiler that a function cannot throw an exception. For example, most functions in the standard C library can be guaranteed not to throw an exception with the notable exceptions of qsort and bsearch that take function pointer arguments.
```

I suspect the same logic applies for noexcept as it does nothrow.  I suspect getting this wrong can lead to codegen bugs in cases of C++ code compiled with exception support calling one of these functions, and passing a callback that does throw.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVM1y4zYTfBroMiUWBeqHPPBgy2aVL9-Xwx5yU4HAiEQMAgxmaK_z9CmQ4spJdpOtUon4GfRM9wCtiGznEWtxeBSHp42auA-x9la_GiQ1OW8x0qYN5qN-8RCmCB16jIrRQI_KYCQQshTHXBTndrLOgLFRFM9CNmMMv6FmErJxttVCNtZrNxkUsiE2zrZZnw7KCl6AEIF7hGtwLrxb34niQeRPIl__j_ny08v8LVgDQj5AS6ii7oUsdfDEsG4IeYZ_rpD9Ay_819HlcsPQYRhVnFcruFz-9__nX8_Pv3wRxeOnnL9TiCxk-d-oc-TPY17iz6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