[libcxx-commits] [PATCH] D157569: Fixed issue #64544 ([libc++] std::rotl and std::rotr have the wrong signature)
Danny via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 9 19:10:10 PDT 2023
DKay7 created this revision.
DKay7 added a reviewer: ldionne.
Herald added a project: All.
DKay7 requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
- Changed parameters type int `std::rotr` and `std::rorl` functions from `unsigned int` to `int`.
- Implemented behaviour for negative parameter values.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157569
Files:
libcxx/include/__bit/rotate.h
libcxx/include/bit
Index: libcxx/include/bit
===================================================================
--- libcxx/include/bit
+++ libcxx/include/bit
@@ -34,9 +34,9 @@
// [bit.rotate], rotating
template<class T>
- constexpr T rotl(T x, unsigned int s) noexcept; // C++20
+ constexpr T rotl(T x, int s) noexcept; // C++20
template<class T>
- constexpr T rotr(T x, unsigned int s) noexcept; // C++20
+ constexpr T rotr(T x, int s) noexcept; // C++20
// [bit.count], counting
template<class T>
Index: libcxx/include/__bit/rotate.h
===================================================================
--- libcxx/include/__bit/rotate.h
+++ libcxx/include/__bit/rotate.h
@@ -34,15 +34,22 @@
#if _LIBCPP_STD_VER >= 20
template <__libcpp_unsigned_integer _Tp>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, unsigned int __cnt) noexcept {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, int __cnt) noexcept {
const unsigned int __dig = numeric_limits<_Tp>::digits;
if ((__cnt % __dig) == 0)
return __t;
+
+ if (__cnt < 0)
+ return std::__rotr(__t, -__cnt);
+
return (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig)));
}
template <__libcpp_unsigned_integer _Tp>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, unsigned int __cnt) noexcept {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, int __cnt) noexcept {
+ if (__cnt < 0)
+ return rotl(__t, -__cnt);
+
return std::__rotr(__t, __cnt);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157569.548850.patch
Type: text/x-patch
Size: 1518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230810/c9e17b59/attachment.bin>
More information about the libcxx-commits
mailing list