[libcxx-commits] [libcxx] [libcxx] Define _LIBCPP_HAS_C8RTOMB_MBRTOC8 for picolibc (PR #152724)

Victor Campos via libcxx-commits libcxx-commits at lists.llvm.org
Mon Aug 11 07:10:47 PDT 2025


https://github.com/vhscampos updated https://github.com/llvm/llvm-project/pull/152724

>From cd932a1733dc82b90613f4e4ee1ecc864a70e153 Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Thu, 7 Aug 2025 16:03:44 +0100
Subject: [PATCH 1/3] [libcxx] Define _LIBCPP_HAS_C8RTOMB_MBRTOC8 for picolibc

Starting from picolibc 1.8.9, the `char8_t` related functions are
provided.

This patch adds logic to detect the underlying picolibc version and
define the `_LIBCPP_HAS_C8RTOMB_MBRTOC8 macro` accordingly.
---
 libcxx/include/__config                   | 8 ++++++--
 libcxx/include/__configuration/platform.h | 4 ++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__config b/libcxx/include/__config
index 77a71b6cf1cae..ab87ed4787b84 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1027,8 +1027,12 @@ typedef __char32_t char32_t;
 #    else
 #      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
 #    endif
-#  else
-#    define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
+#  elif defined (_LIBCPP_PICOLIBC_PREREQ)
+#    if _LIBCPP_PICOLIBC_PREREQ(1, 8, 9) && defined(__cpp_char8_t)
+#      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
+#    else
+#      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
+#    endif
 #  endif
 
 // There are a handful of public standard library types that are intended to
diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h
index f3c199dee172b..4f581a352038f 100644
--- a/libcxx/include/__configuration/platform.h
+++ b/libcxx/include/__configuration/platform.h
@@ -47,6 +47,10 @@
 //       user code. Move code paths that need _NEWLIB_VERSION to another customization mechanism.
 #if __has_include(<picolibc.h>)
 #  include <picolibc.h>
+#  define _LIBCPP_PICOLIBC_VERSION_INT(maj, min, patch) (maj * 10000 + min * 100 + patch)
+#  define _LIBCPP_PICOLIBC_PREREQ(maj, min, patch)                                                                     \
+    _LIBCPP_PICOLIBC_VERSION_INT(__PICOLIBC__, __PICOLIBC_MINOR__, __PICOLIBC_PATCHLEVEL__) >=                         \
+        _LIBCPP_PICOLIBC_VERSION_INT(maj, min, patch)
 #endif
 
 #ifndef __BYTE_ORDER__

>From b60649719eae9693b3cdffa07b44460ee4d4eddf Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Fri, 8 Aug 2025 14:50:07 +0100
Subject: [PATCH 2/3] Fix clang-format issue

---
 libcxx/include/__config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__config b/libcxx/include/__config
index ab87ed4787b84..3dc4d3ce0ed58 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1027,7 +1027,7 @@ typedef __char32_t char32_t;
 #    else
 #      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
 #    endif
-#  elif defined (_LIBCPP_PICOLIBC_PREREQ)
+#  elif defined(_LIBCPP_PICOLIBC_PREREQ)
 #    if _LIBCPP_PICOLIBC_PREREQ(1, 8, 9) && defined(__cpp_char8_t)
 #      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
 #    else

>From 8d87631ab35304dba67322106570bbbc330b6d13 Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Mon, 11 Aug 2025 10:01:18 +0100
Subject: [PATCH 3/3] Refactor the preprocessor logic

---
 libcxx/include/__config | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__config b/libcxx/include/__config
index 3dc4d3ce0ed58..e21d108ccf328 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1021,18 +1021,22 @@ 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.
+//
+// picolibc 1.8.9 and newer declare the two functions unconditionally.
 #  if defined(_LIBCPP_GLIBC_PREREQ)
-#    if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
+#    if defined(__cpp_char8_t) && _LIBCPP_GLIBC_PREREQ(2, 36)
 #      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
 #    else
 #      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
 #    endif
 #  elif defined(_LIBCPP_PICOLIBC_PREREQ)
-#    if _LIBCPP_PICOLIBC_PREREQ(1, 8, 9) && defined(__cpp_char8_t)
+#    if _LIBCPP_PICOLIBC_PREREQ(1, 8, 9)
 #      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
 #    else
 #      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
 #    endif
+#  else
+#    define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
 #  endif
 
 // There are a handful of public standard library types that are intended to



More information about the libcxx-commits mailing list