Skip to content

Conversation

@vhscampos
Copy link
Member

Define _LIBCPP_HAS_C8RTOMB_MBRTOC8 to 1 if compiling with clang.

Some tests involving functionality from uchar.h/cuchar fail when the platform or the supporting C library does not provide support for the corresponding features. These have been xfailed.

This patch will enable the adoption of newer picolibc versions.

…th clang

Define `_LIBCPP_HAS_C8RTOMB_MBRTOC8` to `1` if compiling with clang.

Some tests involving functionality from `uchar.h`/`cuchar` fail when the
platform or the supporting C library does not provide support for the
corresponding features. These have been xfailed.

This patch will enable the adoption of newer picolibc versions.
@vhscampos vhscampos marked this pull request as ready for review October 29, 2025 08:55
@vhscampos vhscampos requested a review from a team as a code owner October 29, 2025 08:55
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Oct 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 29, 2025

@llvm/pr-subscribers-libcxx

Author: Victor Campos (vhscampos)

Changes

Define _LIBCPP_HAS_C8RTOMB_MBRTOC8 to 1 if compiling with clang.

Some tests involving functionality from uchar.h/cuchar fail when the platform or the supporting C library does not provide support for the corresponding features. These have been xfailed.

This patch will enable the adoption of newer picolibc versions.


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

7 Files Affected:

  • (modified) libcxx/include/__config (+3-1)
  • (modified) libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp (-5)
  • (added) libcxx/test/std/depr/depr.c.headers/uchar_h_char8_t.compile.pass.cpp (+27)
  • (modified) libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp (-5)
  • (added) libcxx/test/std/strings/c.strings/cuchar_char8_t.compile.pass.cpp (+27)
  • (removed) libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp (-30)
  • (modified) libcxx/utils/libcxx/test/features.py (+17)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index b4c081dcdff1b..5971a3c5407b9 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1021,7 +1021,9 @@ typedef __char32_t char32_t;
 // the latter depends on internal GNU libc details that are not appropriate
 // to depend on here, so any declarations present when __cpp_char8_t is not
 // defined are ignored.
-#  if defined(_LIBCPP_GLIBC_PREREQ)
+#  if defined(__clang__)
+#    define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
+#  elif defined(_LIBCPP_GLIBC_PREREQ)
 #    if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
 #      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
 #    else
diff --git a/libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp
index a1560c8ee5853..c448ba83f4b38 100644
--- a/libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp
@@ -23,11 +23,6 @@
 // __STDC_UTF_16__ may or may not be defined by the C standard library
 // __STDC_UTF_32__ may or may not be defined by the C standard library
 
