summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-05-26 21:32:55 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-06-08 10:52:16 +0100
commit6666ca1ab44ad8a61e2b916cf4173fe452b78ed6 (patch)
tree2086080274b928ae29a9185493f5a7c6800b9d29 /libstdc++-v3
parent64f5d58d8151324be111ba6e13c50b4b642c41c2 (diff)
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)
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp18
-rw-r--r--libstdc++-v3/include/ext/random2
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__