]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Remove unnecessary uses of <stdint.h>
authorJonathan Wakely <jwakely@redhat.com>
Thu, 7 Dec 2023 12:13:59 +0000 (12:13 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 1 Aug 2024 20:56:56 +0000 (21:56 +0100)
We don't need to include all of <stdint.h> when we only need uintptr_t
from it. By using GCC's internal macro we avoid unnecessarily declaring
everything in <stdint.h>. This helps users to avoid accidentally relying
on those names being declared without explicitly including the header.

libstdc++-v3/ChangeLog:

* include/bits/align.h (align, assume_aligned): Use
__UINTPTR_TYPE__ instead of uintptr_t. Do not include
<stdint.h>.
* include/bits/atomic_base.h (__atomic_ref): Likewise.
* include/bits/atomic_wait.h (__waiter_pool_base::_S_for):
Likewise.
* include/std/atomic: Include <cstdint>.

libstdc++-v3/include/bits/align.h
libstdc++-v3/include/bits/atomic_base.h
libstdc++-v3/include/bits/atomic_wait.h
libstdc++-v3/include/std/atomic

index 1a06b814fbb6a0d8c791a158f490987008e7c2fb..0c64584b27fcaaabe74fb109af503bd96a991ff7 100644 (file)
@@ -31,7 +31,6 @@
 #define _GLIBCXX_ALIGN_H 1
 
 #include <bit>          // std::has_single_bit
-#include <stdint.h>     // uintptr_t
 #include <debug/assertions.h> // _GLIBCXX_DEBUG_ASSERT
 #include <bits/version.h>
 
@@ -62,7 +61,7 @@ align(size_t __align, size_t __size, void*& __ptr, size_t& __space) noexcept
 {
   if (__space < __size)
     return nullptr;
-  const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
+  const auto __intptr = reinterpret_cast<__UINTPTR_TYPE__>(__ptr);
   const auto __aligned = (__intptr - 1u + __align) & -__align;
   const auto __diff = __aligned - __intptr;
   if (__diff > (__space - __size))
@@ -97,7 +96,7 @@ align(size_t __align, size_t __size, void*& __ptr, size_t& __space) noexcept
        {
          // This function is expected to be used in hot code, where
          // __glibcxx_assert would add unwanted overhead.
-         _GLIBCXX_DEBUG_ASSERT((uintptr_t)__ptr % _Align == 0);
+         _GLIBCXX_DEBUG_ASSERT((__UINTPTR_TYPE__)__ptr % _Align == 0);
          return static_cast<_Tp*>(__builtin_assume_aligned(__ptr, _Align));
        }
     }
index ae6819f119b6bace2411bcf600121813b2b2f6dd..7c27bd8c9514e9262278bcd2594d192ff923bc83 100644 (file)
@@ -34,7 +34,6 @@
 
 #include <bits/c++config.h>
 #include <new> // For placement new
-#include <stdint.h>
 #include <bits/atomic_lockfree_defines.h>
 #include <bits/move.h>
 
@@ -1504,7 +1503,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       explicit
       __atomic_ref(_Tp& __t) : _M_ptr(std::__addressof(__t))
-      { __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) == 0); }
+      {
+       __glibcxx_assert(((__UINTPTR_TYPE__)_M_ptr % required_alignment) == 0);
+      }
 
       __atomic_ref(const __atomic_ref&) noexcept = default;
 
@@ -1615,7 +1616,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       explicit
       __atomic_ref(_Tp& __t) : _M_ptr(&__t)
-      { __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) == 0); }
+      {
+       __glibcxx_assert(((__UINTPTR_TYPE__)_M_ptr % required_alignment) == 0);
+      }
 
       __atomic_ref(const __atomic_ref&) noexcept = default;
 
@@ -1788,7 +1791,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       explicit
       __atomic_ref(_Fp& __t) : _M_ptr(&__t)
-      { __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) == 0); }
+      {
+       __glibcxx_assert(((__UINTPTR_TYPE__)_M_ptr % required_alignment) == 0);
+      }
 
       __atomic_ref(const __atomic_ref&) noexcept = default;
 
@@ -1915,7 +1920,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       explicit
       __atomic_ref(_Tp*& __t) : _M_ptr(std::__addressof(__t))
-      { __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) == 0); }
+      {
+       __glibcxx_assert(((__UINTPTR_TYPE__)_M_ptr % required_alignment) == 0);
+      }
 
       __atomic_ref(const __atomic_ref&) noexcept = default;
 
index 6c98f3963ad1f66be9c3b01c869ac17f52d762e7..f1c183f9dbbb286627b36e9cbd592b2108e87f14 100644 (file)
@@ -250,9 +250,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static __waiter_pool_base&
       _S_for(const void* __addr) noexcept
       {
-       constexpr uintptr_t __ct = 16;
+       constexpr __UINTPTR_TYPE__ __ct = 16;
        static __waiter_pool_base __w[__ct];
-       auto __key = (uintptr_t(__addr) >> 2) % __ct;
+       auto __key = ((__UINTPTR_TYPE__)__addr >> 2) % __ct;
        return __w[__key];
       }
     };
index 1462cf5ec23fac9ed1bcea3234669dc0861e6278..36ff89a146c43ee37936b82f1bc22cf6917cefcf 100644 (file)
@@ -48,6 +48,7 @@
 #include <bits/version.h>
 
 #include <bits/atomic_base.h>
+#include <cstdint>
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {