-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
michaelrj-google
merged 1 commit into
llvm:main
from
overmighty:libc-fix-gcc-compilation-errors
Jun 27, 2024
Merged
[libc] Fix compilation errors that occur when building with GCC #96976
michaelrj-google
merged 1 commit into
llvm:main
from
overmighty:libc-fix-gcc-compilation-errors
Jun 27, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-libc Author: OverMighty (overmighty) ChangesFull diff: https://github.com/llvm/llvm-project/pull/96976.diff 5 Files Affected:
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);
|
michaelrj-google
approved these changes
Jun 27, 2024
There was a problem hiding this 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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.