-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[libc] Suppress GCC loop optimization warning #132458
Open
jhuber6
wants to merge
1
commit into
llvm:main
Choose a base branch
from
jhuber6:warning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/132458.diff 1 Files Affected:
diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index 85db31d01399a..2a4a72e30b352 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -790,11 +790,17 @@ struct BigInt {
remainder[pos] = rem;
}
+ // GCC currently emits a false-positive warning on this for some compilers.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Waggressive-loop-optimizations"
+
// Set the remaining lower bits of the remainder.
for (; pos > 0; --pos) {
remainder[pos - 1] = val[pos - 1];
}
+#pragma GCC diagnostic pop
+
*this = quotient;
return remainder;
}
@@ -851,8 +857,8 @@ struct BigInt {
result[i] = lhs[i] OP rhs[i]; \
return result; \
} \
- LIBC_INLINE friend constexpr BigInt operator OP##=(BigInt &lhs, \
- const BigInt &rhs) { \
+ LIBC_INLINE friend constexpr BigInt operator OP## = \
+ (BigInt & lhs, const BigInt &rhs) { \
for (size_t i = 0; i < WORD_COUNT; ++i) \
lhs[i] OP## = rhs[i]; \
return lhs; \
|
You can test this locally with the following command:git-clang-format --diff 3757ecf5f16c0d9b8cbfc1c9d41965df537d43e6 7cdeffa47c66a966a5c53ba863f763f2f6a01107 --extensions h -- libc/src/__support/big_int.h View the diff from clang-format here.diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index 25dddfef9c..c4b2345c49 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -861,8 +861,8 @@ public:
result[i] = lhs[i] OP rhs[i]; \
return result; \
} \
- LIBC_INLINE friend constexpr BigInt operator OP## = \
- (BigInt & lhs, const BigInt &rhs) { \
+ LIBC_INLINE friend constexpr BigInt operator OP##=(BigInt &lhs, \
+ const BigInt &rhs) { \
for (size_t i = 0; i < WORD_COUNT; ++i) \
lhs[i] OP## = rhs[i]; \
return lhs; \
|
Summary: This appears to be a false positive on some versions of GCC.
petrhosek
approved these changes
Mar 22, 2025
Look like you need to guard this for gcc only:
|
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.
Summary:
This appears to be a false positive on some versions of GCC.