[libc-commits] [libc] [libc] Fix BigInt shift on big-endian platforms (PR #196957)

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Mon May 11 07:13:11 PDT 2026


https://github.com/gchatelet updated https://github.com/llvm/llvm-project/pull/196957

>From e29e10366fb34fc2dba08b149bc604a7f3048ad7 Mon Sep 17 00:00:00 2001
From: Milad Fa <mfarazma at ibm.com>
Date: Mon, 11 May 2026 14:05:01 +0000
Subject: [PATCH] Fix

---
 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 bb9cefd67b552..eef12a0fe657f 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -259,7 +259,7 @@ LIBC_INLINE constexpr cpp::array<word, N> shift(cpp::array<word, N> array,
   constexpr size_t WORD_BITS = cpp::numeric_limits<word>::digits;
 #ifdef LIBC_TYPES_HAS_INT128
   constexpr size_t TOTAL_BITS = N * WORD_BITS;
-  if constexpr (TOTAL_BITS == 128) {
+  if constexpr (TOTAL_BITS == 128 && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) {
     using type = cpp::conditional_t<is_signed, __int128_t, __uint128_t>;
     auto tmp = cpp::bit_cast<type>(array);
     if constexpr (direction == LEFT)



More information about the libc-commits mailing list