[libc-commits] [libc] [libc] Make bigint trivially constructable (PR #206277)

via libc-commits libc-commits at lists.llvm.org
Sat Jun 27 12:34:10 PDT 2026


https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/206277

>From 1c07f07900f009398608b9d21ddd42aa26c2e304 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 28 Jun 2026 00:16:39 +0530
Subject: [PATCH 1/3] test for constexpr failures

---
 libc/src/__support/big_int.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index 0e5c038ec356e..c1cf5b43fd1f5 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -358,7 +358,7 @@ struct BigInt {
 
   LIBC_INLINE_VAR static constexpr size_t WORD_COUNT = Bits / WORD_SIZE;
 
-  cpp::array<WordType, WORD_COUNT> val{}; // zero initialized.
+  cpp::array<WordType, WORD_COUNT> val; // zero initialized.
 
   LIBC_INLINE constexpr BigInt() = default;
 

>From 7aabfa421ef39741ef5a8edeab6b294b7c1ca397 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 28 Jun 2026 00:56:14 +0530
Subject: [PATCH 2/3] bigint changes

---
 libc/src/__support/big_int.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index c1cf5b43fd1f5..c71dfacf51608 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -366,7 +366,8 @@ struct BigInt {
 
   template <size_t OtherBits, bool OtherSigned, typename OtherWordType>
   LIBC_INLINE constexpr BigInt(
-      const BigInt<OtherBits, OtherSigned, OtherWordType> &other) {
+      const BigInt<OtherBits, OtherSigned, OtherWordType> &other)
+      : val{} {
     using BigIntOther = BigInt<OtherBits, OtherSigned, OtherWordType>;
     [[maybe_unused]] const bool should_sign_extend = Signed && other.is_neg();
 
@@ -491,7 +492,7 @@ struct BigInt {
   LIBC_INLINE static constexpr BigInt one() { return BigInt(1); }
   LIBC_INLINE static constexpr BigInt all_ones() { return ~zero(); }
   LIBC_INLINE static constexpr BigInt min() {
-    BigInt out;
+    BigInt out{};
     if constexpr (SIGNED)
       out.set_msb();
     return out;

>From 266b0830202ad9c51621b8c6dd01c6021d43add8 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 28 Jun 2026 01:03:50 +0530
Subject: [PATCH 3/3] mroe changes in bigint

---
 libc/src/__support/big_int.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index c71dfacf51608..019c932870f92 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -637,7 +637,7 @@ struct BigInt {
   //    256      4        16          10            3
   //    512      8        64          36            7
   LIBC_INLINE constexpr BigInt quick_mul_hi(const BigInt &other) const {
-    BigInt result;
+    BigInt result{};
     multiword::quick_mul_hi(result.val, val, other.val);
     return result;
   }
@@ -850,7 +850,7 @@ struct BigInt {
 #define DEFINE_BINOP(OP)                                                       \
   LIBC_INLINE friend constexpr BigInt operator OP(const BigInt &lhs,           \
                                                   const BigInt &rhs) {         \
-    BigInt result;                                                             \
+    BigInt result{};                                                           \
     for (size_t i = 0; i < WORD_COUNT; ++i)                                    \
       result[i] = lhs[i] OP rhs[i];                                            \
     return result;                                                             \
@@ -868,7 +868,7 @@ struct BigInt {
 #undef DEFINE_BINOP
 
   LIBC_INLINE constexpr BigInt operator~() const {
-    BigInt result;
+    BigInt result{};
     for (size_t i = 0; i < WORD_COUNT; ++i)
       result[i] = static_cast<WordType>(~val[i]);
     return result;
@@ -1315,7 +1315,7 @@ mask_trailing_ones() {
     return T::all_ones();
   constexpr size_t QUOTIENT = count / T::WORD_SIZE;
   constexpr size_t REMAINDER = count % T::WORD_SIZE;
-  T out; // zero initialized
+  T out{}; // zero initialized
   for (size_t i = 0; i <= QUOTIENT; ++i)
     out[i] = i < QUOTIENT
                  ? cpp::numeric_limits<typename T::word_type>::max()
@@ -1331,7 +1331,7 @@ LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, T> mask_leading_ones() {
     return T::all_ones();
   constexpr size_t QUOTIENT = (T::BITS - count - 1U) / T::WORD_SIZE;
   constexpr size_t REMAINDER = count % T::WORD_SIZE;
-  T out; // zero initialized
+  T out{}; // zero initialized
   for (size_t i = QUOTIENT; i < T::WORD_COUNT; ++i)
     out[i] = i > QUOTIENT
                  ? cpp::numeric_limits<typename T::word_type>::max()



More information about the libc-commits mailing list