[libc-commits] [libc] 7a03666 - [libc] Fix compilation errors that occur when building with GCC (#96976)

via libc-commits libc-commits at lists.llvm.org
Thu Jun 27 15:05:46 PDT 2024


Author: OverMighty
Date: 2024-06-27T15:05:43-07:00
New Revision: 7a03666401342e71995f8e221a8755eb69187876

URL: https://github.com/llvm/llvm-project/commit/7a03666401342e71995f8e221a8755eb69187876
DIFF: https://github.com/llvm/llvm-project/commit/7a03666401342e71995f8e221a8755eb69187876.diff

LOG: [libc] Fix compilation errors that occur when building with GCC (#96976)

Added: 
    

Modified: 
    libc/src/__support/FPUtil/NearestIntegerOperations.h
    libc/src/__support/FPUtil/dyadic_float.h
    libc/src/__support/FPUtil/generic/FMA.h
    libc/src/__support/FPUtil/generic/div.h
    libc/src/__support/big_int.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/FPUtil/NearestIntegerOperations.h b/libc/src/__support/FPUtil/NearestIntegerOperations.h
index 741e24aa519a7..cff32938229d0 100644
--- a/libc/src/__support/FPUtil/NearestIntegerOperations.h
+++ b/libc/src/__support/FPUtil/NearestIntegerOperations.h
@@ -199,7 +199,8 @@ round_using_specific_rounding_mode(T x, int rnd) {
     return x;
 
   StorageType trim_value =
-      bits.get_mantissa() & ((StorageType(1) << trim_size) - 1);
+      bits.get_mantissa() &
+      static_cast<StorageType>(((StorageType(1) << trim_size) - 1));
   StorageType half_value =
       static_cast<StorageType>((StorageType(1) << (trim_size - 1)));
   // If exponent is 0, trimSize will be equal to the mantissa width, and

diff  --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index fb1b22467f940..8d44a98a693f8 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -110,7 +110,7 @@ template <size_t Bits> struct DyadicFloat {
               .get_val();
       // volatile prevents constant propagation that would result in infinity
       // always being returned no matter the current rounding mode.
-      volatile T two(2.0);
+      volatile T two = static_cast<T>(2.0);
       T r = two * d_hi;
 
       // TODO: Whether rounding down the absolute value to max_normal should

diff  --git a/libc/src/__support/FPUtil/generic/FMA.h b/libc/src/__support/FPUtil/generic/FMA.h
index d0a01c3092c42..72341a129dcb5 100644
--- a/libc/src/__support/FPUtil/generic/FMA.h
+++ b/libc/src/__support/FPUtil/generic/FMA.h
@@ -266,7 +266,7 @@ fma(InType x, InType y, InType z) {
   }
 
   DyadicFloat result(prod_sign, prod_lsb_exp - InFPBits::EXP_BIAS, prod_mant);
-  result.mantissa |= sticky_bits;
+  result.mantissa |= static_cast<unsigned int>(sticky_bits);
   return result.template as<OutType, /*ShouldSignalExceptions=*/true>();
 }
 

diff  --git a/libc/src/__support/FPUtil/generic/div.h b/libc/src/__support/FPUtil/generic/div.h
index 843d570a0d16b..0d84aa8d8bccc 100644
--- a/libc/src/__support/FPUtil/generic/div.h
+++ b/libc/src/__support/FPUtil/generic/div.h
@@ -97,14 +97,14 @@ div(InType x, InType y) {
 
   // Number of iterations = full output precision + 1 rounding bit + 1 potential
   // leading 0.
-  constexpr size_t NUM_ITERS = OutFPBits::FRACTION_LEN + 3;
+  constexpr int NUM_ITERS = OutFPBits::FRACTION_LEN + 3;
   int result_exp = xd.exponent - yd.exponent - (NUM_ITERS - 1);
 
   InStorageType q = 0;
   InStorageType r = static_cast<InStorageType>(xd.mantissa >> 2);
   InStorageType yd_mant_in = static_cast<InStorageType>(yd.mantissa >> 1);
 
-  for (size_t i = 0; i < NUM_ITERS; ++i) {
+  for (int i = 0; i < NUM_ITERS; ++i) {
     q <<= 1;
     r <<= 1;
     if (r >= yd_mant_in) {
@@ -114,8 +114,7 @@ div(InType x, InType y) {
   }
 
   DyadicFloat result(result_sign, result_exp, q);
-  result.mantissa += r != 0;
-
+  result.mantissa |= static_cast<unsigned int>(r != 0);
   return result.template as<OutType, /*ShouldSignalExceptions=*/true>();
 }
 

diff  --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index 5ce9541d73f68..59a3912ef0f09 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -387,7 +387,8 @@ 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>>>
+  template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T> &&
+                                                    !cpp::is_same_v<T, bool>>>
   LIBC_INLINE constexpr BigInt(T v) {
     constexpr size_t T_SIZE = sizeof(T) * CHAR_BIT;
     const bool is_neg = Signed && (v < 0);
@@ -440,7 +441,7 @@ struct BigInt {
     constexpr size_t MAX_COUNT =
         T_SIZE > Bits ? WORD_COUNT : T_SIZE / WORD_SIZE;
     for (size_t i = 1; i < MAX_COUNT; ++i)
-      lo += static_cast<T>(val[i]) << (WORD_SIZE * i);
+      lo += static_cast<T>(static_cast<T>(val[i]) << (WORD_SIZE * i));
     if constexpr (Signed && (T_SIZE > Bits)) {
       // Extend sign for negative numbers.
       constexpr T MASK = (~T(0) << Bits);


        


More information about the libc-commits mailing list