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

Milad Fa via libc-commits libc-commits at lists.llvm.org
Mon May 11 07:08:55 PDT 2026


https://github.com/miladfarca created https://github.com/llvm/llvm-project/pull/196957

BigInt<128> stores the value in two separate word sized array slots
with the low 64 bits being stored in val[0] and high 64 bits in val[1].
This can't be reinterpreted as a 128 bit value on big-endian platforms
because the values are reversed.

This has caused test failures on s390x builds of V8:
https://issues.chromium.org/issues/511831894

>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