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

    <tr>
        <th>Summary</th>
        <td>
            std::sort triggers negate-overflow ubsan
        </td>
    </tr>

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

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

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

<pre>
    Change 0fb76bae6b2abfe5e0a34557f365a586be989364 introduced a regression in `std::sort`.

Building
```cpp
#include <algorithm>
#include <vector>

int main() {
        std::vector<int> other_ops;
        for (int i = 0; i < 1024; ++i) {
 other_ops.push_back(i);
        }

        std::sort(other_ops.begin(), other_ops.end(), std::greater<int>());
}
```

with
```
~/llvm/build/bin/clang++ -O2 -fsanitize=integer ubsan_test.cpp -stdlib=libc++ -static-libstdc++ -l:libc++abi.a
```

crashes with the following error:
```
include/c++/v1/__bit/blsr.h:25:23: runtime error: negation of 18446744073709551615 cannot be represented in type 'unsigned long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior include/c++/v1/__bit/blsr.h:25:23
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVE2PozgQ_TXFxQoyNgZy4ECSyW200o7msKfIhgK849jINmn1Hva3r5zP7unTRhFgl-vVq-eqkiHoySK2IHYgDplc4-x8-8vZ6T1Tbnhv97O0ExI6qrpSEivFpBpRIJW8FKIeeSWkaCqF22bLq5JoG70b1h4HIonHyWMI2lmiLYGKhjgA74B3wfkIFc2BdkC73arNoO2UVhW9_ftlSUvGte3NOiABvpdmcl7H-Qz82xfjBfvo_N1CO20jOUttgTXAtgTqHdCO3H9PHg-nvbYR-Dfi4oz-5JYA_OP50XkCrEmYmgA_EAp8d_3ck4KyMq2A7YDt9IdgT7B8WcN8UrL_lUCAbT-jQ324cf5C7yoTa15ACqdHSsD2HyKgHV7bT__Jo4z4yu9x5E7gHvgh-Y3Em47zb7v_AjsaczkDO6p0VemdaBx7I-10S5xs_mBkMwZpddT_IPCDthEn9GRVQdpTxBDzflnIJsTBaAX8YLTqH84hyqj7jdEqxOG5a4B3r1NS6Vx-Jdx7GWYMJBEncUYyOmPcm7YTQe_T7Xa_Od2rJiVwQwZ2vBTAjqeT0jFlZ4LPZ-AdE-nBgXfErzbqMz4xicVJxlTbbiRFU5ZVXZa05jXdClFUhSC9tNZFopB4XDwGtBGH1AnxfUECrF7ttf0GYlySsQba_fj5_Xv3518J_6cdcNQWhx3O8qKd_3HX9hp9fVg36m4m_z-tz7JkQ8uHLd_KDNuiLhvOalpU2dw2tJdNLcZiW8iiYYVs-rJRTBYDl5LRIdMto0xQwWpaMc6rXIle1FT2nHJMMwJKimepTZ7KKHd-ynQIK7ZFWQhBMyMVmnCdQoxZfCNXKzCWhpJvk9NGrVOAkhodYnjBRB0Ntp8ahkSvpwl9uN0QbtwF_Wjc260Ss9Wbdo4x9XgH7AjsOOk4ryrv3flV6NeYi3d_Y5-kuxIKwI53xpeW_RcAAP__BLqPmA">