[libcxx-commits] [libcxx] [libc++] Remove zero size branch from memmove (PR #155419)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 27 00:09:34 PDT 2025


https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/155419

>From 2bc86be3decc44f4f6ab94ec1c417664a96f7b20 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 26 Aug 2025 15:47:33 +0200
Subject: [PATCH] [libc++] Remove zero size branch from memmove

---
 libcxx/include/__string/constexpr_c_functions.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/include/__string/constexpr_c_functions.h b/libcxx/include/__string/constexpr_c_functions.h
index 119669e16bbcf..160d2af10950f 100644
--- a/libcxx/include/__string/constexpr_c_functions.h
+++ b/libcxx/include/__string/constexpr_c_functions.h
@@ -22,7 +22,6 @@
 #include <__type_traits/is_equality_comparable.h>
 #include <__type_traits/is_integral.h>
 #include <__type_traits/is_same.h>
-#include <__type_traits/is_trivially_copyable.h>
 #include <__type_traits/is_trivially_lexicographically_comparable.h>
 #include <__type_traits/remove_cv.h>
 #include <__utility/element_count.h>
@@ -225,6 +224,8 @@ __constexpr_memmove(_Tp* __dest, _Up* __src, __element_count __n) {
           std::__assign_trivially_copyable(__dest[__i], __src[__i]);
       }
     }
+  } else if _LIBCPP_CONSTEXPR (sizeof(_Tp) == __datasizeof_v<_Tp>) {
+    ::__builtin_memmove(__dest, __src, __count * sizeof(_Tp));
   } else if (__count > 0) {
     ::__builtin_memmove(__dest, __src, (__count - 1) * sizeof(_Tp) + __datasizeof_v<_Tp>);
   }



More information about the libcxx-commits mailing list