[libc-commits] [PATCH] D115542: [libc] fix memcpy builtin looping

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Dec 10 10:59:00 PST 2021


michaelrj created this revision.
michaelrj added reviewers: gchatelet, sivachandra, lntue.
Herald added subscribers: libc-commits, ecnelises, tschuett, mgorny.
Herald added a project: libc-project.
michaelrj requested review of this revision.

previously, memcpy could get stuck in a loop, calling __builtin_memcpy
which would redirect to itself. This removes that path, and adds compile
options to prevent the compiler from generating that by itself.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115542

Files:
  libc/cmake/modules/LLVMLibCLibraryRules.cmake
  libc/src/string/memory_utils/CMakeLists.txt
  libc/src/string/memory_utils/elements.h


Index: libc/src/string/memory_utils/elements.h
===================================================================
--- libc/src/string/memory_utils/elements.h
+++ libc/src/string/memory_utils/elements.h
@@ -511,8 +511,6 @@
     // __builtin_memcpy_inline guarantees to never call external functions.
     // Unfortunately it is not widely available.
     __builtin_memcpy_inline(dst, src, SIZE);
-#elif __has_builtin(__builtin_memcpy)
-    __builtin_memcpy(dst, src, SIZE);
 #else
     for_loop_copy(dst, src);
 #endif
Index: libc/src/string/memory_utils/CMakeLists.txt
===================================================================
--- libc/src/string/memory_utils/CMakeLists.txt
+++ libc/src/string/memory_utils/CMakeLists.txt
@@ -15,6 +15,8 @@
     memcpy_implementations.h
   DEPS
     .memory_utils
+  COMPILE_OPTIONS
+    "-fno-builtin-memcpy"
 )
 
 add_header_library(
Index: libc/cmake/modules/LLVMLibCLibraryRules.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCLibraryRules.cmake
+++ libc/cmake/modules/LLVMLibCLibraryRules.cmake
@@ -136,7 +136,7 @@
     "ADD_HEADER"
     "" # No optional arguments
     "" # No Single value arguments
-    "HDRS;DEPENDS" # Multi-value arguments
+    "HDRS;DEPENDS;COMPILE_OPTIONS" # Multi-value arguments
     ${ARGN}
   )
 
@@ -161,6 +161,9 @@
   if(ADD_HEADER_DEPENDS)
     add_dependencies(${interface_target_name} ${fq_deps_list})
   endif()
+  if(ADD_HEADER_COMPILE_OPTIONS)
+    target_compile_options(${interface_target_name} INTERFACE ${ADD_HEADER_COMPILE_OPTIONS})
+  endif()
 
   add_custom_target(${fq_target_name})
   add_dependencies(${fq_target_name} ${interface_target_name})


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115542.393545.patch
Type: text/x-patch
Size: 1698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20211210/77a97518/attachment.bin>


More information about the libc-commits mailing list