[libc-commits] [libc] [libc] Implement entrypoint and test of iswupper function (PR #185215)

via libc-commits libc-commits at lists.llvm.org
Tue Mar 10 02:19:22 PDT 2026


https://github.com/csxplorer updated https://github.com/llvm/llvm-project/pull/185215

>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 1/3] [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));
+//   }
+// }

>From f32fd8aea3759d7777818ce1b3ea12dc608a0ce8 Mon Sep 17 00:00:00 2001
From: Junyu Liu <3221693279 at qq.com>
Date: Tue, 10 Mar 2026 09:14:09 +0000
Subject: [PATCH 2/3] [libc] Resolve dependencies and includes

---
 libc/src/wctype/CMakeLists.txt         | 3 +++
 libc/test/src/wctype/iswalpha_test.cpp | 1 -
 libc/test/src/wctype/iswdigit_test.cpp | 1 -
 libc/test/src/wctype/iswupper_test.cpp | 1 -
 4 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libc/src/wctype/CMakeLists.txt b/libc/src/wctype/CMakeLists.txt
index ab1a113a22c7e..2a73621398b5e 100644
--- a/libc/src/wctype/CMakeLists.txt
+++ b/libc/src/wctype/CMakeLists.txt
@@ -5,6 +5,7 @@ add_entrypoint_object(
   HDRS
     iswalpha.h
   DEPENDS
+    libc.hdr.types.wint_t
     libc.src.__support.wctype_utils    
 )
 
@@ -15,6 +16,7 @@ add_entrypoint_object(
   HDRS
     iswdigit.h
   DEPENDS
+    libc.hdr.types.wint_t
     libc.src.__support.wctype_utils   
 )
 
@@ -25,5 +27,6 @@ add_entrypoint_object(
   HDRS
     iswupper.h
   DEPENDS
+    libc.hdr.types.wint_t
     libc.src.__support.wctype_utils
 )
diff --git a/libc/test/src/wctype/iswalpha_test.cpp b/libc/test/src/wctype/iswalpha_test.cpp
index 261e6fe53790a..eb2314c2ca3f6 100644
--- a/libc/test/src/wctype/iswalpha_test.cpp
+++ b/libc/test/src/wctype/iswalpha_test.cpp
@@ -6,7 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "src/__support/CPP/span.h"
 #include "src/__support/wctype_utils.h"
 #include "src/wctype/iswalpha.h"
 
diff --git a/libc/test/src/wctype/iswdigit_test.cpp b/libc/test/src/wctype/iswdigit_test.cpp
index d529f527e3591..d26ab5c92a46e 100644
--- a/libc/test/src/wctype/iswdigit_test.cpp
+++ b/libc/test/src/wctype/iswdigit_test.cpp
@@ -6,7 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "src/__support/CPP/span.h"
 #include "src/wctype/iswdigit.h"
 
 #include "test/UnitTest/Test.h"
diff --git a/libc/test/src/wctype/iswupper_test.cpp b/libc/test/src/wctype/iswupper_test.cpp
index 9f7e4ad257e66..39da114a33140 100644
--- a/libc/test/src/wctype/iswupper_test.cpp
+++ b/libc/test/src/wctype/iswupper_test.cpp
@@ -6,7 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "src/__support/CPP/span.h"
 #include "src/wctype/iswupper.h"
 
 #include "test/UnitTest/Test.h"

>From fbadfa05c2d682308593a2fdc87187439167d2dc Mon Sep 17 00:00:00 2001
From: Junyu Liu <3221693279 at qq.com>
Date: Tue, 10 Mar 2026 09:19:07 +0000
Subject: [PATCH 3/3] [libc] Update outdated comments in iswupper unittest

---
 libc/test/src/wctype/iswupper_test.cpp | 32 ++------------------------
 1 file changed, 2 insertions(+), 30 deletions(-)

diff --git a/libc/test/src/wctype/iswupper_test.cpp b/libc/test/src/wctype/iswupper_test.cpp
index 39da114a33140..5d723ccf04a75 100644
--- a/libc/test/src/wctype/iswupper_test.cpp
+++ b/libc/test/src/wctype/iswupper_test.cpp
@@ -21,33 +21,5 @@ TEST(LlvmLibciswupper, SimpleTest) {
   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));
-//   }
-// }
+// Tests for the extended range are located in
+// libc/test/src/__support/wctype_utils_test.cpp.



More information about the libc-commits mailing list