Skip to content

Commit

Permalink
[libc] fix -Warray-bounds in block_offset (#77001)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nickdesaulniers committed Jan 5, 2024
1 parent e297238 commit 5352ce3
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions libc/src/string/memory_utils/op_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5352ce3

Please sign in to comment.