Skip to content

[libc++] Redefine Fuchsia locale base support on top of the new API #122489

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 8 commits into from
Jan 13, 2025

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Jan 10, 2025

This follows the same path we've been doing for all platforms so far, moving away from the old definition of the locale base API.

This follows the same path we've been doing for all platforms so far,
moving away from the old definition of the locale base API.
@ldionne ldionne requested a review from a team as a code owner January 10, 2025 16:24
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 10, 2025

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

This follows the same path we've been doing for all platforms so far, moving away from the old definition of the locale base API.


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

7 Files Affected:

  • (modified) libcxx/include/CMakeLists.txt (+3-1)
  • (modified) libcxx/include/__locale_dir/locale_base_api.h (+2-2)
  • (removed) libcxx/include/__locale_dir/locale_base_api/fuchsia.h (-18)
  • (added) libcxx/include/__locale_dir/support/fuchsia.h (+140)
  • (added) libcxx/include/__locale_dir/support/no_locale/characters.h (+98)
  • (added) libcxx/include/__locale_dir/support/no_locale/strtonum.h (+49)
  • (modified) libcxx/include/module.modulemap (+3-1)
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index f7721b1047b81e..f3dc740a88449c 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -499,7 +499,6 @@ set(files
   __locale_dir/locale_base_api.h
   __locale_dir/locale_base_api/android.h
   __locale_dir/locale_base_api/bsd_locale_fallbacks.h
-  __locale_dir/locale_base_api/fuchsia.h
   __locale_dir/locale_base_api/ibm.h
   __locale_dir/locale_base_api/musl.h
   __locale_dir/locale_base_api/openbsd.h
@@ -507,6 +506,9 @@ set(files
   __locale_dir/support/apple.h
   __locale_dir/support/bsd_like.h
   __locale_dir/support/freebsd.h
+  __locale_dir/support/fuchsia.h
+  __locale_dir/support/no_locale/characters.h
+  __locale_dir/support/no_locale/strtonum.h
   __locale_dir/support/windows.h
   __math/abs.h
   __math/copysign.h
diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
index bb0da889f4c845..b112a4aef7765a 100644
--- a/libcxx/include/__locale_dir/locale_base_api.h
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -99,6 +99,8 @@
 #  include <__locale_dir/support/freebsd.h>
 #elif defined(_LIBCPP_MSVCRT_LIKE)
 #  include <__locale_dir/support/windows.h>
+#elif defined(__Fuchsia__)
+#  include <__locale_dir/support/fuchsia.h>
 #else
 
 // TODO: This is a temporary definition to bridge between the old way we defined the locale base API
@@ -111,8 +113,6 @@
 #    include <__locale_dir/locale_base_api/android.h>
 #  elif defined(__OpenBSD__)
 #    include <__locale_dir/locale_base_api/openbsd.h>
-#  elif defined(__Fuchsia__)
-#    include <__locale_dir/locale_base_api/fuchsia.h>
 #  elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC
 #    include <__locale_dir/locale_base_api/musl.h>
 #  endif
diff --git a/libcxx/include/__locale_dir/locale_base_api/fuchsia.h b/libcxx/include/__locale_dir/locale_base_api/fuchsia.h
deleted file mode 100644
index f6ef454ba7ada7..00000000000000
--- a/libcxx/include/__locale_dir/locale_base_api/fuchsia.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// -*- 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 _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_FUCHSIA_H
-#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_FUCHSIA_H
-
-#include <__support/xlocale/__posix_l_fallback.h>
-#include <__support/xlocale/__strtonum_fallback.h>
-#include <cstdlib>
-#include <cwchar>
-
-#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_FUCHSIA_H
diff --git a/libcxx/include/__locale_dir/support/fuchsia.h b/libcxx/include/__locale_dir/support/fuchsia.h
new file mode 100644
index 00000000000000..43c8ba23ade077
--- /dev/null
+++ b/libcxx/include/__locale_dir/support/fuchsia.h
@@ -0,0 +1,140 @@
+//===-----------------------------------------------------------------------===//
+//
+// 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 _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H
+#define _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H
+
+#include <__config>
+#include <cstdlib>
+#include <cwchar>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+namespace __locale {
+
+struct __locale_guard {
+  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
+
+  _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
+    if (__old_loc_)
+      ::uselocale(__old_loc_);
+  }
+
+  locale_t __old_loc_;
+
+  __locale_guard(__locale_guard const&)            = delete;
+  __locale_guard& operator=(__locale_guard const&) = delete;
+};
+
+//
+// Locale management
+//
+using __locale_t = locale_t;
+
+inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) {
+  return ::newlocale(__category_mask, __name, __loc);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); }
+
+inline _LIBCPP_HIDE_FROM_ABI lconv* __localeconv(__locale_t& __loc) {
+  __locale_guard __current(__loc);
+  return std::localeconv();
+}
+
+//
+// Other functions
+//
+inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) {
+  __locale_guard __current(__loc);
+  return MB_CUR_MAX;
+}
+#if _LIBCPP_HAS_WIDE_CHARACTERS
+inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __ch, __locale_t __loc) {
+  __locale_guard __current(__loc);
+  return std::btowc(__ch);
+}
+inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __ch, __locale_t __loc) {
+  __locale_guard __current(__loc);
+  return std::wctob(__ch);
+}
+inline _LIBCPP_HIDE_FROM_ABI size_t
+__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) {
+  __locale_guard __current(__loc);
+  return ::wcsnrtombs(__dest, __src, __nwc, __len, __ps); // non-standard
+}
+inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __ch, mbstate_t* __ps, __locale_t __loc) {
+  __locale_guard __current(__loc);
+  return std::wcrtomb(__s, __ch, __ps);
+}
+inline _LIBCPP_HIDE_FROM_ABI size_t
+__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) {
+  __locale_guard __current(__loc);
+  return ::mbsnrtowcs(__dest, __src, __nms, __len, __ps); // non-standard
+}
+inline _LIBCPP_HIDE_FROM_ABI size_t
+__mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
+  __locale_guard __current(__loc);
+  return std::mbrtowc(__pwc, __s, __n, __ps);
+}
+inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
+  __locale_guard __current(__loc);
+  return std::mbtowc(__pwc, __pmb, __max);
+}
+inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
+  __locale_guard __current(__loc);
+  return std::mbrlen(__s, __n, __ps);
+}
+inline _LIBCPP_HIDE_FROM_ABI size_t
+__mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) {
+  __locale_guard __current(__loc);
+  return ::mbsrtowcs(__dest, __src, __len, __ps);
+}
+#endif
+
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
+_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
+#ifdef _LIBCPP_COMPILER_CLANG_BASED
+#  define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
+#else
+#  define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */
+#endif
+
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf(
+    char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) {
+  __locale_guard __current(__loc);
+  return std::snprintf(__s, __n, __format, std::forward<_Args>(__args)...);
+}
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(
+    char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
+  __locale_guard __current(__loc);
+  return ::asprintf(__s, __format, std::forward<_Args>(__args)...); // non-standard
+}
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
+    const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
+  __locale_guard __current(__loc);
+  return std::sscanf(__s, __format, std::forward<_Args>(__args)...);
+}
+
+_LIBCPP_DIAGNOSTIC_POP
+#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
+
+} // namespace __locale
+_LIBCPP_END_NAMESPACE_STD
+
+#include <__locale_dir/support/no_locale/characters.h>
+#include <__locale_dir/support/no_locale/strtonum.h>
+
+#endif // _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H
diff --git a/libcxx/include/__locale_dir/support/no_locale/characters.h b/libcxx/include/__locale_dir/support/no_locale/characters.h
new file mode 100644
index 00000000000000..20e45fc350e2ef
--- /dev/null
+++ b/libcxx/include/__locale_dir/support/no_locale/characters.h
@@ -0,0 +1,98 @@
+//===-----------------------------------------------------------------------===//
+//
+// 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 _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CHARACTERS_H
+#define _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CHARACTERS_H
+
+#include <__config>
+#include <__cstddef/size_t.h>
+#include <cctype>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+#if _LIBCPP_HAS_WIDE_CHARACTERS
+#  include <cwctype>
+#endif
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+namespace __locale {
+
+//
+// Character manipulation functions
+//
+inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t) { return std::islower(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t) { return std::isupper(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t) { return std::isdigit(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t) { return std::isxdigit(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t) { return std::toupper(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __c, __locale_t) { return std::tolower(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t) {
+  return std::strcoll(__s1, __s2);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t) {
+  return std::strxfrm(__dest, __src, __n);
+}
+
+#if _LIBCPP_HAS_WIDE_CHARACTERS
+inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t) {
+  return std::iswctype(__c, __type);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t) { return std::iswspace(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t) { return std::iswprint(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __c, __locale_t) { return std::iswcntrl(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __c, __locale_t) { return std::iswupper(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __c, __locale_t) { return std::iswlower(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __c, __locale_t) { return std::iswalpha(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __c, __locale_t) { return std::iswblank(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __c, __locale_t) { return std::iswdigit(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __c, __locale_t) { return std::iswpunct(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __c, __locale_t) { return std::iswxdigit(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __c, __locale_t) { return std::towupper(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __c, __locale_t) { return std::towlower(__c); }
+
+inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t) {
+  return std::wcscoll(__ws1, __ws2);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t) {
+  return std::wcsxfrm(__dest, __src, __n);
+}
+#endif // _LIBCPP_HAS_WIDE_CHARACTERS
+
+inline _LIBCPP_HIDE_FROM_ABI size_t
+__strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t) {
+  return std::strftime(__s, __max, __format, __tm);
+}
+
+} // namespace __locale
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CHARACTERS_H
diff --git a/libcxx/include/__locale_dir/support/no_locale/strtonum.h b/libcxx/include/__locale_dir/support/no_locale/strtonum.h
new file mode 100644
index 00000000000000..0e7a32993e7369
--- /dev/null
+++ b/libcxx/include/__locale_dir/support/no_locale/strtonum.h
@@ -0,0 +1,49 @@
+//===-----------------------------------------------------------------------===//
+//
+// 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 _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_STRTONUM_H
+#define _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_STRTONUM_H
+
+#include <__config>
+#include <cstdlib>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+namespace __locale {
+
+//
+// Strtonum functions
+//
+inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t) {
+  return std::strtof(__nptr, __endptr);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t) {
+  return std::strtod(__nptr, __endptr);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t) {
+  return std::strtold(__nptr, __endptr);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t) {
+  return std::strtoll(__nptr, __endptr, __base);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI unsigned long long
+__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t) {
+  return std::strtoull(__nptr, __endptr, __base);
+}
+
+} // namespace __locale
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_STRTONUM_H
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index 07ab5649ae45cb..baa6dc0c3f7c36 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -1478,13 +1478,15 @@ module std [system] {
       textual header "__locale_dir/support/apple.h"
       textual header "__locale_dir/support/bsd_like.h"
       textual header "__locale_dir/support/freebsd.h"
+      textual header "__locale_dir/support/fuchsia.h"
+      textual header "__locale_dir/support/no_locale/characters.h"
+      textual header "__locale_dir/support/no_locale/strtonum.h"
       textual header "__locale_dir/support/windows.h"
     }
 
     module locale_base_api {
       textual header "__locale_dir/locale_base_api/android.h"
       textual header "__locale_dir/locale_base_api/bsd_locale_fallbacks.h"
-      textual header "__locale_dir/locale_base_api/fuchsia.h"
       textual header "__locale_dir/locale_base_api/ibm.h"
       textual header "__locale_dir/locale_base_api/musl.h"
       textual header "__locale_dir/locale_base_api/openbsd.h"

@ldionne
Copy link
Member Author

ldionne commented Jan 10, 2025

@mysterymath Can you please let me know if this patch passes on Fuchsia? This is the preferred way for us to define the locale base API for Fuchsia (it follows what we're migrating towards for other platforms as well).

@mysterymath
Copy link
Contributor

It looks like this still results in a different build failure:

https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci.shadow/clang-linux-x64/b8726107014473846721/overview

FAILED: libcxx/src/CMakeFiles/cxx_shared.dir/vector.cpp.obj 
/b/s/w/ir/x/w/llvm_build/./bin/clang++ --target=x86_64-unknown-fuchsia --sysroot=/b/s/w/ir/x/w/sdk/arch/x64/sysroot -DLIBCXX_BUILDING_LIBCXXABI -DLIBC_NAMESPACE=__llvm_libc_common_utils -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/s/w/ir/x/w/github-ldionne-llvm-project/libcxx/src -I/b/s/w/ir/x/w/llvm_build/include/x86_64-unknown-fuchsia/c++/v1 -I/b/s/w/ir/x/w/llvm_build/include/c++/v1 -I/b/s/w/ir/x/w/github-ldionne-llvm-project/libcxxabi/include -I/b/s/w/ir/x/w/github-ldionne-llvm-project/runtimes/cmake/Modules/../../../libc --target=x86_64-unknown-fuchsia -I/b/s/w/ir/x/w/sdk/pkg/sync/include -I/b/s/w/ir/x/w/sdk/pkg/fdio/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/b/s/w/ir/x/w/llvm_build/runtimes/runtimes-x86_64-unknown-fuchsia-bins=../../../github-ldionne-llvm-project -ffile-prefix-map=/b/s/w/ir/x/w/github-ldionne-llvm-project/= -no-canonical-prefixes -O2 -g -DNDEBUG -std=c++2b -fPIC -UNDEBUG -faligned-allocation -nostdinc++ -fvisibility-inlines-hidden -fvisibility=hidden -fsized-deallocation -Wall -Wextra -Wnewline-eof -Wshadow -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type -Wextra-semi -Wundef -Wunused-template -Wformat-nonliteral -Wzero-length-array -Wdeprecated-redundant-constexpr-static-def -Wno-user-defined-literals -Wno-covered-switch-default -Wno-suggest-override -Wno-error -MD -MT libcxx/src/CMakeFiles/cxx_shared.dir/vector.cpp.obj -MF libcxx/src/CMakeFiles/cxx_shared.dir/vector.cpp.obj.d -o libcxx/src/CMakeFiles/cxx_shared.dir/vector.cpp.obj -c /b/s/w/ir/x/w/github-ldionne-llvm-project/libcxx/src/vector.cpp
In file included from /b/s/w/ir/x/w/github-ldionne-llvm-project/libcxx/src/vector.cpp:9:
In file included from /b/s/w/ir/x/w/llvm_build/include/c++/v1/vector:326:
In file included from /b/s/w/ir/x/w/llvm_build/include/c++/v1/__vector/vector_bool_formatter.h:15:
In file included from /b/s/w/ir/x/w/llvm_build/include/c++/v1/__format/formatter_bool.h:19:
In file included from /b/s/w/ir/x/w/llvm_build/include/c++/v1/__format/formatter_integral.h:36:
In file included from /b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale:14:
In file included from /b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/locale_base_api.h:103:
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/support/fuchsia.h:24:72: error: no member named 'uselocale' in the global namespace
   24 |   _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
      |                                                                      ~~^
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/support/fuchsia.h:28:9: error: no type named 'uselocale' in the global namespace
   28 |       ::uselocale(__old_loc_);
      |       ~~^
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/support/fuchsia.h:28:19: warning: declaration shadows a field of 'std::__locale::__locale_guard' [-Wshadow]
   28 |       ::uselocale(__old_loc_);
      |                   ^
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/support/fuchsia.h:31:12: note: previous declaration is here
   31 |   locale_t __old_loc_;
      |            ^
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/support/fuchsia.h:43:10: error: no member named 'newlocale' in the global namespace; did you mean '__newlocale'?
   43 |   return ::newlocale(__category_mask, __name, __loc);
      |          ^~~~~~~~~~~
      |          __newlocale
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/support/fuchsia.h:42:41: note: '__newlocale' declared here
   42 | inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) {
      |                                         ^
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/support/fuchsia.h:46:70: error: no type named 'freelocale' in the global namespace
   46 | inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); }
      |                                                                    ~~^
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/support/fuchsia.h:46:81: warning: declaration shadows a local variable [-Wshadow]
   46 | inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); }
      |                                                                                 ^
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/support/fuchsia.h:46:59: note: previous declaration is here
   46 | inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); }
      |                                                           ^
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/support/fuchsia.h:48:30: error: unknown type name 'lconv'
   48 | inline _LIBCPP_HIDE_FROM_ABI lconv* __localeconv(__locale_t& __loc) {
      |                              ^
/b/s/w/ir/x/w/llvm_build/include/c++/v1/__locale_dir/support/fuchsia.h:50:15: error: no member named 'localeconv' in namespace 'std'
   50 |   return std::localeconv();
      |          ~~~~~^
2 warnings and 6 errors generated.

@ldionne
Copy link
Member Author

ldionne commented Jan 10, 2025

@mysterymath I think my latest push should fix the issue. But this isn't going to be very productive if we have to go back and forth like this, can you please take this patch as a basis and figure out what needs to change in order to make it work on Fuchsia? It should be pretty close modulo a few obvious issues I can't really fix without having access to your setup.

Use clocale so std::localeconv works.
Copy link

github-actions bot commented Jan 10, 2025

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

Add `<utility>`
Correct include order.
Include cstdio.
@mysterymath
Copy link
Contributor

Alright, the latest version of this just passed a Fuchsia CI tryjob: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci.shadow/clang-linux-x64/b8726080809167290305/overview

It should be good to go, pending libcxx review.

@ldionne
Copy link
Member Author

ldionne commented Jan 13, 2025

Thanks @mysterymath ! I'm going to merge this since you had it passing on your end (and our CI coverage for this patch is irrelevant since we don't test the affected platform).

@ldionne ldionne merged commit b5ba4f0 into llvm:main Jan 13, 2025
11 of 15 checks passed
@ldionne ldionne deleted the review/locale/redefine-fuchsia branch January 13, 2025 14:16
kazutakahirata pushed a commit to kazutakahirata/llvm-project that referenced this pull request Jan 13, 2025
…lvm#122489)

This follows the same path we've been doing for all platforms so far,
moving away from the old definition of the locale base API.

Co-authored-by: Daniel Thornburgh <mysterymath@gmail.com>
aheejin added a commit to emscripten-core/emscripten that referenced this pull request May 21, 2025
This updates libcxx and libcxxabi to LLVM 20.1.4:
https://github.com/llvm/llvm-project/releases/tag/llvmorg-20.1.4

Before going into each additional change of the PR, these are some
noteworthy changes from this LLVM release:

- Freezing C++03 headers
- RFC:
https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc/77319
  - PRs:
    - llvm/llvm-project#108999
    - llvm/llvm-project#109000
    - llvm/llvm-project#109001
    - llvm/llvm-project#109002
    - 
This copies libc++ headers of the last LLVM 19 release into a separate
directory
(https://github.com/llvm/llvm-project/tree/main/libcxx/include/__cxx03)
and redirects all C++03 workflow there. The motivation is not to fix
C++03 related changes unless they are critical bugs, and simplifies the
main headers. So the main headers are like
  ```
  #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
  #  include <__cxx03/algorithm>
  #else
  ... main header content ...
  ```

As you can see it looks like we can avoid opting into this by not
defining `_LIBCPP_USE_FROZEN_CXX03_HEADERS` at the moment. I think their
eventual goal is to remove C++03 support from the main headers but it
hasn't seem to have happened yet and I don't know what their timeline
for that is.

Adding that `__cxx03` directory increases the header size by 10MB. We
can get away not using them by not defining
`_LIBCPP_USE_FROZEN_CXX03_HEADERS` in this release, so this update does
not include that directory.

- Sharing of headers between libc++ and libc (Project Hand in Hand)
- RFC:
https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701
- PR: llvm/llvm-project#91651 (More are likely
to come)

This tries to share some libc headers from libcxx. libcxx's source files
can depend on headers from `libc/shared`, `libc/src/__support`,
`libc/include/llvm-libc-macros`, and `libc/include/llvm-libc-types`. And
it turns out libcxx can also depend on `libc/hdr`, even though the
directory is not in the diagram in the RFC.

These headers can be only included from `libcxx/src` and not
`libcxx/include`, to prevent libcxx's API from changing. So these
headers don't need to be copied into `cache/`.

- Locale API reimplementation
  It doesn't seem to have an RFC, but the PRs are:
  - llvm/llvm-project#113737
  - llvm/llvm-project#115176
  - llvm/llvm-project#115752
  - llvm/llvm-project#122489

It looks this aims provide a new way to define locale API for each
platform. Currently Apple, FreeBSD, MSVCRT, and Fuschia are using the
new API and the others are still using the old one:
https://github.com/llvm/llvm-project/blob/ec28b8f9cc7f2ac187d8a617a6d08d5e56f9120e/libcxx/include/__locale_dir/locale_base_api.h#L116-L138
For our purpose, adding `if defined(__EMSCRIPTEN__)` entry to the list
of "old" list seems to work for the moment, but we may need to move to
the new way eventually later.

---

Additional changes:

- Copy `vendor/llvm/default_assertion_handler.in` to
`__assertion_handler`:
aa53648
Our previous `__assertion_handler` was copied from
`libcxx/vendor/llvm/default_assertion_handler.in`. This updates our
`__assertion_handler` to the new
`libcxx/vendor/llvm/default_assertion_handler.in`. For what this file
is, see the PR description of #22994, with which the file was added.

- Remove `libcxx/include/__cxx03` directory:
d646f6b
As I described in "Freezing C++ headers" above, C++03 headers were
copied to `include/cxx03` to be "frozen". But by not defining
`_LIBCPP_USE_FROZEN_CXX03_HEADERS` we can still use the main headers.
This new `__cxx03` header directory is almost 10M and we are not using
it in this update, this deletes it.

- Define more variables in `__config_site`:
9912236
libcxx decides to almost all configuration macros to be defined. So
before it tested whether a macro was defined/undefined, and now it
assumes it is defined and tests whether its value is 1/0.

Before llvm/llvm-project#112094
`_config_site.in` used to use `#cmakedefine`, which only defined
variables when they were enabled, but now it uses `#cmakedefine01`,
which always defines variables and assigns 1 or 0 depending on whether
the feature is enabled.

So this change adds `#define` to each variable that `_config_site.in`
has an entry of. The value assigned is 1 if it was defined in our
previous Emscripten environment and 0 if not.

- Fix Emscripten's locale:
2ae01b0
Before, the code was like
https://github.com/emscripten-core/emscripten/blob/dc1abd514b1bade135a01a4453a9ff6def0793b6/system/lib/libcxx/include/__locale_dir/locale_base_api.h#L12-L30
But now they are divided into two parts, one using the new API and the
other using old. See "Locale API reimplementation" above.

https://github.com/llvm/llvm-project/blob/ec28b8f9cc7f2ac187d8a617a6d08d5e56f9120e/libcxx/include/__locale_dir/locale_base_api.h#L116-L138
This adds Emscripten in the beginning of the "old" API list. (This has
to be the beginning; see #23414)

- Import libc headers used by libcxx:
12a4ee4,
12a4ee4
and
43c8ce4
This imports a part of libc headers into `system/lib/llvm-libc`. The
imported directories are:
  - `libc/shared`
  - `libc/src/__support`
  - `libc/include/llvm-libc-macros`
  - `libc/include/llvm-libc-types`
  - `libc/hdr`
  See "sharing of headers between libc+ and libc" above for details.
This also applies llvm/llvm-project#133999,
which is a bugfix that has not be backported, which fixes the bug of
including from a wrong directory.

- `std::uncaught_exception` -> `std::uncaught_exceptions`:
1bf4e78
`std::uncaught_exception` has been deprecated in C++17, so it generates
a warning (which we treat as an error). Replaced it with
`std::uncaught_exceptions`, which returns the number of uncaught
exceptions (but can still be used as a boolean in the test).

- Remove `ryu_constants.h` and `ryu_long_double_constants.h` from libc:
5767ac4
These are not used from libcxx and `ryu_long_double_constants.h` is huge
(12M).
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.

4 participants