public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-8464] libstdc++: Fix narrowing conversions for 16-bit size_t [PR105681] Date: Wed, 8 Jun 2022 15:52:58 +0000 (GMT) [thread overview] Message-ID: <20220608155258.4E0FB3850872@sourceware.org> (raw) https://gcc.gnu.org/g:6666ca1ab44ad8a61e2b916cf4173fe452b78ed6 commit r12-8464-g6666ca1ab44ad8a61e2b916cf4173fe452b78ed6 Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu May 26 21:32:55 2022 +0100 libstdc++: Fix narrowing conversions for 16-bit size_t [PR105681] On a 16-bit target such as msp430 we get errors about narrowing long values to size_t, which is only 16-bit. When --enable-libstdcxx-pch is used the <bits/extc++.h> header breaks the build because of these narrowing errors. libstdc++-v3/ChangeLog: PR libstdc++/105681 * include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp: Limit ga_sizes array to values that fit in size_t. * include/ext/random [__SIZE_WIDTH < 32] (sfmt86243) (sfmt86243_64, sfmt132049, sfmt132049_64, sfmt216091) (sfmt216091_64): Do not declare. (cherry picked from commit 367740bf6d3a6627798b3955e5d85efc7549ef50) Diff: --- .../resize_policy/hash_prime_size_policy_imp.hpp | 18 +++++++++++++++--- libstdc++-v3/include/ext/random | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp b/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp index d53392c8211..43d72768206 100644 --- a/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp +++ b/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp @@ -46,15 +46,23 @@ namespace detail { enum { + num_distinct_sizes_16_bit = 14, num_distinct_sizes_32_bit = 30, num_distinct_sizes_64_bit = 62, - num_distinct_sizes = sizeof(std::size_t) != 8 ? - num_distinct_sizes_32_bit : num_distinct_sizes_64_bit, + // The number of values is limited by the width of size_t. + // Maybe we could just use (__SIZE_WIDTH__ - 2) here. +#if __SIZE_WIDTH__ >= 64 + num_distinct_sizes = num_distinct_sizes_64_bit +#elif __SIZE_WIDTH__ >= 32 + num_distinct_sizes = num_distinct_sizes_32_bit +#else + num_distinct_sizes = num_distinct_sizes_16_bit +#endif }; // Originally taken from the SGI implementation; acknowledged in the docs. // Further modified (for 64 bits) from tr1's hashtable. - static const std::size_t g_a_sizes[num_distinct_sizes_64_bit] = + static const std::size_t g_a_sizes[num_distinct_sizes] = { /* 0 */ 5ul, /* 1 */ 11ul, @@ -70,6 +78,7 @@ namespace detail /* 11 */ 14033ul, /* 12 */ 28411ul, /* 13 */ 57557ul, +#if __SIZE_WIDTH__ >= 32 /* 14 */ 116731ul, /* 15 */ 236897ul, /* 16 */ 480881ul, @@ -86,6 +95,7 @@ namespace detail /* 27 */ 1164186217ul, /* 28 */ 2364114217ul, /* 29 */ 4294967291ul, +#if __SIZE_WIDTH__ >= 64 /* 30 */ (std::size_t)8589934583ull, /* 31 */ (std::size_t)17179869143ull, /* 32 */ (std::size_t)34359738337ull, @@ -118,6 +128,8 @@ namespace detail /* 59 */ (std::size_t)4611686018427387847ull, /* 60 */ (std::size_t)9223372036854775783ull, /* 61 */ (std::size_t)18446744073709551557ull, +#endif +#endif }; } // namespace detail diff --git a/libstdc++-v3/include/ext/random b/libstdc++-v3/include/ext/random index b7155767b02..50505b876cc 100644 --- a/libstdc++-v3/include/ext/random +++ b/libstdc++-v3/include/ext/random @@ -346,6 +346,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION 0xa3ac4000U, 0xecc1327aU> sfmt44497_64; +#if __SIZE_WIDTH__ >= 32 typedef simd_fast_mersenne_twister_engine<uint32_t, 86243, 366, 6, 7, 19, 1, @@ -396,6 +397,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION 0xf8000001U, 0x89e80709U, 0x3bd2b64bU, 0x0c64b1e4U> sfmt216091_64; +#endif // __SIZE_WIDTH__ >= 32 #endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
reply other threads:[~2022-06-08 15:52 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220608155258.4E0FB3850872@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).