[libc-commits] [libc] 5352ce3 - [libc] fix -Warray-bounds in block_offset (#77001)

via libc-commits libc-commits at lists.llvm.org
Fri Jan 5 08:19:08 PST 2024


Author: Nick Desaulniers
Date: 2024-01-05T08:19:04-08:00
New Revision: 5352ce32fccd37c54aff2b3a2b0e3ca5115bb8a9

URL: https://github.com/llvm/llvm-project/commit/5352ce32fccd37c54aff2b3a2b0e3ca5115bb8a9
DIFF: https://github.com/llvm/llvm-project/commit/5352ce32fccd37c54aff2b3a2b0e3ca5115bb8a9.diff

LOG: [libc] fix -Warray-bounds in block_offset (#77001)

GCC reports an instance of -Warray-bounds in block_offset.  Reimplement
block_offset in terms of memcpy_inline which was created to avoid this
diagnostic. See the linked issue for the full trace of diagnostic.

Fixes: https://github.com/llvm/llvm-project/issues/76877

Added: 
    

Modified: 
    libc/src/string/memory_utils/op_builtin.h

Removed: 
    


################################################################################
diff  --git a/libc/src/string/memory_utils/op_builtin.h b/libc/src/string/memory_utils/op_builtin.h
index 16c9f519c37e3f..3c17eef781e576 100644
--- a/libc/src/string/memory_utils/op_builtin.h
+++ b/libc/src/string/memory_utils/op_builtin.h
@@ -26,13 +26,7 @@ template <size_t Size> struct Memcpy {
   static constexpr size_t SIZE = Size;
   LIBC_INLINE static void block_offset(Ptr __restrict dst, CPtr __restrict src,
                                        size_t offset) {
-#ifdef LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE
-    return __builtin_memcpy_inline(dst + offset, src + offset, SIZE);
-#else
-    // The codegen may be suboptimal.
-    for (size_t i = 0; i < Size; ++i)
-      dst[i + offset] = src[i + offset];
-#endif
+    memcpy_inline<Size>(dst + offset, src + offset);
   }
 
   LIBC_INLINE static void block(Ptr __restrict dst, CPtr __restrict src) {


        


More information about the libc-commits mailing list