https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/167053

>From e5510192d0f6f17d6a69b882c3e008629509ccbc Mon Sep 17 00:00:00 2001
From: Matt Arsenault <[email protected]>
Date: Fri, 7 Nov 2025 15:27:24 -0800
Subject: [PATCH] RuntimeLibcalls: Add __memcpy_chk, __memmove_chk,
 __memset_chk

These were in TargetLibraryInfo, but missing from RuntimeLibcalls.
This only adds the cases that already have the non-chk variants
already. Copies the enabled-by-default logic from TargetLibraryInfo,
which is probably overly permissive. Only isPS opts-out.
---
 llvm/include/llvm/IR/RuntimeLibcalls.td         | 17 +++++++++++++++--
 .../Util/DeclareRuntimeLibcalls/basic.ll        |  4 ++++
 .../Util/DeclareRuntimeLibcalls/ps.ll           |  6 ++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ps.ll

diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td 
b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 3fb55ad40e71b..f6ad23a4f9c49 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -35,6 +35,9 @@ def isNotOSLinuxAndNotOSOpenBSD : RuntimeLibcallPredicate<
 def isNotOSAIXAndNotOSOpenBSD : RuntimeLibcallPredicate<
   [{!TT.isOSAIX() && !TT.isOSOpenBSD()}]>;
 
+def isNotPS : RuntimeLibcallPredicate<
+  [{!TT.isPS()}]>;
+
 // OpenBSD uses __guard_local. AIX uses __ssp_canary_word, MSVC/Windows
 // Itanium uses __security_cookie
 def hasStackChkFail : RuntimeLibcallPredicate<
@@ -374,8 +377,11 @@ foreach FPTy = ["F32", "F64", "F128", "PPCF128"] in {
 // Memory
 def MEMCMP : RuntimeLibcall;
 def MEMCPY : RuntimeLibcall;
+def MEMCPY_CHK : RuntimeLibcall;
 def MEMMOVE : RuntimeLibcall;
+def MEMMOVE_CHK : RuntimeLibcall;
 def MEMSET : RuntimeLibcall;
+def MEMSET_CHK : RuntimeLibcall;
 def CALLOC : RuntimeLibcall;
 def BZERO : RuntimeLibcall;
 def STRLEN : RuntimeLibcall;
@@ -1091,6 +1097,10 @@ def memcpy : RuntimeLibcallImpl<MEMCPY>;
 def memmove : RuntimeLibcallImpl<MEMMOVE>;
 def memset : RuntimeLibcallImpl<MEMSET>;
 
+def __memcpy_chk : RuntimeLibcallImpl<MEMCPY_CHK>;
+def __memmove_chk : RuntimeLibcallImpl<MEMMOVE_CHK>;
+def __memset_chk : RuntimeLibcallImpl<MEMSET_CHK>;
+
 // DSEPass can emit calloc if it finds a pair of malloc/memset
 def calloc : RuntimeLibcallImpl<CALLOC>;
 
@@ -2624,8 +2634,10 @@ defvar X86_F128_Libcalls = LibcallImpls<(add 
LibmF128Libcalls, LibmF128FiniteLib
 
 defvar SinCosF32F64Libcalls = LibcallImpls<(add sincosf, sincos), 
hasSinCos_f32_f64>;
 
+defvar MemChkLibcalls = [__memcpy_chk, __memset_chk, __memmove_chk];
+
 defvar X86CommonLibcalls =
-  (add (sub WinDefaultLibcallImpls, WindowsDivRemMulLibcallOverrides),
+  (add (sub WinDefaultLibcallImpls, WindowsDivRemMulLibcallOverrides, 
MemChkLibcalls),
        DarwinSinCosStret, DarwinExp10,
        X86_F128_Libcalls,
        LibmHasSinCosF80, // FIXME: Depends on long double
@@ -2641,7 +2653,8 @@ defvar X86CommonLibcalls =
        // FIXME: MSVCRT doesn't have powi. The f128 case is added as a
        // hack for one test relying on it.
        __powitf2_f128,
-       DefaultStackProtector
+       DefaultStackProtector,
+       LibcallImpls<(add MemChkLibcalls), isNotPS>
      );
 
 defvar Windows32DivRemMulCalls =
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll 
b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll
index be8cae261c7bf..db0cc24c287bc 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll
@@ -12,6 +12,10 @@ define float @sinf(float %x) {
 
 ; CHECK: declare void @_Unwind_Resume(...)
 
+; CHECK: declare void @__memcpy_chk(...)
+; CHECK: declare void @__memmove_chk(...)
+; CHECK: declare void @__memset_chk(...)
+
 ; CHECK: declare void @__umodti3(...)
 
 ; CHECK: declare void @acosf(...)
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ps.ll 
b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ps.ll
new file mode 100644
index 0000000000000..bcdcc63400f72
--- /dev/null
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ps.ll
@@ -0,0 +1,6 @@
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-scei-ps4 < %s | 
FileCheck %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-scei-ps5 < %s | 
FileCheck %s
+
+; CHECK-NOT: __memcpy_chk
+; CHECK-NOT: __memset_chk
+; CHECK-NOT: __memmove_chk

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to