-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Fix casts for arm32 after Wconversion #129771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc] Fix casts for arm32 after Wconversion #129771
Conversation
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.
@llvm/pr-subscribers-libc Author: Michael Jones (michaelrj-google) ChangesFollowup to #127523 There were some test failures on arm32 after enabling Wconversion. There Full diff: https://github.com/llvm/llvm-project/pull/129771.diff 2 Files Affected:
diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index 85a17f3110d6a..f44624a7eafce 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -272,15 +272,15 @@ LIBC_INLINE constexpr cpp::array<word, N> shift(cpp::array<word, N> array,
if (LIBC_UNLIKELY(offset == 0))
return array;
const bool is_neg = is_signed && is_negative(array);
- constexpr auto at = [](size_t index) -> size_t {
+ constexpr auto at = [](size_t index) -> int {
// reverse iteration when direction == LEFT.
if constexpr (direction == LEFT)
- return N - index - 1;
- return index;
+ return int(N) - int(index) - 1;
+ return int(index);
};
const auto safe_get_at = [&](size_t index) -> word {
// return appropriate value when accessing out of bound elements.
- const size_t i = at(index);
+ const int i = at(index);
if (i < 0)
return 0;
if (i >= int(N))
@@ -465,8 +465,7 @@ struct BigInt {
}
// Initialize the first word to |v| and the rest to 0.
- template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T> &&
- !cpp::is_same_v<T, bool>>>
+ template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T>>>
LIBC_INLINE constexpr BigInt(T v) {
constexpr size_t T_SIZE = sizeof(T) * CHAR_BIT;
const bool is_neg = v < 0;
diff --git a/libc/src/string/memory_utils/generic/byte_per_byte.h b/libc/src/string/memory_utils/generic/byte_per_byte.h
index 2aecf0126cc43..862aeecab7f55 100644
--- a/libc/src/string/memory_utils/generic/byte_per_byte.h
+++ b/libc/src/string/memory_utils/generic/byte_per_byte.h
@@ -38,7 +38,8 @@ inline_memmove_byte_per_byte(Ptr dst, CPtr src, size_t count) {
dst[offset] = src[offset];
} else {
LIBC_LOOP_NOUNROLL
- for (ptrdiff_t offset = count - 1; offset >= 0; --offset)
+ for (ptrdiff_t offset = static_cast<ptrdiff_t>(count - 1); offset >= 0;
+ --offset)
dst[offset] = src[offset];
}
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! We saw similar breakages on our Fuchsia-libc integration roller. LGTM
Thanks for the review, I'll merge after presubmits finish. |
@michaelrj-google Thanks for the quick fix! Do you know why the arm32 issues weren't caught in the checks that run on the PR? All of those seemed to be passing.
TIL, is it to have indexing like Python does where Follow up: how does a negative value work here, given that llvm-project/libc/src/__support/CPP/array.h Lines 40 to 44 in 3b38992
Aside: I'll be running into the same/similar warning in: #129811 |
It's not that
If |
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.
Followup to #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 abilityto be negative.