[libc-commits] [libc] [libc] implement wcstoimax/wcstoumax (PR #200284)

via libc-commits libc-commits at lists.llvm.org
Thu May 28 15:01:50 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

<details>
<summary>Changes</summary>

Adds the implementation and tests for wide character to intmax_t and
uintmax_t.

Assisted-by: Automated tooling, human reviewed.


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


10 Files Affected:

- (modified) libc/config/linux/x86_64/entrypoints.txt (+2) 
- (modified) libc/include/inttypes.yaml (+17) 
- (modified) libc/src/inttypes/CMakeLists.txt (+27) 
- (added) libc/src/inttypes/wcstoimax.cpp (+35) 
- (added) libc/src/inttypes/wcstoimax.h (+28) 
- (added) libc/src/inttypes/wcstoumax.cpp (+35) 
- (added) libc/src/inttypes/wcstoumax.h (+28) 
- (modified) libc/test/src/inttypes/CMakeLists.txt (+21) 
- (added) libc/test/src/inttypes/wcstoimax_test.cpp (+20) 
- (added) libc/test/src/inttypes/wcstoumax_test.cpp (+20) 


``````````diff
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index bba31a3df9ad9..04ff83282a167 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -118,6 +118,8 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.inttypes.imaxdiv
     libc.src.inttypes.strtoimax
     libc.src.inttypes.strtoumax
+    libc.src.inttypes.wcstoimax
+    libc.src.inttypes.wcstoumax
 
     # stdbit.h entrypoints
     libc.src.stdbit.stdc_bit_ceil_uc
diff --git a/libc/include/inttypes.yaml b/libc/include/inttypes.yaml
index 9cfca386a9af4..cccfdc4d63d76 100644
--- a/libc/include/inttypes.yaml
+++ b/libc/include/inttypes.yaml
@@ -313,6 +313,7 @@ macros:
     macro_header: inttypes-macros.h
 types:
   - type_name: imaxdiv_t
+  - type_name: wchar_t
 enums: []
 objects: []
 functions:
@@ -345,3 +346,19 @@ functions:
       - type: const char *__restrict
       - type: char * *__restrict
       - type: int
+  - name: wcstoimax
+    standards:
+      - stdc
+    return_type: intmax_t
+    arguments:
+      - type: const wchar_t *__restrict
+      - type: wchar_t * *__restrict
+      - type: int
+  - name: wcstoumax
+    standards:
+      - stdc
+    return_type: uintmax_t
+    arguments:
+      - type: const wchar_t *__restrict
+      - type: wchar_t * *__restrict
+      - type: int
diff --git a/libc/src/inttypes/CMakeLists.txt b/libc/src/inttypes/CMakeLists.txt
index 3a48c9a1a8b97..4860ed838bc85 100644
--- a/libc/src/inttypes/CMakeLists.txt
+++ b/libc/src/inttypes/CMakeLists.txt
@@ -43,3 +43,30 @@ add_entrypoint_object(
     libc.include.inttypes
     libc.src.__support.integer_operations
 )
+
+add_entrypoint_object(
+  wcstoimax
+  SRCS
+    wcstoimax.cpp
+  HDRS
+    wcstoimax.h
+  DEPENDS
+    libc.hdr.types.wchar_t
+    libc.hdr.stdint_proxy
+    libc.src.__support.str_to_integer
+    libc.src.errno.errno
+)
+
+add_entrypoint_object(
+  wcstoumax
+  SRCS
+    wcstoumax.cpp
+  HDRS
+    wcstoumax.h
+  DEPENDS
+    libc.hdr.types.wchar_t
+    libc.hdr.stdint_proxy
+    libc.src.__support.str_to_integer
+    libc.src.errno.errno
+)
+
diff --git a/libc/src/inttypes/wcstoimax.cpp b/libc/src/inttypes/wcstoimax.cpp
new file mode 100644
index 0000000000000..2cfef258fb0f7
--- /dev/null
+++ b/libc/src/inttypes/wcstoimax.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of wcstoimax.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/inttypes/wcstoimax.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/str_to_integer.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(intmax_t, wcstoimax,
+                   (const wchar_t *__restrict str, wchar_t **__restrict str_end,
+                    int base)) {
+  auto result = internal::strtointeger<intmax_t>(str, base);
+  if (result.has_error())
+    libc_errno = result.error;
+
+  if (str_end != nullptr && result.error != EINVAL)
+    *str_end = const_cast<wchar_t *>(str + result.parsed_len);
+
+  return result;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/inttypes/wcstoimax.h b/libc/src/inttypes/wcstoimax.h
new file mode 100644
index 0000000000000..11dce881d844a
--- /dev/null
+++ b/libc/src/inttypes/wcstoimax.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for wcstoimax.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_INTTYPES_WCSTOIMAX_H
+#define LLVM_LIBC_SRC_INTTYPES_WCSTOIMAX_H
+
+#include "hdr/stdint_proxy.h"
+#include "hdr/types/wchar_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+intmax_t wcstoimax(const wchar_t *__restrict str, wchar_t **__restrict str_end,
+                   int base);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_INTTYPES_WCSTOIMAX_H
diff --git a/libc/src/inttypes/wcstoumax.cpp b/libc/src/inttypes/wcstoumax.cpp
new file mode 100644
index 0000000000000..ec8c43b3a375f
--- /dev/null
+++ b/libc/src/inttypes/wcstoumax.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of wcstoumax.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/inttypes/wcstoumax.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/str_to_integer.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(uintmax_t, wcstoumax,
+                   (const wchar_t *__restrict str, wchar_t **__restrict str_end,
+                    int base)) {
+  auto result = internal::strtointeger<uintmax_t>(str, base);
+  if (result.has_error())
+    libc_errno = result.error;
+
+  if (str_end != nullptr && result.error != EINVAL)
+    *str_end = const_cast<wchar_t *>(str + result.parsed_len);
+
+  return result;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/inttypes/wcstoumax.h b/libc/src/inttypes/wcstoumax.h
new file mode 100644
index 0000000000000..2004da2d39f4a
--- /dev/null
+++ b/libc/src/inttypes/wcstoumax.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for wcstoumax.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_INTTYPES_WCSTOUMAX_H
+#define LLVM_LIBC_SRC_INTTYPES_WCSTOUMAX_H
+
+#include "hdr/stdint_proxy.h"
+#include "hdr/types/wchar_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+uintmax_t wcstoumax(const wchar_t *__restrict str, wchar_t **__restrict str_end,
+                    int base);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_INTTYPES_WCSTOUMAX_H
diff --git a/libc/test/src/inttypes/CMakeLists.txt b/libc/test/src/inttypes/CMakeLists.txt
index c7088d3c13e2e..f79c9a7f4f6f9 100644
--- a/libc/test/src/inttypes/CMakeLists.txt
+++ b/libc/test/src/inttypes/CMakeLists.txt
@@ -48,3 +48,24 @@ add_libc_test(
     libc.src.inttypes.imaxabs
 )
 
+add_libc_test(
+  wcstoimax_test
+  SUITE
+    libc_inttypes_tests
+  SRCS
+    wcstoimax_test.cpp
+  DEPENDS
+    libc.src.inttypes.wcstoimax
+    libc.test.src.wchar.wcstol_test_support
+)
+
+add_libc_test(
+  wcstoumax_test
+  SUITE
+    libc_inttypes_tests
+  SRCS
+    wcstoumax_test.cpp
+  DEPENDS
+    libc.src.inttypes.wcstoumax
+    libc.test.src.wchar.wcstol_test_support
+)
diff --git a/libc/test/src/inttypes/wcstoimax_test.cpp b/libc/test/src/inttypes/wcstoimax_test.cpp
new file mode 100644
index 0000000000000..fcef8c2985d61
--- /dev/null
+++ b/libc/test/src/inttypes/wcstoimax_test.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unit tests for wcstoimax.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/inttypes/wcstoimax.h"
+
+#include "test/UnitTest/Test.h"
+
+#include "test/src/wchar/WcstolTest.h"
+
+WCSTOL_TEST(Wcstoimax, LIBC_NAMESPACE::wcstoimax)
diff --git a/libc/test/src/inttypes/wcstoumax_test.cpp b/libc/test/src/inttypes/wcstoumax_test.cpp
new file mode 100644
index 0000000000000..61ea4bbdefb41
--- /dev/null
+++ b/libc/test/src/inttypes/wcstoumax_test.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unit tests for wcstoumax.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/inttypes/wcstoumax.h"
+
+#include "test/UnitTest/Test.h"
+
+#include "test/src/wchar/WcstolTest.h"
+
+WCSTOL_TEST(Wcstoumax, LIBC_NAMESPACE::wcstoumax)

``````````

</details>


https://github.com/llvm/llvm-project/pull/200284


More information about the libc-commits mailing list