Skip to content

Commit 486628c

Browse files
[libc] fix -Wshorten-64-to-32
32b arm failed when enabling -Werror: libc/src/string/memory_utils/utils.h:50:36: error: implicit conversion loses integer precision: 'unsigned long long' to 'size_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32] return value == 0 ? value : 1ULL << log2s(value); ~~~~~~ ~~~~~^~~~~~~~~~~~~~~ libc/src/string/memory_utils/utils.h:56:50: error: implicit conversion loses integer precision: 'unsigned long long' to 'size_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32] return is_power2_or_zero(value) ? value : 1ULL << (log2s(value) + 1); ~~~~~~ ~~~~~^~~~~~~~~~~~~~~~~~~~~ arm-linux-gnueabi is ILP32. size_t is an 'unsigned int' and 'long' is the same bit width as `int`. Use an unsigned long literal rather than an unsigned long long literal to avoid the implicit promotion to unsigned long long which would then be truncated to unsigned int, as hinted at by the warning. Link: https://lab.llvm.org/buildbot/#/builders/229/builds/20596
1 parent 6886a52 commit 486628c

File tree

1 file changed

+2
-2
lines changed
  • libc/src/string/memory_utils

1 file changed

+2
-2
lines changed

libc/src/string/memory_utils/utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ LIBC_INLINE constexpr size_t log2s(size_t value) {
4747
// Returns the first power of two preceding value or value if it is already a
4848
// power of two (or 0 when value is 0).
4949
LIBC_INLINE constexpr size_t le_power2(size_t value) {
50-
return value == 0 ? value : 1ULL << log2s(value);
50+
return value == 0 ? value : 1UL << log2s(value);
5151
}
5252

5353
// Returns the first power of two following value or value if it is already a
5454
// power of two (or 0 when value is 0).
5555
LIBC_INLINE constexpr size_t ge_power2(size_t value) {
56-
return is_power2_or_zero(value) ? value : 1ULL << (log2s(value) + 1);
56+
return is_power2_or_zero(value) ? value : 1UL << (log2s(value) + 1);
5757
}
5858

5959
// Returns the number of bytes to substract from ptr to get to the previous

0 commit comments

Comments
 (0)