Skip to content

Conversation

@vonosmas
Copy link
Contributor

  • Add FILE type declaration, as it should be presented in <wchar.h>, as well as in <stdio.h>
  • Fix argument type in wcsrtombs / wcsnrtombs function - it should be restrict pointer to mbstate_t. Add restrict qualifier to internal implementation as well.

This brings us closer to being able to build libcxx with wide-character support against llvm-libc headers.

@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2025

@llvm/pr-subscribers-libc

Author: Alexey Samsonov (vonosmas)

Changes
  • Add FILE type declaration, as it should be presented in &lt;wchar.h&gt;, as well as in &lt;stdio.h&gt;
  • Fix argument type in wcsrtombs / wcsnrtombs function - it should be restrict pointer to mbstate_t. Add restrict qualifier to internal implementation as well.

This brings us closer to being able to build libcxx with wide-character support against llvm-libc headers.


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

5 Files Affected:

  • (modified) libc/include/wchar.yaml (+6-5)
  • (modified) libc/src/wchar/wcsnrtombs.cpp (+1-1)
  • (modified) libc/src/wchar/wcsnrtombs.h (+1-1)
  • (modified) libc/src/wchar/wcsrtombs.cpp (+1-1)
  • (modified) libc/src/wchar/wcsrtombs.h (+1-1)
diff --git a/libc/include/wchar.yaml b/libc/include/wchar.yaml
index 8178091ab2202..b8a0a748cd3ad 100644
--- a/libc/include/wchar.yaml
+++ b/libc/include/wchar.yaml
@@ -4,6 +4,7 @@ macros:
   - macro_name: NULL
     macro_header: null-macro.h
 types:
+  - type_name: FILE
   - type_name: size_t
   - type_name: wint_t
   - type_name: wchar_t
@@ -104,9 +105,9 @@ functions:
   - name: wmemset
     standards:
       - stdc
-    return_type: wchar_t*
+    return_type: wchar_t *
     arguments:
-      - type: wchar_t*
+      - type: wchar_t *
       - type: wchar_t
       - type: size_t
   - name: wcschr
@@ -246,7 +247,7 @@ functions:
       - type: const wchar_t **__restrict
       - type: size_t
       - type: size_t
-      - type: mbstate_t
+      - type: mbstate_t *__restrict
   - name: wcsrtombs
     standards:
       - stdc
@@ -255,7 +256,7 @@ functions:
       - type: char *__restrict
       - type: const wchar_t **__restrict
       - type: size_t
-      - type: mbstate_t
+      - type: mbstate_t *__restrict
   - name: wcrtomb
     standards:
       - stdc
@@ -299,7 +300,7 @@ functions:
     arguments:
       - type: wchar_t *__restrict
       - type: const wchar_t *__restrict
-      - type: wchar_t** __restrict
+      - type: wchar_t **__restrict
   - name: wcpcpy
     standards:
       - stdc
diff --git a/libc/src/wchar/wcsnrtombs.cpp b/libc/src/wchar/wcsnrtombs.cpp
index 7f25b248a0863..a344c2331b532 100644
--- a/libc/src/wchar/wcsnrtombs.cpp
+++ b/libc/src/wchar/wcsnrtombs.cpp
@@ -22,7 +22,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(size_t, wcsnrtombs,
                    (char *__restrict s, const wchar_t **__restrict pwcs,
-                    size_t nwc, size_t len, mbstate_t *ps)) {
+                    size_t nwc, size_t len, mbstate_t *__restrict ps)) {
   LIBC_CRASH_ON_NULLPTR(pwcs);
   static internal::mbstate internal_mbstate;
   auto result = internal::wcsnrtombs(
diff --git a/libc/src/wchar/wcsnrtombs.h b/libc/src/wchar/wcsnrtombs.h
index bf8add75b2951..2ca42c71e2e9d 100644
--- a/libc/src/wchar/wcsnrtombs.h
+++ b/libc/src/wchar/wcsnrtombs.h
@@ -17,7 +17,7 @@
 namespace LIBC_NAMESPACE_DECL {
 
 size_t wcsnrtombs(char *__restrict s, const wchar_t **__restrict pwcs,
-                  size_t nwc, size_t len, mbstate_t *ps);
+                  size_t nwc, size_t len, mbstate_t *__restrict ps);
 
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/src/wchar/wcsrtombs.cpp b/libc/src/wchar/wcsrtombs.cpp
index 9d2508cb81a8c..0167e857128de 100644
--- a/libc/src/wchar/wcsrtombs.cpp
+++ b/libc/src/wchar/wcsrtombs.cpp
@@ -22,7 +22,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(size_t, wcsrtombs,
                    (char *__restrict s, const wchar_t **__restrict pwcs,
-                    size_t n, mbstate_t *ps)) {
+                    size_t n, mbstate_t *__restrict ps)) {
   LIBC_CRASH_ON_NULLPTR(pwcs);
   static internal::mbstate internal_mbstate;
   auto result = internal::wcsnrtombs(
diff --git a/libc/src/wchar/wcsrtombs.h b/libc/src/wchar/wcsrtombs.h
index d23573f5b9418..b85e2c6ed740a 100644
--- a/libc/src/wchar/wcsrtombs.h
+++ b/libc/src/wchar/wcsrtombs.h
@@ -17,7 +17,7 @@
 namespace LIBC_NAMESPACE_DECL {
 
 size_t wcsrtombs(char *__restrict s, const wchar_t **__restrict pwcs, size_t n,
-                 mbstate_t *ps);
+                 mbstate_t *__restrict ps);
 
 } // namespace LIBC_NAMESPACE_DECL
 

@vonosmas vonosmas merged commit 9fc353e into llvm:main Oct 22, 2025
22 checks passed
@vonosmas vonosmas deleted the libc-header-fix-1 branch October 22, 2025 18:12
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
* Add FILE type declaration, as it should be presented in `<wchar.h>`,
as well as in `<stdio.h>`
* Fix argument type in `wcsrtombs` / `wcsnrtombs` function - it should
be restrict pointer to `mbstate_t`. Add restrict qualifier to internal
implementation as well.

This brings us closer to being able to build libcxx with wide-character
support against llvm-libc headers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants