[llvm-branch-commits] [llvm] RuntimeLibcalls: Add attributes to printf variants (PR #244649)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Nov 20 11:46:09 PST 2026
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/244649
>From 49826457d0b86539b458534465e92e7dc5982597 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 20 Nov 2026 11:27:40 -0500
Subject: [PATCH] RuntimeLibcalls: Add attributes to printf variants
Give the integer-only and size-optimized printf variants the
attributes of the corresponding printf functions.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
---
llvm/include/llvm/IR/RuntimeLibcalls.td | 12 ++++++------
.../Util/DeclareRuntimeLibcalls/emscripten.ll | 8 +++++---
.../Transforms/Util/DeclareRuntimeLibcalls/xcore.ll | 8 +++++---
3 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index dc12c86d790c10..78a8de4ef75291 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -1416,7 +1416,7 @@ def FILENO : RuntimeLibcall<Int, [Ptr]> {
let ParamAttrs = [[CapturesNone, NoUndef]];
}
-def FIPRINTF : RuntimeLibcall<Int, [Ptr, Ptr, Ellip]>;
+def FIPRINTF : FPrintfLibcall;
def FLOCKFILE : RuntimeLibcall<Void, [Ptr]> {
let FnAttrs = [NoFree, NoUnwind];
let ParamAttrs = [[CapturesNone, NoUndef]];
@@ -1641,7 +1641,7 @@ def GETTIMEOFDAY : RuntimeLibcall<Int, [Ptr, Ptr]> {
def HTONL : PureLibcall<UInt32, [UInt32]>;
def HTONS : PureLibcall<UInt16, [UInt16]>;
-def IPRINTF : RuntimeLibcall<Int, [Ptr, Ellip]>;
+def IPRINTF : PrintfLibcall;
def ISASCII : RuntimeLibcall<Int, [Int]> {
let FnAttrs = CommonFnAttrs;
}
@@ -1924,16 +1924,16 @@ def SETVBUF : RuntimeLibcall<Int, [Ptr, Ptr, Int, SizeT]> {
let ParamAttrs = [[CapturesNone, NoUndef], [NoUndef], [NoUndef], [NoUndef]];
}
-def SIPRINTF : RuntimeLibcall<Int, [Ptr, Ptr, Ellip]>;
+def SIPRINTF : SPrintfLibcall;
def SizedPtr : StructFuncArgType<[Ptr, SizeT]>;
def SIZE_RETURNING_NEW : RuntimeLibcall<SizedPtr, [SizeT]>;
def SIZE_RETURNING_NEW_ALIGNED : RuntimeLibcall<SizedPtr, [SizeT, AlignValT]>;
def SIZE_RETURNING_NEW_ALIGNED_HOT_COLD
: RuntimeLibcall<SizedPtr, [SizeT, AlignValT, UInt8]>;
def SIZE_RETURNING_NEW_HOT_COLD : RuntimeLibcall<SizedPtr, [SizeT, UInt8]>;
-def SMALL_FPRINTF : RuntimeLibcall<Int, [Ptr, Ptr, Ellip]>;
-def SMALL_PRINTF : RuntimeLibcall<Int, [Ptr, Ellip]>;
-def SMALL_SPRINTF : RuntimeLibcall<Int, [Ptr, Ptr, Ellip]>;
+def SMALL_FPRINTF : FPrintfLibcall;
+def SMALL_PRINTF : PrintfLibcall;
+def SMALL_SPRINTF : SPrintfLibcall;
def SNPRINTF : RuntimeLibcall<Int, [Ptr, SizeT, Ptr, Ellip]> {
let FnAttrs = [NoFree, NoUnwind];
let RetAttrs = [NoUndef];
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/emscripten.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/emscripten.ll
index b04a6d958d396b..c2c2cb5e62337d 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/emscripten.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/emscripten.ll
@@ -1,6 +1,8 @@
; REQUIRES: webassembly-registered-target
; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=wasm64-unknown-emscripten < %s | FileCheck %s
-; CHECK: declare i32 @__small_fprintf(ptr, ptr, ...)
-; CHECK: declare i32 @__small_printf(ptr, ...)
-; CHECK: declare i32 @__small_sprintf(ptr, ptr, ...)
+; CHECK: declare noundef i32 @__small_fprintf(ptr noundef captures(none), ptr noundef readonly captures(none), ...) [[PRINTF_ATTRS:#[0-9]+]]
+; CHECK: declare noundef i32 @__small_printf(ptr noundef readonly captures(none), ...) [[PRINTF_ATTRS]]
+; CHECK: declare noundef i32 @__small_sprintf(ptr noalias noundef writeonly captures(none), ptr noundef readonly captures(none), ...) [[PRINTF_ATTRS]]
+
+; CHECK: attributes [[PRINTF_ATTRS]] = { nofree nounwind }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/xcore.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/xcore.ll
index 8fe3aa86290260..264e69fb8a3346 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/xcore.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/xcore.ll
@@ -1,6 +1,8 @@
; REQUIRES: webassembly-registered-target
; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=xcore < %s | FileCheck %s
-; CHECK: declare i32 @fiprintf(ptr, ptr, ...)
-; CHECK: declare i32 @iprintf(ptr, ...)
-; CHECK: declare i32 @siprintf(ptr, ptr, ...)
+; CHECK: declare noundef i32 @fiprintf(ptr noundef captures(none), ptr noundef readonly captures(none), ...) [[PRINTF_ATTRS:#[0-9]+]]
+; CHECK: declare noundef i32 @iprintf(ptr noundef readonly captures(none), ...) [[PRINTF_ATTRS]]
+; CHECK: declare noundef i32 @siprintf(ptr noalias noundef writeonly captures(none), ptr noundef readonly captures(none), ...) [[PRINTF_ATTRS]]
+
+; CHECK: attributes [[PRINTF_ATTRS]] = { nofree nounwind }
More information about the llvm-branch-commits
mailing list