Skip to content
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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Mar 21, 2025

Summary:
This appears to be a false positive on some versions of GCC.

@llvmbot
Copy link
Member

llvmbot commented Mar 21, 2025

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

Changes

Summary:
This appears to be a false positive on some versions of GCC.


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

1 Files Affected:

  • (modified) libc/src/__support/big_int.h (+8-2)
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;                                                                \

Copy link

github-actions bot commented Mar 21, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

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.
@lntue
Copy link
Contributor

lntue commented Mar 22, 2025

Look like you need to guard this for gcc only:

/home/runner/work/llvm-project/llvm-project/libc/src/__support/big_int.h:796:32: error: unknown warning group '-Waggressive-loop-optimizations', ignored [-Werror,-Wunknown-warning-option]
  796 | #pragma GCC diagnostic ignored "-Waggressive-loop-optimizations"

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.

4 participants