-#if !defined(TEST_HAS_NO_C8RTOMB_MBRTOC8)
-ASSERT_SAME_TYPE(size_t, decltype(mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
-ASSERT_SAME_TYPE(size_t, decltype(c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));
-#endif
-
 ASSERT_SAME_TYPE(size_t, decltype(mbrtoc16((char16_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
 ASSERT_SAME_TYPE(size_t, decltype(c16rtomb((char*)0, (char16_t)0, (mbstate_t*)0)));
 
diff --git a/libcxx/test/std/depr/depr.c.headers/uchar_h_char8_t.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/uchar_h_char8_t.compile.pass.cpp
new file mode 100644
index 0000000000000..864ea2e0a7e59
--- /dev/null
+++ b/libcxx/test/std/depr/depr.c.headers/uchar_h_char8_t.compile.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// The following platforms do not provide mbrtoc8 and c8rtomb so the tests fail
+// XFAIL: target={{.+}}-aix{{.*}}
+// XFAIL: android
+// XFAIL: darwin
+// XFAIL: freebsd
+// XFAIL: windows
+// XFAIL: glibc-no-char8_t-support
+// XFAIL: LIBCXX-PICOLIBC-FIXME
+
+// <uchar.h>
+
+#include <uchar.h>
+
+#include "test_macros.h"
+
+ASSERT_SAME_TYPE(size_t, decltype(mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
+ASSERT_SAME_TYPE(size_t, decltype(c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));
diff --git a/libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp b/libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp
index 2076384deb2b2..96b394a9934f8 100644
--- a/libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp
+++ b/libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp
@@ -23,11 +23,6 @@
 // __STDC_UTF_16__ may or may not be defined by the C standard library
 // __STDC_UTF_32__ may or may not be defined by the C standard library
 
-#if !defined(TEST_HAS_NO_C8RTOMB_MBRTOC8)
-ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
-ASSERT_SAME_TYPE(std::size_t, decltype(std::c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));
-#endif
-
 ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrtoc16((char16_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
 ASSERT_SAME_TYPE(std::size_t, decltype(std::c16rtomb((char*)0, (char16_t)0, (mbstate_t*)0)));
 
diff --git a/libcxx/test/std/strings/c.strings/cuchar_char8_t.compile.pass.cpp b/libcxx/test/std/strings/c.strings/cuchar_char8_t.compile.pass.cpp
new file mode 100644
index 0000000000000..f78f925d72917
--- /dev/null
+++ b/libcxx/test/std/strings/c.strings/cuchar_char8_t.compile.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// The following platforms do not provide mbrtoc8 and c8rtomb so the tests fail
+// XFAIL: target={{.+}}-aix{{.*}}
+// XFAIL: android
+// XFAIL: darwin
+// XFAIL: freebsd
+// XFAIL: windows
+// XFAIL: glibc-no-char8_t-support
+// XFAIL: LIBCXX-PICOLIBC-FIXME
+
+// <cuchar>
+
+#include <cuchar>
+
+#include "test_macros.h"
+
+ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
+ASSERT_SAME_TYPE(std::size_t, decltype(std::c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));
diff --git a/libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp b/libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp
deleted file mode 100644
index 1d4a225668d80..0000000000000
--- a/libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03
-
-#include <uchar.h>
-
-#include "test_macros.h"
-
-// When C++ char8_t support is not enabled, definitions of these functions that
-// match the C2X declarations may still be present in the global namespace with
-// a char8_t typedef substituted for the C++ char8_t type. If so, these are not
-// the declarations we are looking for, so don't test for them.
-#if !defined(TEST_HAS_NO_CHAR8_T)
-using U = decltype(::c8rtomb);
-using V = decltype(::mbrtoc8);
-#  if !_LIBCPP_HAS_C8RTOMB_MBRTOC8
-// expected-error@-3 {{no member named 'c8rtomb' in the global namespace}}
-// expected-error@-3 {{no member named 'mbrtoc8' in the global namespace}}
-#  else
-// expected-no-diagnostics
-#  endif
-#else
-// expected-no-diagnostics
-#endif
diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py
index 7d6e78de343c5..e305b2ff88065 100644
--- a/libcxx/utils/libcxx/test/features.py
+++ b/libcxx/utils/libcxx/test/features.py
@@ -293,6 +293,23 @@ def _mingwSupportsModules(cfg):
           """,
         ),
     ),
+    # Check for Glibc < 2.36, where there was no support for char8_t functions
+    Feature(
+        name="glibc-no-char8_t-support",
+        when=lambda cfg: "__GLIBC__" in compilerMacros(cfg)
+        and not sourceBuilds(
+            cfg,
+            """
+            #include <uchar.h>
+            #include <wchar.h>
+            mbstate_t s;
+            int main(void) {
+                char8_t c;
+                return mbrtoc8(&c, "", 0, &s);
+            }
+            """,
+        ),
+    ),
     Feature(
         name="has-unix-headers",
         when=lambda cfg: sourceBuilds(

@vhscampos
Copy link
Member Author

Hi @philnik777 ,

I've tried to reproduce the CI failure locally with no success. Both with and without using the Docker container. Can you please help me in understanding what's going wrong?

@frederick-vs-ja
Copy link
Contributor

Seems like that Clang mistakenly thought that these functions were not in the global namespace when building the module...

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

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants