Skip to content

[libc] fix -Warray-bounds in block_offset #77001

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 1 commit into from
Jan 5, 2024

Conversation

nickdesaulniers
Copy link
Member

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: #76877

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: llvm#76877
@llvmbot
Copy link
Member

llvmbot commented Jan 4, 2024

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

Changes

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: #76877


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

1 Files Affected:

  • (modified) libc/src/string/memory_utils/op_builtin.h (+1-7)
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) {

@nickdesaulniers nickdesaulniers merged commit 5352ce3 into llvm:main Jan 5, 2024
@nickdesaulniers nickdesaulniers deleted the Warray-size branch January 5, 2024 16:19
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.

[libc] -Warray-bounds= in libc/src/string/memory_utils/op_builtin.h
3 participants