Skip to content

[libc] add wctype.h header #149202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 17, 2025
Merged

[libc] add wctype.h header #149202

merged 10 commits into from
Jul 17, 2025

Conversation

Prabhuk
Copy link
Contributor

@Prabhuk Prabhuk commented Jul 16, 2025

Add basic configurations to generate wctype.h header file. To begin with this header file just exposes one function iswalpha.

Prabhuk added 4 commits July 16, 2025 15:06
Add basic configurations to generate wctype.h header file. To begin with
this header file just exposes one function iswalpha.
@Prabhuk Prabhuk requested a review from frobtech July 16, 2025 23:25
@Prabhuk Prabhuk marked this pull request as ready for review July 16, 2025 23:25
@llvmbot llvmbot added the libc label Jul 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 16, 2025

@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-libc

Author: Prabhu Rajasekaran (Prabhuk)

Changes

Add basic configurations to generate wctype.h header file. To begin with this header file just exposes one function iswalpha.


Full diff: https://github.com/llvm/llvm-project/pull/149202.diff

8 Files Affected:

  • (modified) libc/config/baremetal/arm/entrypoints.txt (+3)
  • (modified) libc/config/baremetal/arm/headers.txt (+1)
  • (modified) libc/include/CMakeLists.txt (+9)
  • (added) libc/include/wctype.yaml (+10)
  • (modified) libc/src/CMakeLists.txt (+1)
  • (added) libc/src/wctype/CMakeLists.txt (+9)
  • (added) libc/src/wctype/iswalpha.cpp (+19)
  • (added) libc/src/wctype/iswalpha.h (+21)
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index de7549c57ff44..80cd15eebc91f 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -278,6 +278,9 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.wchar.wcslen
     libc.src.wchar.wctob
 
+    # wctype.h entrypoints
+    libc.src.wctype.iswalpha
+
     # internal entrypoints
     libc.startup.baremetal.init
     libc.startup.baremetal.fini
diff --git a/libc/config/baremetal/arm/headers.txt b/libc/config/baremetal/arm/headers.txt
index 5666ef7e0012d..1f64afebdaaa7 100644
--- a/libc/config/baremetal/arm/headers.txt
+++ b/libc/config/baremetal/arm/headers.txt
@@ -23,4 +23,5 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.time
     libc.include.uchar
     libc.include.wchar
+    libc.include.wctype
 )
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 55268d19529c7..984b960acb2d7 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -720,6 +720,15 @@ add_header_macro(
     .llvm-libc-types.wchar_t
 )
 
