Skip to content

Commit 1a6fb70

Browse files
michaelrj-googlejph-13
authored andcommitted
[libc] Fix casts for arm32 after Wconversion (llvm#129771)
Followup to llvm#127523 There were some test failures on arm32 after enabling Wconversion. There were some tests that were failing due to missing casts. Also I changed BigInt's `safe_get_at` back to being signed since it needed the ability to be negative.
1 parent 3c069d8 commit 1a6fb70

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

libc/src/__support/big_int.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,15 @@ LIBC_INLINE constexpr cpp::array<word, N> shift(cpp::array<word, N> array,
272272
if (LIBC_UNLIKELY(offset == 0))
273273
return array;
274274
const bool is_neg = is_signed && is_negative(array);
275-
constexpr auto at = [](size_t index) -> size_t {
275+
constexpr auto at = [](size_t index) -> int {
276276
// reverse iteration when direction == LEFT.
277277
if constexpr (direction == LEFT)
278-
return N - index - 1;
279-
return index;
278+
return int(N) - int(index) - 1;
279+
return int(index);
280280
};
281281
const auto safe_get_at = [&](size_t index) -> word {
282282
// return appropriate value when accessing out of bound elements.
283-
const size_t i = at(index);
283+
const int i = at(index);
284284
if (i < 0)
285285
return 0;
286286
if (i >= int(N))
@@ -465,8 +465,7 @@ struct BigInt {
465465
}
466466

467467
// Initialize the first word to |v| and the rest to 0.
468-
template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T> &&
469-
!cpp::is_same_v<T, bool>>>
468+
template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T>>>
470469
LIBC_INLINE constexpr BigInt(T v) {
471470
constexpr size_t T_SIZE = sizeof(T) * CHAR_BIT;
472471
const bool is_neg = v < 0;

libc/src/string/memory_utils/generic/byte_per_byte.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ inline_memmove_byte_per_byte(Ptr dst, CPtr src, size_t count) {
3838
dst[offset] = src[offset];
3939
} else {
4040
LIBC_LOOP_NOUNROLL
41-
for (ptrdiff_t offset = count - 1; offset >= 0; --offset)
41+
for (ptrdiff_t offset = static_cast<ptrdiff_t>(count - 1); offset >= 0;
42+
--offset)
4243
dst[offset] = src[offset];
4344
}
4445
}

0 commit comments

Comments
 (0)