[libc-commits] [libc] [libc] Add `-Wsign-conversion` (PR #129811)
Vinay Deshmukh via libc-commits
libc-commits at lists.llvm.org
Wed Mar 5 17:30:03 PST 2025
https://github.com/vinay-deshmukh updated https://github.com/llvm/llvm-project/pull/129811
>From 9e64e2a4202ef5f397008b9a250c8e14b61f6394 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Tue, 4 Mar 2025 20:33:19 -0500
Subject: [PATCH 1/3] WIP: sign-conversion
---
libc/src/__support/big_int.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index e726a094b5dac..141a07869cc9b 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -296,7 +296,10 @@ LIBC_INLINE constexpr cpp::array<word, N> shift(cpp::array<word, N> array,
for (size_t index = 0; index < N; ++index) {
const word part1 = safe_get_at(index + index_offset);
const word part2 = safe_get_at(index + index_offset + 1);
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wsign-conversion"
word &dst = out[at(index)];
+ #pragma GCC diagnostic pop
if (bit_offset == 0)
dst = part1; // no crosstalk between parts.
else if constexpr (direction == LEFT)
>From 47c95c9563b3f8f1619f5117a1c46e7293bd511a Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Tue, 4 Mar 2025 20:53:06 -0500
Subject: [PATCH 2/3] clang-format
---
libc/src/__support/big_int.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index 141a07869cc9b..10a046ea95a9c 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -296,10 +296,10 @@ LIBC_INLINE constexpr cpp::array<word, N> shift(cpp::array<word, N> array,
for (size_t index = 0; index < N; ++index) {
const word part1 = safe_get_at(index + index_offset);
const word part2 = safe_get_at(index + index_offset + 1);
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wsign-conversion"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsign-conversion"
word &dst = out[at(index)];
- #pragma GCC diagnostic pop
+#pragma GCC diagnostic pop
if (bit_offset == 0)
dst = part1; // no crosstalk between parts.
else if constexpr (direction == LEFT)
>From 958813abcc5c39bc671a1d8b531fa11f548acc5e Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshmukh at users.noreply.github.com>
Date: Wed, 5 Mar 2025 20:22:56 -0500
Subject: [PATCH 3/3] better cast
---
libc/src/__support/big_int.h | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index 10a046ea95a9c..9f8001b9a66e8 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -296,10 +296,7 @@ LIBC_INLINE constexpr cpp::array<word, N> shift(cpp::array<word, N> array,
for (size_t index = 0; index < N; ++index) {
const word part1 = safe_get_at(index + index_offset);
const word part2 = safe_get_at(index + index_offset + 1);
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
- word &dst = out[at(index)];
-#pragma GCC diagnostic pop
+ word &dst = out[static_cast<size_t>(at(index))];
if (bit_offset == 0)
dst = part1; // no crosstalk between parts.
else if constexpr (direction == LEFT)
More information about the libc-commits
mailing list