[libc-commits] [libc] [libc] Implement entrypoint and test of iswupper function (PR #185215)
via libc-commits
libc-commits at lists.llvm.org
Sat Mar 7 10:21:16 PST 2026
https://github.com/csxplorer created https://github.com/llvm/llvm-project/pull/185215
Implement entrypoint and test of iswupper function
>From 8e46da87820738dcd2edac0aae3c121ccecfd043 Mon Sep 17 00:00:00 2001
From: Junyu Liu <3221693279 at qq.com>
Date: Sat, 7 Mar 2026 11:44:38 +0000
Subject: [PATCH] [libc] Implement entrypoint and test of iswupper function
---
libc/config/baremetal/arm/entrypoints.txt | 1 +
libc/config/baremetal/riscv/entrypoints.txt | 1 +
libc/config/darwin/aarch64/entrypoints.txt | 1 +
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/arm/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/config/windows/entrypoints.txt | 1 +
libc/include/wctype.yaml | 6 +++
libc/src/wctype/CMakeLists.txt | 10 ++++
libc/src/wctype/iswupper.cpp | 21 ++++++++
libc/src/wctype/iswupper.h | 21 ++++++++
libc/test/src/wctype/CMakeLists.txt | 10 ++++
libc/test/src/wctype/iswupper_test.cpp | 54 +++++++++++++++++++++
14 files changed, 130 insertions(+)
create mode 100644 libc/src/wctype/iswupper.cpp
create mode 100644 libc/src/wctype/iswupper.h
create mode 100644 libc/test/src/wctype/iswupper_test.cpp
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 7bc92e84b7fa4..244627cb6f6f0 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -299,6 +299,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# wctype.h entrypoints
libc.src.wctype.iswalpha
+ libc.src.wctype.iswupper
# internal entrypoints
libc.startup.baremetal.init
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 29be47dfbfd53..887ec84d0b26e 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -296,6 +296,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# wctype.h entrypoints
libc.src.wctype.iswalpha
+ libc.src.wctype.iswupper
# internal entrypoints
libc.startup.baremetal.init
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index b4a1ee70764cb..714684c3671ba 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -102,6 +102,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# wctype.h entrypoints
libc.src.wctype.iswalpha
+ libc.src.wctype.iswupper
)
if(LLVM_LIBC_FULL_BUILD)
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 960958b7cf90a..5f1a6c57eed42 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -369,6 +369,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# wctype.h entrypoints
libc.src.wctype.iswalpha
+ libc.src.wctype.iswupper
# sys/uio.h entrypoints
libc.src.sys.uio.writev
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index e76bf81670ce5..558c6690c64b4 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -194,6 +194,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# wctype.h entrypoints
libc.src.wctype.iswalpha
+ libc.src.wctype.iswupper
)
if(LLVM_LIBC_FULL_BUILD)
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index a69d1a1b0a642..7a9a8a1b7d47c 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -373,6 +373,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# wctype.h entrypoints
libc.src.wctype.iswalpha
+ libc.src.wctype.iswupper
# sys/uio.h entrypoints
libc.src.sys.uio.writev
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 4103ee0331a23..61b0d7dcf80b0 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -418,6 +418,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# wctype.h entrypoints
libc.src.wctype.iswalpha
+ libc.src.wctype.iswupper
# sys/uio.h entrypoints
libc.src.sys.uio.writev
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index f777fc6c94bc2..4a770bba64e36 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -108,6 +108,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# wctype.h entrypoints
libc.src.wctype.iswalpha
+ libc.src.wctype.iswupper
)
set(TARGET_LIBM_ENTRYPOINTS
diff --git a/libc/include/wctype.yaml b/libc/include/wctype.yaml
index fb4f96f7d17e4..2addcbc9730f4 100644
--- a/libc/include/wctype.yaml
+++ b/libc/include/wctype.yaml
@@ -8,3 +8,9 @@ functions:
return_type: int
arguments:
- type: wint_t
+ - name: iswupper
+ standards:
+ - stdc
+ return_type: int
+ arguments:
+ - type: wint_t
diff --git a/libc/src/wctype/CMakeLists.txt b/libc/src/wctype/CMakeLists.txt
index 3ac5eaef8ed8b..36ad46d062656 100644
--- a/libc/src/wctype/CMakeLists.txt
+++ b/libc/src/wctype/CMakeLists.txt
@@ -7,3 +7,13 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.wctype_utils
)
+
+add_entrypoint_object(
+ iswupper
+ SRCS
+ iswupper.cpp
+ HDRS
+ iswupper.h
+ DEPENDS
+ libc.src.__support.wctype_utils
+)
diff --git a/libc/src/wctype/iswupper.cpp b/libc/src/wctype/iswupper.cpp
new file mode 100644
index 0000000000000..28c3161726936
--- /dev/null
+++ b/libc/src/wctype/iswupper.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of iswupper ----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/wctype/iswupper.h"
+#include "src/__support/common.h"
+#include "src/__support/wctype_utils.h"
+
+#include "hdr/types/wint_t.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, iswupper, (wint_t c)) {
+ return internal::isupper(static_cast<wchar_t>(c));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/wctype/iswupper.h b/libc/src/wctype/iswupper.h
new file mode 100644
index 0000000000000..e630b42e2dcc9
--- /dev/null
+++ b/libc/src/wctype/iswupper.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for iswupper ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_WCTYPE_ISWUPPER_H
+#define LLVM_LIBC_SRC_WCTYPE_ISWUPPER_H
+
+#include "hdr/types/wint_t.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int iswupper(wint_t c);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_WCTYPE_ISWUPPER_H
diff --git a/libc/test/src/wctype/CMakeLists.txt b/libc/test/src/wctype/CMakeLists.txt
index 5459cdb4a9b71..dd9eeea9ddda9 100644
--- a/libc/test/src/wctype/CMakeLists.txt
+++ b/libc/test/src/wctype/CMakeLists.txt
@@ -9,3 +9,13 @@ add_libc_test(
DEPENDS
libc.src.wctype.iswalpha
)
+
+add_libc_test(
+ iswupper_test
+ SUITE
+ libc_wctype_unittests
+ SRCS
+ iswupper_test.cpp
+ DEPENDS
+ libc.src.wctype.iswupper
+)
diff --git a/libc/test/src/wctype/iswupper_test.cpp b/libc/test/src/wctype/iswupper_test.cpp
new file mode 100644
index 0000000000000..9f7e4ad257e66
--- /dev/null
+++ b/libc/test/src/wctype/iswupper_test.cpp
@@ -0,0 +1,54 @@
+//===-- Unittests for iswupper --------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/CPP/span.h"
+#include "src/wctype/iswupper.h"
+
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibciswupper, SimpleTest) {
+ EXPECT_NE(LIBC_NAMESPACE::iswupper('B'), 0);
+
+ EXPECT_EQ(LIBC_NAMESPACE::iswupper('a'), 0);
+ EXPECT_EQ(LIBC_NAMESPACE::iswupper('3'), 0);
+ EXPECT_EQ(LIBC_NAMESPACE::iswupper(' '), 0);
+ EXPECT_EQ(LIBC_NAMESPACE::iswupper('?'), 0);
+ EXPECT_EQ(LIBC_NAMESPACE::iswupper('\0'), 0);
+ EXPECT_EQ(LIBC_NAMESPACE::iswupper(-1), 0);
+}
+
+// TODO: once iswupper supports more than just ascii-range characters add a
+// proper test.
+
+// namespace {
+
+// // TODO: Merge the wctype tests using this framework.
+// constexpr char WUPPER_ARRAY[] = {
+// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+// };
+
+// bool in_span(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) {
+// for (size_t i = 0; i < arr.size(); ++i)
+// if (static_cast<int>(arr[i]) == ch)
+// return true;
+// return false;
+// }
+
+// } // namespace
+
+// TEST(LlvmLibciswupper, DefaultLocale) {
+// // Loops through all characters, verifying that letters return
+// // true and everything else returns false.
+// for (int ch = -255; ch < 255; ++ch) {
+// if (in_span(ch, WUPPER_ARRAY))
+// EXPECT_TRUE(LIBC_NAMESPACE::iswupper(ch));
+// else
+// EXPECT_FALSE(LIBC_NAMESPACE::iswupper(ch));
+// }
+// }
More information about the libc-commits
mailing list