aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2023-12-07 12:13:59 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2024-08-01 21:56:56 +0100
commit3a817a4a5a6d94da9127af3be9f84a74e3076ee2 (patch)
tree4aa05f69785ab1dc9656c72b5ebcaaad618d378e
parent283f6e24c6b5c8a1b35003b27bfcad46af25a859 (diff)
downloadgcc-3a817a4a5a6d94da9127af3be9f84a74e3076ee2.zip
gcc-3a817a4a5a6d94da9127af3be9f84a74e3076ee2.tar.gz
gcc-3a817a4a5a6d94da9127af3be9f84a74e3076ee2.tar.bz2
libstdc++: Remove unnecessary uses of <stdint.h>
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>.
-rw-r--r--libstdc++-v3/include/bits/align.h5
-rw-r--r--libstdc++-v3/include/bits/atomic_base.h17
-rw-r--r--libstdc++-v3/include/bits/atomic_wait.h4
-rw-r--r--libstdc++-v3/include/std/atomic1
4 files changed, 17 insertions, 10 deletions
diff --git a/libstdc++-v3/include/bits/align.h b/libstdc++-v3/include/bits/align.h
index 1a06b81..0c64584 100644
--- a/libstdc++-v3/include/bits/align.h
+++ b/libstdc++-v3/include/bits/align.h
@@ -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));
}
}
diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index ae6819f..7c27bd8 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -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;
diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index 6c98f39..f1c183f 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -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];
}
};
diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 1462cf5..36ff89a 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -48,6 +48,7 @@
#include <bits/version.h>
#include <bits/atomic_base.h>
+#include <cstdint>
namespace std _GLIBCXX_VISIBILITY(default)
{