[llvm-branch-commits] [llvm] [RuntimeLibcalls] Add wchar_t support (PR #241681)
Sergei Barannikov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Nov 16 22:19:41 PST 2026
https://github.com/s-barannikov updated https://github.com/llvm/llvm-project/pull/241681
>From 602ecd3164deb8c2ff1e48e9407126ddc68d373e Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Thu, 12 Nov 2026 07:52:21 +0300
Subject: [PATCH] [RuntimeLibcalls] Model wchar_t arguments in libcall
signatures
RuntimeLibcalls could describe int, size_t and several other C types
but had no way to describe wchar_t, so a libcall taking one could not
be declared with the correct parameter type and extension attribute.
The width of wchar_t is not a property of the triple alone: it can be
overridden by the wchar_size module flag, as -fshort-wchar does.
Add a WChar FuncArgType that converts to an integer of
Module::getWCharSize() bits, and derive its extension attribute in
RuntimeLibcallsInfo::getExtAttrForWCharParam.
Declare wmemset using the new type. A wchar_t as wide as int is
sign-extended wherever int is, so targets such as RISC-V, MIPS, PowerPC
and SystemZ now get signext on it, while AIX, z/OS and VE, where it is
unsigned, get zeroext.
Assisted-by: Claude
---
llvm/include/llvm/IR/RuntimeLibcalls.h | 5 ++
llvm/include/llvm/IR/RuntimeLibcalls.td | 2 +
llvm/include/llvm/IR/RuntimeLibcallsImpl.td | 1 +
llvm/lib/IR/RuntimeLibcalls.cpp | 50 +++++++++++++++++++
llvm/test/TableGen/RuntimeLibcallEmitter.td | 1 +
.../Util/DeclareRuntimeLibcalls/aarch64.ll | 5 ++
.../Util/DeclareRuntimeLibcalls/arm.ll | 2 +
.../Util/DeclareRuntimeLibcalls/arm64ec.ll | 1 +
.../Util/DeclareRuntimeLibcalls/avr.ll | 1 +
.../Util/DeclareRuntimeLibcalls/bsd.ll | 3 ++
.../Util/DeclareRuntimeLibcalls/hexagon.ll | 2 +
.../Util/DeclareRuntimeLibcalls/m68k.ll | 1 +
.../Util/DeclareRuntimeLibcalls/mips.ll | 2 +
.../Util/DeclareRuntimeLibcalls/msp430.ll | 1 +
.../Util/DeclareRuntimeLibcalls/ppc.ll | 3 ++
.../Util/DeclareRuntimeLibcalls/riscv.ll | 2 +
.../Util/DeclareRuntimeLibcalls/sparc.ll | 2 +
.../Util/DeclareRuntimeLibcalls/systemz.ll | 2 +
.../Util/DeclareRuntimeLibcalls/ve.ll | 1 +
.../DeclareRuntimeLibcalls/wchar-default.ll | 39 +++++++++++++++
.../DeclareRuntimeLibcalls/wchar-short.ll | 29 +++++++++++
.../Util/DeclareRuntimeLibcalls/windows.ll | 4 ++
22 files changed, 159 insertions(+)
create mode 100644 llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wchar-default.ll
create mode 100644 llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wchar-short.ll
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index 1b00a21f360a04..59d21d6f25fd47 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -205,6 +205,11 @@ struct RuntimeLibcallsInfo {
bool &ShouldZExtBoolReturn,
const Triple &T);
+ /// Returns the extension attribute needed for a wchar_t parameter of a
+ /// libcall. May be zeroext, signext, or none.
+ LLVM_ABI static Attribute::AttrKind
+ getExtAttrForWCharParam(const Triple &T, unsigned WCharWidth);
+
/// Get the C-type function signature of the Libcall if provided,
/// and convert it to IR FunctionType and Attributes.
/// If the C-type function signature is not provided, return nullptr.
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index a0fa58abff9b1b..a0c7c8c19fddb6 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -743,6 +743,7 @@ def MEMMOVE : RuntimeLibcall<Ptr, [Ptr, Ptr, SizeT]>;
def MEMMOVE_CHK : RuntimeLibcall<Ptr, [Ptr, Ptr, SizeT, SizeT]>;
def MEMSET : RuntimeLibcall<Ptr, [Ptr, Int, SizeT]>;
def MEMSET_CHK : RuntimeLibcall<Ptr, [Ptr, Int, SizeT, SizeT]>;
+def WMEMSET : RuntimeLibcall<Ptr, [Ptr, WChar, SizeT]>;
class MallocLibcall<string family> : RuntimeLibcall<Ptr, [SizeT]> {
let FnAttrs = [NoFree, NoUnwind, WillReturn,
AllocKindAttr<"AllocFnKind::Alloc | AllocFnKind::Uninitialized">,
@@ -1730,6 +1731,7 @@ defset list<RuntimeLibcallImpl> LibcCoreImpls = {
def memcpy : RuntimeLibcallImpl<MEMCPY>;
def memmove : RuntimeLibcallImpl<MEMMOVE>;
def memset : RuntimeLibcallImpl<MEMSET>;
+def wmemset : RuntimeLibcallImpl<WMEMSET>;
def __memcpy_chk : RuntimeLibcallImpl<MEMCPY_CHK>;
def __memmove_chk : RuntimeLibcallImpl<MEMMOVE_CHK>;
diff --git a/llvm/include/llvm/IR/RuntimeLibcallsImpl.td b/llvm/include/llvm/IR/RuntimeLibcallsImpl.td
index 1cd80d2d3f8f0d..5db9e3a15f2c7b 100644
--- a/llvm/include/llvm/IR/RuntimeLibcallsImpl.td
+++ b/llvm/include/llvm/IR/RuntimeLibcallsImpl.td
@@ -86,6 +86,7 @@ def ULLong : FuncArgType;
def UInt128 : FuncArgType;
def SizeT : FuncArgType; // size_t.
def SSizeT : FuncArgType; // POSIX ssize_t.
+def WChar : FuncArgType; // wchar_t.
defvar AlignValT = SizeT; // std::align_val_t.
def CmpResult : FuncArgType; // libgcc_cmp_return.
def Half : FuncArgType; // IEEE half.
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 12f2887651583d..a91fb180e48dfa 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -280,6 +280,8 @@ static Type *convertToIRType(FuncArgTypeID ID, LLVMContext &Ctx,
case SizeT:
case SSizeT:
return getSizeTType(Ctx, DL);
+ case WChar:
+ return IntegerType::get(Ctx, WCharSize * 8);
case CmpResult:
if (TT.isAArch64() || TT.isAMDGPU() || TT.isWasm())
return Type::getInt32Ty(Ctx);
@@ -386,10 +388,58 @@ static std::optional<bool> isSignedIntArgType(FuncArgTypeID ID) {
}
}
+/// Returns the extension attribute needed for an int/unsigned parameter of a
+/// libcall. May be zeroext, signext, or none.
+static Attribute::AttrKind getExtAttrForIntParam(const Triple &T,
+ bool IsSigned) {
+ // 64-bit targets tend to extend int/unsigned parameters to register width.
+ // Some targets ignore type signedness and sign-extend.
+ if (shouldSignExtI32Param(T))
+ return Attribute::SExt;
+ // A few others extend according to type signedness.
+ if (shouldExtI32(T))
+ return IsSigned ? Attribute::SExt : Attribute::ZExt;
+ // The rest either don't extend or don't need to extend because the type is
+ // already register-sized.
+ return Attribute::None;
+}
+
+// wchar_t is just an alias to some integer type and passed the same way.
+// Module records wchar_t size, but not its sign, so we have to guess it.
+Attribute::AttrKind
+RuntimeLibcallsInfo::getExtAttrForWCharParam(const Triple &T,
+ unsigned WCharWidth) {
+ unsigned IntWidth = getIntSize(T);
+
+ if (WCharWidth < IntWidth) {
+ // A wchar_t narrower than int is unsigned on every supported platform,
+ // either by default or because of -fshort-wchar.
+ if (T.isOSWindowsOrUEFI() && T.isX86_64())
+ return Attribute::None;
+ if (T.isAArch64() && !T.isOSDarwin())
+ return Attribute::None;
+ // NOTE: It is safe to add an extension attribute to a parameter that does
+ // not need one. The callee assumes the extension bits are garbage and will
+ // never inspect them.
+ return Attribute::ZExt;
+ }
+ if (WCharWidth == IntWidth) {
+ // A wchar_t of int width is signed on most platforms.
+ bool IsSigned = !T.isOSAIX() && !T.isOSzOS() && !T.isVE();
+ return getExtAttrForIntParam(T, IsSigned);
+ }
+ return Attribute::None;
+}
+
static Attribute::AttrKind getIntExtAttr(FuncArgTypeID ID, Type *Ty,
const Triple &TT, bool IsReturn) {
if (ID == Bool)
return shouldZExtBool(TT) ? Attribute::ZExt : Attribute::None;
+ if (ID == WChar) {
+ assert(!IsReturn && "No known function returns wchar_t");
+ return RuntimeLibcallsInfo::getExtAttrForWCharParam(
+ TT, Ty->getIntegerBitWidth());
+ }
std::optional<bool> Signed = isSignedIntArgType(ID);
if (!Signed || !Ty->isIntegerTy())
diff --git a/llvm/test/TableGen/RuntimeLibcallEmitter.td b/llvm/test/TableGen/RuntimeLibcallEmitter.td
index a6ebe2bfe073d3..4f67b59c9bce6a 100644
--- a/llvm/test/TableGen/RuntimeLibcallEmitter.td
+++ b/llvm/test/TableGen/RuntimeLibcallEmitter.td
@@ -176,6 +176,7 @@ def BlahLibrary : SystemRuntimeLibrary<isBlahArch, ["libc"]>;
// CHECK-NEXT: V16I32,
// CHECK-NEXT: Variable,
// CHECK-NEXT: Void,
+// CHECK-NEXT: WChar,
// CHECK-NEXT: X86FP80,
// CHECK-NEXT:};
// CHECK-EMPTY:
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/aarch64.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/aarch64.ll
index c1908ce9ff5e37..8883dc08669f19 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/aarch64.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/aarch64.ll
@@ -595,6 +595,7 @@
; LINUX-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; LINUX-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; LINUX-NEXT: declare fp128 @truncl(fp128) [[NOMEM_ATTRS]]
+; LINUX-NEXT: declare ptr @wmemset(ptr, i32, i64)
; LINUX-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; LINUX-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; LINUX-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -1135,6 +1136,7 @@
; DARWIN-NEXT: declare float @tgammaf(float) [[SQRT_ATTRS]]
; DARWIN-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; DARWIN-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
+; DARWIN-NEXT: declare ptr @wmemset(ptr, i32, i64)
; DARWIN-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; DARWIN-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; DARWIN-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -1669,6 +1671,7 @@
; WINMSVC-NEXT: declare float @tgammaf(float) [[SQRT_ATTRS]]
; WINMSVC-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; WINMSVC-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
+; WINMSVC-NEXT: declare ptr @wmemset(ptr, i16, i64)
; WINMSVC-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; WINMSVC-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; WINMSVC-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -2206,6 +2209,7 @@
; MINGW-NEXT: declare float @tgammaf(float) [[SQRT_ATTRS]]
; MINGW-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; MINGW-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
+; MINGW-NEXT: declare ptr @wmemset(ptr, i16, i64)
; MINGW-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; MINGW-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; MINGW-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -2804,6 +2808,7 @@
; ANDROID-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; ANDROID-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; ANDROID-NEXT: declare fp128 @truncl(fp128) [[NOMEM_ATTRS]]
+; ANDROID-NEXT: declare ptr @wmemset(ptr, i32, i64)
; ANDROID-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; ANDROID-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; ANDROID-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm.ll
index 36018ce18fcbae..109e5cc7758b24 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm.ll
@@ -473,6 +473,7 @@
; SJLJ-NEXT: declare arm_aapcscc float @tgammaf(float) [[SQRT_ATTRS]]
; SJLJ-NEXT: declare arm_aapcscc double @trunc(double) [[DIVMOD_ATTRS]]
; SJLJ-NEXT: declare arm_aapcscc float @truncf(float) [[DIVMOD_ATTRS]]
+; SJLJ-NEXT: declare arm_aapcscc ptr @wmemset(ptr, i32, i32)
; SJLJ-NEXT: attributes [[DIVMOD_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; SJLJ-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; SJLJ-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -949,6 +950,7 @@
; DWARF-NEXT: declare arm_aapcscc float @tgammaf(float) [[SQRT_ATTRS]]
; DWARF-NEXT: declare arm_aapcscc double @trunc(double) [[DIVMOD_ATTRS]]
; DWARF-NEXT: declare arm_aapcscc float @truncf(float) [[DIVMOD_ATTRS]]
+; DWARF-NEXT: declare arm_aapcscc ptr @wmemset(ptr, i32, i32)
; DWARF-NEXT: attributes [[DIVMOD_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; DWARF-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; DWARF-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm64ec.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm64ec.ll
index 7599166de8a065..13a53d39b3ce7b 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm64ec.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm64ec.ll
@@ -515,6 +515,7 @@
; CHECK-NEXT: declare float @"#tgammaf"(float) [[SQRT_ATTRS]]
; CHECK-NEXT: declare double @"#trunc"(double) [[NOMEM_ATTRS]]
; CHECK-NEXT: declare float @"#truncf"(float) [[NOMEM_ATTRS]]
+; CHECK-NEXT: declare ptr @"#wmemset"(ptr, i16, i64)
; CHECK-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; CHECK-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; CHECK-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/avr.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/avr.ll
index 59061f456d4d07..948e2c21cb6632 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/avr.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/avr.ll
@@ -403,6 +403,7 @@
; CHECK-NEXT: declare float @tgammaf(float) addrspace(1) [[SQRT_ATTRS]]
; CHECK-NEXT: declare double @trunc(double) addrspace(1) [[DIVMOD_ATTRS]]
; CHECK-NEXT: declare float @truncf(float) addrspace(1) [[DIVMOD_ATTRS]]
+; CHECK-NEXT: declare ptr @wmemset(ptr, i16, i16) addrspace(1)
; CHECK-NEXT: attributes [[DIVMOD_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; CHECK-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; CHECK-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/bsd.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/bsd.ll
index 7191118b66eaae..87e8f5a98500e3 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/bsd.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/bsd.ll
@@ -550,6 +550,7 @@
; LINUX-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; LINUX-NEXT: declare fp128 @truncf128(fp128) [[NOMEM_ATTRS]]
; LINUX-NEXT: declare x86_fp80 @truncl(x86_fp80) [[NOMEM_ATTRS]]
+; LINUX-NEXT: declare ptr @wmemset(ptr, i32, i64)
; LINUX-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; LINUX-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; LINUX-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -1051,6 +1052,7 @@
; FREEBSD-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; FREEBSD-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; FREEBSD-NEXT: declare x86_fp80 @truncl(x86_fp80) [[NOMEM_ATTRS]]
+; FREEBSD-NEXT: declare ptr @wmemset(ptr, i32, i64)
; FREEBSD-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; FREEBSD-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; FREEBSD-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -1552,6 +1554,7 @@
; OPENBSD-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; OPENBSD-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; OPENBSD-NEXT: declare x86_fp80 @truncl(x86_fp80) [[NOMEM_ATTRS]]
+; OPENBSD-NEXT: declare ptr @wmemset(ptr, i32, i64)
; OPENBSD-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; OPENBSD-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; OPENBSD-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/hexagon.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/hexagon.ll
index fc7782dad0fd65..9c08b70cf94c50 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/hexagon.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/hexagon.ll
@@ -439,6 +439,7 @@
; CHECK-NEXT: declare float @tgammaf(float) [[SQRT_ATTRS]]
; CHECK-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; CHECK-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
+; CHECK-NEXT: declare ptr @wmemset(ptr, i32, i32)
; CHECK-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; CHECK-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; CHECK-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -885,6 +886,7 @@
; LINUX-NEXT: declare float @tgammaf(float) [[SQRT_ATTRS]]
; LINUX-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; LINUX-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
+; LINUX-NEXT: declare ptr @wmemset(ptr, i32, i32)
; LINUX-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; LINUX-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; LINUX-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/m68k.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/m68k.ll
index 6441c58741d2de..1ab97568f0d839 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/m68k.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/m68k.ll
@@ -415,6 +415,7 @@
; M68K-NEXT: declare float @tgammaf(float) [[SQRT_ATTRS]]
; M68K-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; M68K-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
+; M68K-NEXT: declare ptr @wmemset(ptr, i32, i32)
; M68K-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; M68K-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; M68K-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/mips.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/mips.ll
index 38b44750217d2d..6a8c94e388c170 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/mips.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/mips.ll
@@ -452,6 +452,7 @@
; MIPS32-NEXT: declare float @tgammaf(float) [[SQRT_ATTRS]]
; MIPS32-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; MIPS32-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
+; MIPS32-NEXT: declare ptr @wmemset(ptr, i32 signext, i32 signext)
; MIPS32-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; MIPS32-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; MIPS32-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -937,6 +938,7 @@
; MIPS64-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; MIPS64-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; MIPS64-NEXT: declare fp128 @truncl(fp128) [[NOMEM_ATTRS]]
+; MIPS64-NEXT: declare ptr @wmemset(ptr, i32 signext, i64)
; MIPS64-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; MIPS64-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; MIPS64-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/msp430.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/msp430.ll
index a3cfac4e4b23c2..289d90ea640778 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/msp430.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/msp430.ll
@@ -457,6 +457,7 @@
; CHECK-NEXT: declare float @tgammaf(float) [[SQRT_ATTRS]]
; CHECK-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; CHECK-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
+; CHECK-NEXT: declare ptr @wmemset(ptr, i16, i16)
; CHECK-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; CHECK-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; CHECK-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ppc.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ppc.ll
index c652f59f1de5fb..1d24c9873ef898 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ppc.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ppc.ll
@@ -557,6 +557,7 @@
; AIX32-NEXT: declare void @vec_free(ptr allocptr noundef captures(none)) [[VEC_FREE_ATTRS:#[0-9]+]]
; AIX32-NEXT: declare noalias noundef ptr @vec_malloc(i32 noundef) [[VEC_MALLOC_ATTRS:#[0-9]+]]
; AIX32-NEXT: declare ptr @vec_realloc(ptr, i32)
+; AIX32-NEXT: declare ptr @wmemset(ptr, i16 zeroext, i32)
; AIX32-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
; AIX32-NEXT: attributes [[ARGMEM_READ_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }
; AIX32-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
@@ -1125,6 +1126,7 @@
; AIX64-NEXT: declare void @vec_free(ptr allocptr noundef captures(none)) [[VEC_FREE_ATTRS:#[0-9]+]]
; AIX64-NEXT: declare noalias noundef ptr @vec_malloc(i64 noundef) [[VEC_MALLOC_ATTRS:#[0-9]+]]
; AIX64-NEXT: declare ptr @vec_realloc(ptr, i64)
+; AIX64-NEXT: declare ptr @wmemset(ptr, i32 zeroext, i64)
; AIX64-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
; AIX64-NEXT: attributes [[ARGMEM_READ_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }
; AIX64-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
@@ -1684,6 +1686,7 @@
; LINUX-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; LINUX-NEXT: declare fp128 @truncf128(fp128) [[NOMEM_ATTRS]]
; LINUX-NEXT: declare ppc_fp128 @truncl(ppc_fp128) [[NOMEM_ATTRS]]
+; LINUX-NEXT: declare ptr @wmemset(ptr, i32 signext, i64)
; LINUX-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; LINUX-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; LINUX-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/riscv.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/riscv.ll
index a23349c548dc61..601aa8e56850de 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/riscv.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/riscv.ll
@@ -474,6 +474,7 @@
; RV32-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; RV32-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; RV32-NEXT: declare fp128 @truncl(fp128) [[NOMEM_ATTRS]]
+; RV32-NEXT: declare ptr @wmemset(ptr, i32, i32)
; RV32-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; RV32-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; RV32-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -957,6 +958,7 @@
; RV64-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; RV64-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; RV64-NEXT: declare fp128 @truncl(fp128) [[NOMEM_ATTRS]]
+; RV64-NEXT: declare ptr @wmemset(ptr, i32 signext, i64)
; RV64-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; RV64-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; RV64-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sparc.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sparc.ll
index 735a760a2bc35d..e896f103fd26cc 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sparc.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/sparc.ll
@@ -479,6 +479,7 @@
; SPARC32-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; SPARC32-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; SPARC32-NEXT: declare fp128 @truncl(fp128) [[NOMEM_ATTRS]]
+; SPARC32-NEXT: declare ptr @wmemset(ptr, i32, i32)
; SPARC32-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; SPARC32-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; SPARC32-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -968,6 +969,7 @@
; SPARC64-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; SPARC64-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; SPARC64-NEXT: declare fp128 @truncl(fp128) [[NOMEM_ATTRS]]
+; SPARC64-NEXT: declare ptr @wmemset(ptr, i32 signext, i64)
; SPARC64-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; SPARC64-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; SPARC64-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/systemz.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/systemz.ll
index 40a59c44555818..2f3e541a074833 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/systemz.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/systemz.ll
@@ -479,6 +479,7 @@
; LINUX-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; LINUX-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; LINUX-NEXT: declare fp128 @truncl(fp128) [[NOMEM_ATTRS]]
+; LINUX-NEXT: declare ptr @wmemset(ptr, i32 signext, i64)
; LINUX-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; LINUX-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; LINUX-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -1065,6 +1066,7 @@
; ZOS-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; ZOS-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; ZOS-NEXT: declare fp128 @truncl(fp128) [[NOMEM_ATTRS]]
+; ZOS-NEXT: declare ptr @wmemset(ptr, i32 zeroext, i64)
; ZOS-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; ZOS-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; ZOS-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ve.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ve.ll
index b749e4b6e5ccd0..72a60f12887dad 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ve.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/ve.ll
@@ -475,6 +475,7 @@
; CHECK-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; CHECK-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; CHECK-NEXT: declare fp128 @truncl(fp128) [[NOMEM_ATTRS]]
+; CHECK-NEXT: declare ptr @wmemset(ptr, i32 zeroext, i64)
; CHECK-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; CHECK-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; CHECK-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wchar-default.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wchar-default.ll
new file mode 100644
index 00000000000000..8858d0be3e5344
--- /dev/null
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wchar-default.ll
@@ -0,0 +1,39 @@
+; Check wchar_t width and the its extension attribute with target-default
+; wchar_t size.
+
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=aarch64-linux < %s | FileCheck -check-prefixes=CHECK,I32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=aarch64-darwin < %s | FileCheck -check-prefixes=CHECK,I32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=aarch64-windows < %s | FileCheck -check-prefixes=CHECK,I16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=armv7-linux < %s | FileCheck -check-prefixes=CHECK,I32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=armv7-darwin < %s | FileCheck -check-prefixes=CHECK,I32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=armv7-windows < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=avr < %s | FileCheck -check-prefixes=CHECK,I16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=i386-linux < %s | FileCheck -check-prefixes=CHECK,I32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=i386-windows < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=loongarch32 < %s | FileCheck -check-prefixes=CHECK,S32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=loongarch64 < %s | FileCheck -check-prefixes=CHECK,S32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=mips < %s | FileCheck -check-prefixes=CHECK,S32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=mips64 < %s | FileCheck -check-prefixes=CHECK,S32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=msp430 < %s | FileCheck -check-prefixes=CHECK,I16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=powerpc-linux < %s | FileCheck -check-prefixes=CHECK,I32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=powerpc-aix < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=powerpc64-linux < %s | FileCheck -check-prefixes=CHECK,S32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=powerpc64-aix < %s | FileCheck -check-prefixes=CHECK,Z32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=riscv32 < %s | FileCheck -check-prefixes=CHECK,I32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=riscv64 < %s | FileCheck -check-prefixes=CHECK,S32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=s390x-linux < %s | FileCheck -check-prefixes=CHECK,S32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=s390x-zos < %s | FileCheck -check-prefixes=CHECK,Z32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=sparc < %s | FileCheck -check-prefixes=CHECK,I32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=sparcv9 < %s | FileCheck -check-prefixes=CHECK,S32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=ve < %s | FileCheck -check-prefixes=CHECK,Z32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-linux < %s | FileCheck -check-prefixes=CHECK,I32 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-windows < %s | FileCheck -check-prefixes=CHECK,I16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=xcore < %s | FileCheck -check-prefixes=CHECK,Z8 %s
+
+; CHECK: declare{{.*}}wmemset
+; Z8-SAME: (ptr, i8 zeroext
+; I16-SAME: (ptr, i16,
+; Z16-SAME: (ptr, i16 zeroext
+; I32-SAME: (ptr, i32,
+; Z32-SAME: (ptr, i32 zeroext
+; S32-SAME: (ptr, i32 signext
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wchar-short.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wchar-short.ll
new file mode 100644
index 00000000000000..273ff738ebf96c
--- /dev/null
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/wchar-short.ll
@@ -0,0 +1,29 @@
+; Check wchar_t width and the its extension attribute with wchar_t size of 2,
+; simulating -fshort-wchar.
+
+; wchar_t is the same as int, no extension required.
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=avr < %s | FileCheck -check-prefixes=CHECK,I16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=msp430 < %s | FileCheck -check-prefixes=CHECK,I16 %s
+
+; No extension on x86_64-windows and non-darwin aarch64.
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=aarch64-linux < %s | FileCheck -check-prefixes=CHECK,I16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=aarch64-windows < %s | FileCheck -check-prefixes=CHECK,I16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-windows < %s | FileCheck -check-prefixes=CHECK,I16 %s
+
+; Zero extension is the default.
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=aarch64-darwin < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=armv7-linux < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=armv7-darwin < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=armv7-windows < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=i386-linux < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=i386-windows < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=riscv32 < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=riscv64 < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-linux < %s | FileCheck -check-prefixes=CHECK,Z16 %s
+
+; CHECK: declare{{.*}}wmemset
+; I16-SAME: (ptr, i16,
+; Z16-SAME: (ptr, i16 zeroext
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"wchar_size", i32 2}
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/windows.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/windows.ll
index a6a2f68f122ffc..5c57259f63d514 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/windows.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/windows.ll
@@ -437,6 +437,7 @@
; MSVC-NEXT: declare float @tgammaf(float) [[SQRT_ATTRS]]
; MSVC-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; MSVC-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
+; MSVC-NEXT: declare ptr @wmemset(ptr, i16, i64)
; MSVC-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; MSVC-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; MSVC-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -988,6 +989,7 @@
; MINGW-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; MINGW-NEXT: declare fp128 @truncf128(fp128) [[NOMEM_ATTRS]]
; MINGW-NEXT: declare x86_fp80 @truncl(x86_fp80) [[NOMEM_ATTRS]]
+; MINGW-NEXT: declare ptr @wmemset(ptr, i16, i64)
; MINGW-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; MINGW-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; MINGW-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -1490,6 +1492,7 @@
; CYGWIN-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; CYGWIN-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
; CYGWIN-NEXT: declare x86_fp80 @truncl(x86_fp80) [[NOMEM_ATTRS]]
+; CYGWIN-NEXT: declare ptr @wmemset(ptr, i16, i64)
; CYGWIN-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; CYGWIN-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; CYGWIN-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
@@ -1935,6 +1938,7 @@
; UEFI-NEXT: declare float @tgammaf(float) [[SQRT_ATTRS]]
; UEFI-NEXT: declare double @trunc(double) [[NOMEM_ATTRS]]
; UEFI-NEXT: declare float @truncf(float) [[NOMEM_ATTRS]]
+; UEFI-NEXT: declare ptr @wmemset(ptr, i16, i64)
; UEFI-NEXT: attributes [[NOMEM_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(none) }
; UEFI-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; UEFI-NEXT: attributes [[ARGMEM_WRITE_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
More information about the llvm-branch-commits
mailing list