[libc-commits] [PATCH] D152507: Directly return 0 in memcmp/bcmp when input pointers point to same memory location

xiongji90 via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Jun 9 02:08:33 PDT 2023


xiongji90 created this revision.
xiongji90 added a reviewer: gchatelet.
Herald added projects: libc-project, All.
Herald added a subscriber: libc-commits.
xiongji90 requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152507

Files:
  libc/src/string/memory_utils/bcmp_implementations.h
  libc/src/string/memory_utils/x86_64/memcmp_implementations.h


Index: libc/src/string/memory_utils/x86_64/memcmp_implementations.h
===================================================================
--- libc/src/string/memory_utils/x86_64/memcmp_implementations.h
+++ libc/src/string/memory_utils/x86_64/memcmp_implementations.h
@@ -70,7 +70,7 @@
 
 LIBC_INLINE MemcmpReturnType inline_memcmp_x86(CPtr p1, CPtr p2, size_t count) {
 
-  if (count == 0)
+  if (count == 0 || p1 == p2)
     return MemcmpReturnType::ZERO();
   if (count == 1)
     return generic::Memcmp<1>::block(p1, p2);
Index: libc/src/string/memory_utils/bcmp_implementations.h
===================================================================
--- libc/src/string/memory_utils/bcmp_implementations.h
+++ libc/src/string/memory_utils/bcmp_implementations.h
@@ -143,7 +143,7 @@
 
 [[maybe_unused]] LIBC_INLINE BcmpReturnType inline_bcmp_x86(CPtr p1, CPtr p2,
                                                             size_t count) {
-  if (count == 0)
+  if (count == 0 || p1 == p2)
     return BcmpReturnType::ZERO();
   if (count == 1)
     return generic::Bcmp<1>::block(p1, p2);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152507.529861.patch
Type: text/x-patch
Size: 1091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230609/0778ba52/attachment.bin>


More information about the libc-commits mailing list