<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96612>96612</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`std::rotr()` causes implicit-integer-sign-change UBSan failure if passed negative shift
</td>
</tr>
<tr>
<th>Labels</th>
<td>
bug,
libc++,
undefined behaviour
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chfast
</td>
</tr>
</table>
<pre>
The following program built with `-std=c++23 -stdlib=libc++ -fsanitize=implicit-integer-sign-change`
causes:
```
include/c++/v1/__bit/rotate.h:27:8: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'unsigned int' changed the value to 4294967295 (32-bit, unsigned)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /opt/compiler-explorer/clang-18.1.0/bin/../include/c++/v1/__bit/rotate.h:27:8
```
```cpp
#include <bit>
int main()
{
return std::rotr(0u, -1);
}
```
If you think this is worth fixing I can submit a patch.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUU02PpDYQ_TXFpQQy5QaaA4fu6SDtYS-ZzCGnlQEDToyN_NGzk18f0TCzySoaKRIy-JVe1atHlfBeTUbKBoorFLdExDBb1_TzKHxIOju8Nb_NEkertX1VZsLV2cmJBbuodMBXFWaEkqU-DMBvPdAV6EocN0CrDvhNq-6AMR29MCqovyTwm1pWrXoVUmWCnKRLNyFpPwszSSgZsBuwSy-ilx74Zb8eZ8mO53FVptdxkEDtUQeovedA7bdvnQpArbNBBJnNwC9UAb-cgV_QRRPUIlE6Z90GvOvB3pq7dF5Zg6OzC4a3VSJQpUwAqtCOeBc6SkxzBDpzSh9VnvBh5ABUY7AfpGh2GA_23t-AYZZHmmDxRPWpLiuqi39nfCcD1Xurzy9fv15-_X2T-2IGOSojh6ucxV1Z93xY-2gmvkfT7ggjUGvXzY7eLqvS0qXy-6qtk27DtDBTmp-zPGNAbacMUJtlQO3_dxf_8y_9BPbreiDEjxII_GlLyX_5J0OZgIvY9Jw_bIDqun8gIjoZojP4GMAL8IuzwQGdWdwcTPONxK_vvNsn2r6M-GYjhlmZP7fTo_L4al2YcVTft9n_gr0w6GO3qIACVxH6OdvJydDwoea1SGSTV3nNWVWUPJmb4dwVBbFqOBf1UBXVeSyH06nPh7oUAxtZohpidGIlFaymkvGsPgkx5iyXjFW870c4MbkIpTOt70tm3ZQo76Ns6rLMKdGik9o_1peoixMQAT0B0Y-9-4A-pgKPqYhuixW3xDVb8rSLk4cT08oH_6NcUEHLBkr2s8ebtyXDfUnxs4XGl-uzMDgKpaOTqEZchfdyQCMnEdRdop_VGJLodDOHsD5WnlqgdlJhjl3W2wWo3SQdr3R19g_ZbxP4sMMDtbsj94b-DgAA___xdnfL">