[libc-commits] [libc] [libc][NFC] Selectively disable GCC warnings (PR #78462)

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Wed Jan 17 13:54:19 PST 2024


https://github.com/gchatelet updated https://github.com/llvm/llvm-project/pull/78462

>From debf7314ce152919dcfdca531526c561d37dc298 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Wed, 17 Jan 2024 16:23:20 +0000
Subject: [PATCH 1/3] [libc][NFC] Selectively disable GCC warnings

---
 libc/src/string/memory_utils/op_x86.h | 7 +++++++
 libc/src/string/memory_utils/utils.h  | 4 +++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libc/src/string/memory_utils/op_x86.h b/libc/src/string/memory_utils/op_x86.h
index 6ae9583627bd6d..f7897a7f9fd720 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 5cd716e033d6a4..543d45b7c4e33e 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

>From 3d371cd721860fd335804f299e68a14e952ff35c Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Wed, 17 Jan 2024 18:13:26 +0000
Subject: [PATCH 2/3] Provide a better explanation

---
 libc/src/string/memory_utils/op_x86.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libc/src/string/memory_utils/op_x86.h b/libc/src/string/memory_utils/op_x86.h
index f7897a7f9fd720..4978c64aa5e8df 100644
--- a/libc/src/string/memory_utils/op_x86.h
+++ b/libc/src/string/memory_utils/op_x86.h
@@ -25,8 +25,11 @@
 #include <immintrin.h>
 #endif
 
-// Disable GCC complaining about missing attributes when using SIMD types in
-// template specializations.
+// SIMD types are defined with attributes. e.g., '__m128i' is defined as
+// long long  __attribute__((__vector_size__(16), __aligned__(16)))
+// When we use these SIMD types in template specialization GCC complains:
+// "ignoring attributes on template argument ‘__m128i’ [-Wignored-attributes]"
+// Therefore, we disable this warning in this file.
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wignored-attributes"
 

>From 2ff7367fce5ee41b9fdc7243542dec42f45f943c Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Wed, 17 Jan 2024 21:53:25 +0000
Subject: [PATCH 3/3] Reduce region with disabled warnings

---
 libc/src/string/memory_utils/op_x86.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libc/src/string/memory_utils/op_x86.h b/libc/src/string/memory_utils/op_x86.h
index 4978c64aa5e8df..2852636c48a74d 100644
--- a/libc/src/string/memory_utils/op_x86.h
+++ b/libc/src/string/memory_utils/op_x86.h
@@ -25,14 +25,6 @@
 #include <immintrin.h>
 #endif
 
-// SIMD types are defined with attributes. e.g., '__m128i' is defined as
-// long long  __attribute__((__vector_size__(16), __aligned__(16)))
-// When we use these SIMD types in template specialization GCC complains:
-// "ignoring attributes on template argument ‘__m128i’ [-Wignored-attributes]"
-// Therefore, we disable this warning in this file.
-#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__))
@@ -124,6 +116,14 @@ LIBC_INLINE MemcmpReturnType cmp_neq<uint64_t>(CPtr p1, CPtr p2,
   return cmp_neq_uint64_t(a, b);
 }
 
+// SIMD types are defined with attributes. e.g., '__m128i' is defined as
+// long long  __attribute__((__vector_size__(16), __aligned__(16)))
+// When we use these SIMD types in template specialization GCC complains:
+// "ignoring attributes on template argument ‘__m128i’ [-Wignored-attributes]"
+// Therefore, we disable this warning in this file.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wignored-attributes"
+
 ///////////////////////////////////////////////////////////////////////////////
 // Specializations for __m128i
 #if defined(__SSE4_1__)
@@ -312,10 +312,10 @@ LIBC_INLINE MemcmpReturnType cmp_neq<__m512i>(CPtr p1, CPtr p2, size_t offset) {
 }
 #endif // __AVX512BW__
 
-} // namespace LIBC_NAMESPACE::generic
-
 #pragma GCC diagnostic pop
 
+} // namespace LIBC_NAMESPACE::generic
+
 #endif // LIBC_TARGET_ARCH_IS_X86_64
 
 #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_X86_H



More information about the libc-commits mailing list