Skip to content

[libc] Fix compilation errors that occur when building with GCC #96976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

overmighty
Copy link
Member

No description provided.

@llvmbot llvmbot added the libc label Jun 27, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 27, 2024

@llvm/pr-subscribers-libc

Author: OverMighty (overmighty)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/96976.diff

5 Files Affected:

  • (modified) libc/src/__support/FPUtil/NearestIntegerOperations.h (+2-1)
  • (modified) libc/src/__support/FPUtil/dyadic_float.h (+1-1)
  • (modified) libc/src/__support/FPUtil/generic/FMA.h (+1-1)
  • (modified) libc/src/__support/FPUtil/generic/div.h (+3-4)
  • (modified) libc/src/__support/big_int.h (+3-2)
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);

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, feel free to land before presubmits finish to fix the buildbot

@michaelrj-google michaelrj-google merged commit 7a03666 into llvm:main Jun 27, 2024
5 of 7 checks passed
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants