[committed] libstdc++: Remove unnecessary uses of <stdint.h>
Checks
Commit Message
This will probably need a gcc-15/porting_to.html entry at some point.
Every time we remove transitive includes of <cstdint> it breaks
somebody!
Tested x86_64-linux. Pushed to trunk.
-- >8 --
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 | 5 ++---
libstdc++-v3/include/bits/atomic_base.h | 17 ++++++++++++-----
libstdc++-v3/include/bits/atomic_wait.h | 4 ++--
libstdc++-v3/include/std/atomic | 1 +
4 files changed, 17 insertions(+), 10 deletions(-)
Comments
On Thu, Aug 1, 2024 at 2:14 PM Jonathan Wakely <jwakely@redhat.com> wrote:
>
> This will probably need a gcc-15/porting_to.html entry at some point.
> Every time we remove transitive includes of <cstdint> it breaks
> somebody!
Yes including testcases, libstdc++-prettyprinters/shared_ptr.cc does
not compile due to this change even:
/home/apinski/src/upstream-gcc-isel/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc:40:
error: 'uintptr_t' was not declared in this scope
/home/apinski/src/upstream-gcc-isel/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc:40:
note: 'uintptr_t' is defined in header '<cstdint>'; this is probably
fixable by adding '#include <cstdint>'
/home/apinski/src/upstream-gcc-isel/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc:41:
error: expected ',' or ';' before '{' token
/home/apinski/src/upstream-gcc-isel/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc:
In function 'int main()':
/home/apinski/src/upstream-gcc-isel/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc:58:
error: no match for call to '(std::shared_ptr<int>) (int)'
/home/apinski/src/upstream-gcc-isel/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc:62:
error: no match for call to '(std::shared_ptr<int>) (int)'
/home/apinski/src/upstream-gcc-isel/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc:67:
error: no match for call to '(std::shared_ptr<int>) (int)'
compiler exited with status 1
UNRESOLVED: libstdc++-prettyprinters/shared_ptr.cc compilation failed
to produce executable
Thanks,
Andrew Pinski
>
> Tested x86_64-linux. Pushed to trunk.
>
> -- >8 --
>
> 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 | 5 ++---
> libstdc++-v3/include/bits/atomic_base.h | 17 ++++++++++++-----
> libstdc++-v3/include/bits/atomic_wait.h | 4 ++--
> libstdc++-v3/include/std/atomic | 1 +
> 4 files changed, 17 insertions(+), 10 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/align.h b/libstdc++-v3/include/bits/align.h
> index 1a06b814fbb..0c64584b27f 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 ae6819f119b..7c27bd8c951 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 6c98f3963ad..f1c183f9dbb 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 1462cf5ec23..36ff89a146c 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)
> {
> --
> 2.45.2
>
On Fri, 2 Aug 2024 at 02:29, Andrew Pinski <pinskia@gmail.com> wrote:
>
> On Thu, Aug 1, 2024 at 2:14 PM Jonathan Wakely <jwakely@redhat.com> wrote:
> >
> > This will probably need a gcc-15/porting_to.html entry at some point.
> > Every time we remove transitive includes of <cstdint> it breaks
> > somebody!
>
> Yes including testcases, libstdc++-prettyprinters/shared_ptr.cc does
> not compile due to this change even:
Oops, looks like I missed the UNRESOLVED lines in the log by only
searching for FAIL.
Fixed with the attached patch, pushed to trunk.
commit 06201faa6376cade5a286850370dd070c1573531
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Aug 2 08:27:09 2024
libstdc++: Add missing <cstdint> to test
libstdc++-v3/ChangeLog:
* testsuite/libstdc++-prettyprinters/shared_ptr.cc: Include
<cstdint>.
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc
index a9910e6a56d..5ff206a145b 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/shared_ptr.cc
@@ -20,6 +20,7 @@
#include <memory>
#include <iostream>
+#include <cstdint>
template<class T>
void
@@ -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));
}
}
@@ -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;
@@ -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];
}
};
@@ -48,6 +48,7 @@
#include <bits/version.h>
#include <bits/atomic_base.h>
+#include <cstdint>
namespace std _GLIBCXX_VISIBILITY(default)
{