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

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Wed Dec 31 10:19:53 PST 2025


Valentin Clement =?utf-8?b?KOODkOODrOODsw=?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/174048 at github.com>


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

>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 1/2] [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++;

>From 3741462973c81f17d06cfc499f37379b02cfa69b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Valentin=20Clement=20=28=E3=83=90=E3=83=AC=E3=83=B3?=
 =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=B3=20=E3=82=AF=E3=83=AC=E3=83=A1?=
 =?UTF-8?q?=E3=83=B3=29?= <clementval at gmail.com>
Date: Wed, 31 Dec 2025 10:19:44 -0800
Subject: [PATCH 2/2] Apply suggestion from @clementval

---
 flang/include/flang/Runtime/freestanding-tools.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/flang/include/flang/Runtime/freestanding-tools.h b/flang/include/flang/Runtime/freestanding-tools.h
index 75843b4e53c58..4469cb9eeee98 100644
--- a/flang/include/flang/Runtime/freestanding-tools.h
+++ b/flang/include/flang/Runtime/freestanding-tools.h
@@ -158,7 +158,6 @@ 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