Skip to content

[libc][NFC] Selectively disable GCC warnings #78462

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
merged 3 commits into from
Jan 18, 2024

Conversation

gchatelet
Copy link
Contributor

No description provided.

@gchatelet gchatelet marked this pull request as ready for review January 17, 2024 16:24
@llvmbot llvmbot added the libc label Jan 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2024

@llvm/pr-subscribers-libc

Author: Guillaume Chatelet (gchatelet)

Changes

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

2 Files Affected:

  • (modified) libc/src/string/memory_utils/op_x86.h (+7)
  • (modified) libc/src/string/memory_utils/utils.h (+3-1)
diff --git a/libc/src/string/memory_utils/op_x86.h b/libc/src/string/memory_utils/op_x86.h
index 6ae9583627bd6d3..f7897a7f9fd7205 100644
--- a/libc/src/string/memory_utils/op_x86.h
+++ b/libc/src/string/memory_utils/op_x86.h
@@ -25,6 +25,11 @@
 #include <immintrin.h>
 #endif
 
+// Disable GCC complaining about missing attributes when using SIMD types in
+// template specializations.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wignored-attributes"
+
 // Define fake functions to prevent the compiler from failing on undefined
 // functions in case the CPU extension is not present.
 #if !defined(__AVX512BW__) && (defined(_MSC_VER) || defined(__SCE__))
@@ -306,6 +311,8 @@ LIBC_INLINE MemcmpReturnType cmp_neq<__m512i>(CPtr p1, CPtr p2, size_t offset) {
 
 } // namespace LIBC_NAMESPACE::generic
 
+#pragma GCC diagnostic pop
+
 #endif // LIBC_TARGET_ARCH_IS_X86_64
 
 #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_X86_H
diff --git a/libc/src/string/memory_utils/utils.h b/libc/src/string/memory_utils/utils.h
index 5cd716e033d6a4c..543d45b7c4e33e3 100644
--- a/libc/src/string/memory_utils/utils.h
+++ b/libc/src/string/memory_utils/utils.h
@@ -89,9 +89,11 @@ LIBC_INLINE void memcpy_inline(void *__restrict dst,
   // In memory functions `memcpy_inline` is instantiated several times with
   // different value of the Size parameter. This doesn't play well with GCC's
   // Value Range Analysis that wrongly detects out of bounds accesses. We
-  // disable the 'array-bounds' warning for the purpose of this function.
+  // disable these warnings for the purpose of this function.
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Warray-bounds"
+#pragma GCC diagnostic ignored "-Wstringop-overread"
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
   for (size_t i = 0; i < Size; ++i)
     static_cast<char *>(dst)[i] = static_cast<const char *>(src)[i];
 #pragma GCC diagnostic pop

Comment on lines 28 to 29
// Disable GCC complaining about missing attributes when using SIMD types in
// template specializations.
Copy link
Member

Choose a reason for hiding this comment

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

Which attributes is it complaining about? Mind adding that to the commit message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't say which ones ☹

[17/29] Building CXX object projects/libc/test/src/__support/FPUtil/CMakeFiles/libc.test.src.__support.FPUtil.fpbits_test.__unit__.__build__.dir/fpbits_test.cpp.o
In file included from /redacted/gchatelet/git/llvm-project/libc/src/string/memory_utils/x86_64/inline_memcpy.h:15,
                 from /redacted/gchatelet/git/llvm-project/libc/src/string/memory_utils/inline_memcpy.h:22,
                 from /redacted/gchatelet/git/llvm-project/libc/src/__support/CPP/string.h:14,
                 from /redacted/gchatelet/git/llvm-project/libc/src/__support/FPUtil/fpbits_str.h:12,
                 from /redacted/gchatelet/git/llvm-project/libc/test/src/__support/FPUtil/fpbits_test.cpp:10:
/redacted/gchatelet/git/llvm-project/libc/src/string/memory_utils/op_x86.h:122:37: warning: ignoring attributes on template argument ‘__m128i’ [-Wignored-attributes]
  122 | template <> struct is_vector<__m128i> : cpp::true_type {};
      |                                     ^
/redacted/gchatelet/git/llvm-project/libc/src/string/memory_utils/op_x86.h:123:44: warning: ignoring attributes on template argument ‘__m128i’ [-Wignored-attributes]
  123 | template <> struct cmp_is_expensive<__m128i> : cpp::true_type {};
      |                                            ^
/redacted/gchatelet/git/llvm-project/libc/src/string/memory_utils/op_x86.h:162:37: warning: ignoring attributes on template argument ‘__m256i’ [-Wignored-attributes]
  162 | template <> struct is_vector<__m256i> : cpp::true_type {};
      |                                     ^
/redacted/gchatelet/git/llvm-project/libc/src/string/memory_utils/op_x86.h:163:44: warning: ignoring attributes on template argument ‘__m256i’ [-Wignored-attributes]
  163 | template <> struct cmp_is_expensive<__m256i> : cpp::true_type {};
      |                                            ^

Copy link
Contributor Author

@gchatelet gchatelet Jan 17, 2024

Choose a reason for hiding this comment

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

Looking at __m256i definition

/usr/lib/llvm-16/lib/clang/16/include/avxintrin.h:typedef long long __m256i __attribute__((__vector_size__(32), __aligned__(32)));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried a better explanation, let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

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

ah, yeah https://stackoverflow.com/questions/41676311/implication-of-gcc-warning-ignoring-attributes-on-template-argument-wignored has more context. I was just looking at /usr/lib/gcc/x86_64-linux-gnu/13/include/avxintrin.h myself.

Do you mind mimimizing the region of code for which the pragma is disabled? I think the initial push+disable could be "sunk" lower in the header. That might help avoid false negatives that result from disabling the diagnostics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing. Done!

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

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

nice work, thank you!

@gchatelet gchatelet merged commit bc4f3e3 into llvm:main Jan 18, 2024
@gchatelet gchatelet deleted the remove_gcc_warning_false_positives branch January 18, 2024 09:36
ampandey-1995 pushed a commit to ampandey-1995/llvm-project that referenced this pull request Jan 19, 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