+add_header_macro(
+  wctype
+  ../libc/include/wctype.yaml
+  wctype.h
+  DEPENDS
+    .llvm_libc_common_h    
+    .llvm-libc-types.wint_t
+)
+
 add_header_macro(
   locale
   ../libc/include/locale.yaml
diff --git a/libc/include/wctype.yaml b/libc/include/wctype.yaml
new file mode 100644
index 0000000000000..fb4f96f7d17e4
--- /dev/null
+++ b/libc/include/wctype.yaml
@@ -0,0 +1,10 @@
+header: wctype.h
+types:
+  - type_name: wint_t
+functions:
+  - name: iswalpha
+    standards:
+      - stdc
+    return_type: int
+    arguments:
+      - type: wint_t
diff --git a/libc/src/CMakeLists.txt b/libc/src/CMakeLists.txt
index a665253c4cc03..d7a1e1f49e6ff 100644
--- a/libc/src/CMakeLists.txt
+++ b/libc/src/CMakeLists.txt
@@ -17,6 +17,7 @@ add_subdirectory(strings)
 add_subdirectory(time)
 add_subdirectory(unistd)
 add_subdirectory(wchar)
+add_subdirectory(wctype)
 
 if(${LIBC_TARGET_OS} STREQUAL "linux")
   add_subdirectory(dirent)
diff --git a/libc/src/wctype/CMakeLists.txt b/libc/src/wctype/CMakeLists.txt
new file mode 100644
index 0000000000000..3ac5eaef8ed8b
--- /dev/null
+++ b/libc/src/wctype/CMakeLists.txt
@@ -0,0 +1,9 @@
+add_entrypoint_object(
+  iswalpha
+  SRCS
+    iswalpha.cpp
+  HDRS
+    iswalpha.h
+  DEPENDS
+    libc.src.__support.wctype_utils    
+)
diff --git a/libc/src/wctype/iswalpha.cpp b/libc/src/wctype/iswalpha.cpp
new file mode 100644
index 0000000000000..7bd9e894234d6
--- /dev/null
+++ b/libc/src/wctype/iswalpha.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of iswcalpha ---------------------------------------===//
+//
+// 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/iswalpha.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(bool, iswalpha, (wint_t c)) { return internal::iswalpha(c); }
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/wctype/iswalpha.h b/libc/src/wctype/iswalpha.h
new file mode 100644
index 0000000000000..681fc6ba79a54
--- /dev/null
+++ b/libc/src/wctype/iswalpha.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for iswalpha ----------------------*- 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_ISWALPHA_H
+#define LLVM_LIBC_SRC_WCTYPE_ISWALPHA_H
+
+#include "hdr/types/wint_t.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bool iswalpha(wint_t c);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_WCTYPE_ISWALPHA_H

Copy link

github-actions bot commented Jul 16, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@lntue lntue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about Linux (aarch64, arm, x86_64, riscv), Darwin aarch64, and Windows targets?

@Prabhuk
Copy link
Contributor Author

Prabhuk commented Jul 17, 2025

What about Linux (aarch64, arm, x86_64, riscv), Darwin aarch64, and Windows targets?

My focus was on baremetal 32 bit targets and was not sure if these platforms also needed this change. Added these entrypoints now. PTAL. Thank you.

@Prabhuk Prabhuk merged commit e8182fb into llvm:main Jul 17, 2025
18 of 19 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 18, 2025

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building libc at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/38494

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
...
PASS: lld :: COFF/duplicate-absolute.s (98681 of 101675)
PASS: lld :: COFF/dllexport-mingw.s (98682 of 101675)
PASS: lld :: COFF/error-limit.test (98683 of 101675)
PASS: lld :: COFF/arm64x-import.test (98684 of 101675)
PASS: lld :: COFF/dllexport.s (98685 of 101675)
PASS: lld :: COFF/duplicate-absolute-same.s (98686 of 101675)
PASS: lit :: shtest-external-shell-kill.py (98687 of 101675)
PASS: lld :: COFF/arm64x-symtab.s (98688 of 101675)
PASS: lld :: COFF/empty-section-decl.yaml (98689 of 101675)
TIMEOUT: MLIR :: Examples/standalone/test.toy (98690 of 101675)
******************** TEST 'MLIR :: Examples/standalone/test.toy' FAILED ********************
Exit Code: 1
Timeout: Reached timeout of 60 seconds

Command Output (stdout):
--
# RUN: at line 1
"/etc/cmake/bin/cmake" "/build/buildbot/premerge-monolithic-linux/llvm-project/mlir/examples/standalone" -G "Ninja"  -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang  -DLLVM_ENABLE_LIBCXX=OFF -DMLIR_DIR=/build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir  -DLLVM_USE_LINKER=lld  -DPython3_EXECUTABLE="/usr/bin/python3.10"
# executed command: /etc/cmake/bin/cmake /build/buildbot/premerge-monolithic-linux/llvm-project/mlir/examples/standalone -G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang -DLLVM_ENABLE_LIBCXX=OFF -DMLIR_DIR=/build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir -DLLVM_USE_LINKER=lld -DPython3_EXECUTABLE=/usr/bin/python3.10
# .---command stdout------------
# | -- The CXX compiler identification is Clang 16.0.6
# | -- The C compiler identification is Clang 16.0.6
# | -- Detecting CXX compiler ABI info
# | -- Detecting CXX compiler ABI info - done
# | -- Check for working CXX compiler: /usr/bin/clang++ - skipped
# | -- Detecting CXX compile features
# | -- Detecting CXX compile features - done
# | -- Detecting C compiler ABI info
# | -- Detecting C compiler ABI info - done
# | -- Check for working C compiler: /usr/bin/clang - skipped
# | -- Detecting C compile features
# | -- Detecting C compile features - done
# | -- Looking for histedit.h
# | -- Looking for histedit.h - found
# | -- Found LibEdit: /usr/include (found version "2.11") 
# | -- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") 
# | -- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.13") 
# | -- Using MLIRConfig.cmake in: /build/buildbot/premerge-monolithic-linux/build/lib/cmake/mlir
# | -- Using LLVMConfig.cmake in: /build/buildbot/premerge-monolithic-linux/build/lib/cmake/llvm
# | -- Linker detection: unknown
# | -- Performing Test LLVM_LIBSTDCXX_MIN
# | -- Performing Test LLVM_LIBSTDCXX_MIN - Success
# | -- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR
# | -- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR - Success
# | -- Performing Test CXX_SUPPORTS_CUSTOM_LINKER
# | -- Performing Test CXX_SUPPORTS_CUSTOM_LINKER - Success
# | -- Performing Test C_SUPPORTS_FPIC
# | -- Performing Test C_SUPPORTS_FPIC - Success
# | -- Performing Test CXX_SUPPORTS_FPIC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants