[flang-commits] [flang] [flang] Unify return value of memcpy and memmove (PR #174048)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Tue Dec 30 17:07:13 PST 2025


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/174048

memcpy and memmove function are not all returning a void*. Unify this so it doesn't make other errors like in #172568

>From a05c43aa4a2868e6cb6ba3fe3eda5b3fe4b5f529 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 30 Dec 2025 17:05:34 -0800
Subject: [PATCH] [flang] Unify return value of memcpy and memmove

---
 flang/include/flang/Runtime/freestanding-tools.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/flang/include/flang/Runtime/freestanding-tools.h b/flang/include/flang/Runtime/freestanding-tools.h
index 42129328d0b02..75843b4e53c58 100644
--- a/flang/include/flang/Runtime/freestanding-tools.h
+++ b/flang/include/flang/Runtime/freestanding-tools.h
@@ -117,9 +117,10 @@ using std::memset;
 #endif
 
 #if STD_MEMCPY_USE_BUILTIN
-static inline RT_API_ATTRS void memcpy(
+static inline RT_API_ATTRS void *memcpy(
     void *dest, const void *src, std::size_t count) {
   __builtin_memcpy(dest, src, count);
+  return dest;
 }
 #elif STD_MEMCPY_UNSUPPORTED
 static inline RT_API_ATTRS void *memcpy(
@@ -127,7 +128,7 @@ static inline RT_API_ATTRS void *memcpy(
   char *to{reinterpret_cast<char *>(dest)};
   const char *from{reinterpret_cast<const char *>(src)};
   if (to == from) {
-    return;
+    return dest;
   }
   while (count--) {
     *to++ = *from++;
@@ -139,9 +140,10 @@ using std::memcpy;
 #endif
 
 #if STD_MEMMOVE_USE_BUILTIN
-static inline RT_API_ATTRS void memmove(
+static inline RT_API_ATTRS void *memmove(
     void *dest, const void *src, std::size_t count) {
   __builtin_memmove(dest, src, count);
+  return dest;
 }
 #elif STD_MEMMOVE_UNSUPPORTED
 // Provides alternative implementation for std::memmove(), if
@@ -156,6 +158,7 @@ static inline RT_API_ATTRS void *memmove(
   }
   if (to + count <= from || from + count <= to) {
     memcpy(dest, src, count);
+    return dest;
   } else if (to < from) {
     while (count--) {
       *to++ = *from++;



More information about the flang-commits mailing list