aboutsummaryrefslogtreecommitdiff
path: root/libcxx/src
AgeCommit message (Collapse)AuthorFilesLines
2025-01-11[libc++] Improve diagnostic when failing to parse the tzdb (#122125)Louis Dionne1-5/+15
Providing the character that we failed on is helpful for figuring out what's going wrong in the tzdb.
2025-01-10[libc++] Implement a libc++ private version of isascii (#122361)Louis Dionne1-33/+38
The isascii() function is not standard, so we should avoid relying on the platform providing it, especially since it's easy to implement in libc++ portably.
2025-01-09[libc++] Add __iswctype to the locale base API since it's required by ↵Louis Dionne1-5/+5
<locale> (#122168)
2025-01-08[libcxx] Handle windows system error code mapping in std::error_code. (#93101)James Y Knight7-147/+231
The `std::error_code`/`std::error_category` functionality is designed to support multiple error domains. On Unix, both system calls and libc functions return the same error codes, and thus, libc++ today treats `generic_category()` and `system_category()` as being equivalent. However, on Windows, libc functions return `errno.h` error codes in the `errno` global, but system calls return the very different `winerror.h` error codes via `GetLastError()`. As such, there is a need to map the winerror.h error codes into generic errno codes. In libc++, however, the system_error facility does not implement this mapping; instead the mapping is hidden inside libc++, used directly by the std::filesystem implementation. That has a few problems: 1. For std::filesystem APIs, the concrete windows error number is lost, before users can see it. The intent of the distinction between std::error_code and std::error_condition is that the error_code return has the original (potentially more detailed) error code. 2. User-written code which calls Windows system APIs requires this same mapping, so it also can also return error_code objects that other (cross-platform) code can understand. After this commit, an `error_code` with `generic_category()` is used to report an error from `errno`, and, on Windows only, an `error_code` with `system_category()` is used to report an error from `GetLastError()`. On Unix, system_category remains identity-mapped to generic_category, but is never used by libc++ itself. The windows error code mapping is moved into system_error, so that conversion of an `error_code` to `error_condition` correctly translates the `system_category()` code into a `generic_category()` code, when appropriate. This allows code like: `error_code(GetLastError(), system_category()) == errc::invalid_argument` to work as expected -- as it does with MSVC STL. (Continued from old phabricator review [D151493](https://reviews.llvm.org/D151493))
2025-01-08[libc++][NFC] Add missing includes in tzdb.cppLouis Dionne1-0/+3
2025-01-07[libcxx] Use alias for detecting overriden function (#120805)Petr Hosek2-82/+55
This mechanism is preferable in environments like embedded since it doesn't require special handling of the custom section. This is a reland of https://github.com/llvm/llvm-project/pull/114961 which addresses the issue reported by downstream users. Specifically, the two differences from the previous version are: * The internal `symbol##_impl__` symbol in the Mach-O implementation is annotated with `__attribute__((used))` to prevent LTO from deleting it which we've seen in the previous version. * `__is_function_overridden` is marked as `inline` so these symbols are placed in a COMDAT (or fully inlined) to avoid duplicate symbol errors which we've seen in the previous version.
2025-01-07[libcxx] Fix build for glibc < 2.27 (#121893)Yi Kong1-2/+10
PR #109211 introduced a build break on systems with glibc < 2.27, since copy_file_range was only introduced after that version. A version check is added to prevent this breakage.
2025-01-07[libc++] Fix largefile handling in fs::copy_file (#121855)Jannik Glückert1-0/+6
Fix for issues reported in https://github.com/llvm/llvm-project/pull/109211
2025-01-06[libc++] Use copy_file_range for fs::copy (#109211)Jannik Glückert1-33/+139
This optimizes `std::filesystem::copy_file` to use the `copy_file_range` syscall (Linux and FreeBSD) when available. It allows for reflinks on filesystems such as btrfs, zfs and xfs, and server-side copy for network filesystems such as NFS.
2024-12-23[libc++] Refactor some code in monotonic_buffer_resource (#117271)Peng Xie1-19/+18
1. remove unused __default_buffer_alignment 2. two __try_allocate_from_chunk are same, put it together This patch refactor some code in monotonic_buffer_resource.
2024-12-19[libc++] Remove the need for `uselocale()` (#120158)Louis Dionne2-21/+16
Instead of requiring `uselocale()` as part of the base locale API, define __locale_guard in the few places that need it directly, without making __locale_guard part of the base API. In practice, most mainstream platforms never used __locale_guard, so they also didn't need to define uselocale(), and after this patch they actually don't define it anymore.
2024-12-19Revert "[libcxx] Use alias for detecting overriden function (#114961)"Nico Weber2-55/+82
This reverts commit 62bd10f7d18ca6f544286767cae2c9026d493888. Breaks building with -flto=thin, see https://github.com/llvm/llvm-project/pull/114961#issuecomment-2555754056
2024-12-17[libcxx] Support for using timespec_get (#117362)Petr Hosek2-0/+32
clock_gettime is a POSIX API that may not be available on platforms like baremetal; timespec_get is the C11 equivalent. This change adds support for using timespec_get instead of clock_gettime to improve compatibility with non-POSIX platforms. For now, this is only enabled with LLVM libc which implemented timespec_get in #116102, but in the future this can be expanded to other platforms. Related to #84879.
2024-12-17[libcxx] Use alias for detecting overriden function (#114961)Petr Hosek2-82/+55
This mechanism is preferable in environments like embedded since it doesn't require special handling of the custom section.
2024-12-16[libc++] Refactor the Windows and MinGW implementation of the locale base ↵Louis Dionne2-100/+123
API (#115752) This patch reimplements the locale base support for Windows flavors in a way that is more modules-friendly and without defining non-internal names. Since this changes the name of some types and entry points in the built library, this is effectively an ABI break on Windows (which is acceptable after checking with the Windows/libc++ maintainers).
2024-12-02[libc++] Remove obsolete CMake variable (#118119)Louis Dionne1-2/+0
That variable is not referenced anywhere anymore, so it can be removed.
2024-11-28[libc++] Remove the pointer safety functions from the dylib (#117390)Nikolas Klauser2-24/+0
The pointer safety functions were never implemented by anyone in a non-trivial way, which lead us to removing them entirely from the headers when they were removed in C++23. This also means that just about nobody ever called these functions, especially not in production code. Because of that, we expect there to be no references in the wild to the functions in the dylib. Because of that, this patch removes the symbols from the dylib.
2024-11-22[libc++] Add a .clang-tidy file to libcxx/srcNikolas Klauser1-0/+4
This disables `readability-identifier-naming` for the source files, since names don't have to by _Uglified in the source files. We currently don't enforce clang-tidy in the source files, so this is only useful to avoid a bunch of warnings when using an editor that shows the results of clang-tidy.
2024-11-20[libc++] Make __atomic_base into an implementation detail of std::atomic ↵Louis Dionne1-1/+1
(#115764) The __atomic_base base class is only useful to conditionalize the operations we provide inside std::atomic. It shouldn't be used directly from other places in the library which can use std::atomic directly instead. Since we've granularized our includes, using std::atomic directly should not make much of a difference compile-time wise. This patch starts using std::atomic directly from other classes like std::barrier and std::latch. Changing this shouldn't be an ABI break since both classes have the same size and layout. The benefits of this patch are isolating other parts of the code base from implementation details of std::atomic and simplifying the mental model for std::atomic's layers of implementation by making it clear that __atomic_base is only an implementation detail of std::atomic.
2024-11-16[libc++] Avoid including <string> in <mutex> (#116254)Nikolas Klauser4-2/+4
2024-11-13[libc++] Make variables in templates inline (#115785)Nikolas Klauser3-0/+12
The variables are all `constexpr`, which implies `inline`. Since they aren't `constexpr` in C++03 they're also not `inline` there. Because of that we define them out-of-line currently. Instead we can use the C++17 extension of `inline` variables, which results in the same weak definitions of the variables but without having all the boilerplate.
2024-11-06[libc++] Define an internal locale API as a shim on top of the current one ↵Louis Dionne2-145/+145
(#114596) Our current locale base API is a mix of non-reserved system names that we incorrectly (re)define and internal functions and macros starting with __libcpp. This patch introduces a function-based internal interface to isolate the rest of the code base from that mess, so that we can work on refactoring how each platform implements the base API in subsequent patches. This makes it possible to refactor how each platform implements the base localization API without impacting the rest of the code base.
2024-11-06[libc++] Refactor the configuration macros to being always defined (#112094)Nikolas Klauser19-160/+160
This is a follow-up to #89178. This updates the `<__config_site>` macros.
2024-10-31[libc++] Granularize <cstddef> includes (#108696)Nikolas Klauser1-0/+1
2024-10-30Reapply "[libc++] Simplify the implementation of std::sort a bit (#104902)" ↵Nikolas Klauser1-2/+1
(#114023) This reverts commit ef44e4659878f2. The patch was originally reverted because it was deemed to introduce a performance regression for small inputs, however it also fixed a previous performance regression for larger inputs. So overall, this patch is desirable.
2024-10-25[libc++] Refactor locale_guard (#113694)Louis Dionne2-20/+18
Rename __libcpp_locale_guard to just __locale_guard, since there's no reason for it to have __libcpp_ in its name -- it's just an internal utility. Also, define __locale_guard unconditionally of _LIBCPP_LOCALE__L_EXTENSIONS, since that header is only used on Windows (where it has a custom definition) or from bsd_locale_fallbacks.h, which is only included when the L extensions are not provided.
2024-10-25[libc++] __uglify `[[clang::noescape]]` (#113280)A. Jiang1-3/+3
Identifiers `clang` and `noescape` are not reserved by the C++ standard, so perhaps we need to use the equivalent reserved forms. Also changes the occurrences of that attribute to a macro, following the convention for `[[_Clang::__lifetimebound__]]`. Addresses https://github.com/llvm/llvm-project/pull/91651#discussion_r1807852646.
2024-10-23[libc++] Add a escape hatch for making __libcpp_verbose_abort non-noexcept ↵Louis Dionne1-1/+1
again (#113310) This allows a slightly smoother transition for people after #109151, as requested on that PR.
2024-10-21[libcxx][libc] Hand in Hand PoC with from_chars (#91651)Michael Jones3-2/+476
Implements std::from_chars for float and double. The implementation uses LLVM-libc to do the real parsing. Since this is the first time libc++ uses LLVM-libc there is a bit of additional infrastructure code. The patch is based on the [RFC] Project Hand In Hand (LLVM-libc/libc++ code sharing) https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701
2024-10-17[libc++] Make __libcpp_verbose_abort() noexcept like std::terminate() (#109151)Doug Wyatt1-1/+1
Make __libcpp_verbose_abort() noexcept (it is already noreturn), to match std::terminate(). Clang's function effect analysis can use this to ignore such functions as being beyond its scope. (See https://github.com/llvm/llvm-project/pull/99656).
2024-10-12[libc++][RFC] Always define internal feature test macros (#89178)Nikolas Klauser17-64/+64
Currently, the library-internal feature test macros are only defined if the feature is not available, and always have the prefix `_LIBCPP_HAS_NO_`. This patch changes that, so that they are always defined and have the prefix `_LIBCPP_HAS_` instead. This changes the canonical use of these macros to `#if _LIBCPP_HAS_FEATURE`, which means that using an undefined macro (e.g. due to a missing include) is diagnosed now. While this is rather unlikely currently, a similar change in `<__configuration/availability.h>` caught a few bugs. This also improves readability, since it removes the double-negation of `#ifndef _LIBCPP_HAS_NO_FEATURE`. The current patch only touches the macros defined in `<__config>`. If people are happy with this approach, I'll make a follow-up PR to also change the macros defined in `<__config_site>`.
2024-10-10[runtimes][NFC] Reindent CMake files (#111821)Louis Dionne1-97/+97
This is a purely mechanical commit for fixing the indentation of the runtimes' CMakeLists files after #80007. That PR didn't update the indentation in order to make the diff easier to review and for merge conflicts to be easier to resolve (for downstream changes). This doesn't change any code, it only reindents it.
2024-10-10[runtimes] Always define cxx_shared, cxx_static & other targets (#80007)Louis Dionne1-11/+11
This patch always defines the cxx_shared, cxx_static & other top-level targets. However, they are marked as EXCLUDE_FROM_ALL when we don't want to build them. Simply declaring the targets should be of no harm, and it allows other projects to mention these targets regardless of whether they end up being built or not. This patch basically moves the definition of e.g. cxx_shared out of the `if (LIBCXX_ENABLE_SHARED)` and instead marks it as EXCLUDE_FROM_ALL conditionally on whether LIBCXX_ENABLE_SHARED is passed. It then does the same for libunwind and libc++abi targets. I purposefully avoided to reformat the files (which now has inconsistent indentation) because I wanted to keep the diff minimal, and I know this is an area of the code where folks may have downstream diffs. I will re-indent the code separately once this patch lands. This is a reapplication of 79ee0342dbf0, which was reverted in a3539090884c because it broke the TSAN and the Fuchsia builds. Resolves #77654 Differential Revision: https://reviews.llvm.org/D134221
2024-10-09[libc++] Fix broken configuration system-libcxxabi on Apple (#110920)Louis Dionne1-6/+2
On Apple platforms, using system-libcxxabi as an ABI library wouldn't work because we'd try to re-export symbols from libc++abi that the system libc++abi.dylib might not have. Instead, only re-export those symbols when we're using the in-tree libc++abi. This does mean that libc++.dylib won't re-export any libc++abi symbols when building against the system libc++abi, which could be fixed in various ways. However, the best solution really depends on the intended use case, so this patch doesn't try to solve that problem. As a drive-by, also improve the diagnostic message when the user forgets to set the LIBCXX_CXX_ABI_INCLUDE_PATHS variable, which would previously lead to a confusing error. Closes #104672
2024-10-03[libc++] Stop trying to avoid exporting some typeinfo names (#110925)Louis Dionne1-1/+0
When the library was initially written, it was not built with hidden visibility. In an attempt to reduce the number of symbols exported from libc++, an explicit list of symbols to avoid exporting was passed to the linker. This was only done on Apple platforms. Since then, the library has moved on in several ways. First, we now build with hidden visibility by default, so arbitrary symbols don't get exported from the library for no reason. Second, we have proper visibility control via source annotations, so we export exactly what we want to, and we do that from the sources. This patch removes the explicit list of symbols to avoid exporting from the library, which at this point doesn't cover much anyways. The only symbols we will now be exporting that we were not before are some typeinfo names for implementation-detail types. While we technically wouldn't have to export those (I don't think any user can get their hands on those typeinfo names), that makes the library more consistent on all platforms.
2024-09-20Revert "[libc++] Simplify the implementation of std::sort a bit (#104902)"Louis Dionne1-1/+2
This reverts commit d4ffccfce103b01401b8a9222e373f2d404f8439, which caused a performance regression that needs to be investigated further.
2024-09-19[libcxx] Use __libcpp_verbose_abort for error messages (#108873)Petr Hosek3-29/+15
Rather than using the following sequence of calls: ``` fprintf(stderr, "..."); ::abort(); ``` We should use the following: ``` __libcpp_verbose_abort("...") ``` This simplifies the code and ensures the behavior is consistent across all call sites.
2024-09-19[libcxx] No _LIBCPP_ELAST needed for LLVM libc (#108739)Petr Hosek1-0/+2
LLVM libc can handle out-of-range errno values.
2024-09-17[libc++][NFC] Replace uses of NULL by nullptr (#108847)Louis Dionne7-22/+22
Closes #108741
2024-09-11[libc++] Get rid of experimental/__config (#108233)Louis Dionne2-2/+2
It doesn't serve much of a purpose since we can easily put its contents inside __config. Removing it simplifies the modulemap once we are trying to create a single top-level module.
2024-09-11[libc++][NFC] Replace _LIBCPP_NORETURN and TEST_NORETURN with [[noreturn]] ↵Nikolas Klauser9-18/+18
(#80455) `[[__noreturn__]]` is now always available, so we can simply use the attribute directly instead of through a macro.
2024-09-09[PAC] Make __is_function_overridden pauth-aware on ELF platforms (#107498)Anton Korobeynikov1-0/+5
Apparently, there are two almost identical implementations: one for MachO and another one for ELF. The ELF bits somehow slipped while https://github.com/llvm/llvm-project/pull/84573 was reviewed. The particular implementation is identical to MachO case.
2024-09-09[libc++] Cache file attributes during directory iteration (#93316)Eduard Satdarov2-10/+17
This patch adds caching of file attributes during directory iteration on Windows. This improves the performance when working with files being iterated on in a directory.
2024-09-05[libc++][NFC] Increase consistency for namespace closing commentsLouis Dionne9-11/+11
2024-08-31[libcxx] Do not include `langinfo.h` when using the LLVM C library (#106634)Joseph Huber1-1/+1
Summary: The `langinfo.h` header is a POSIX extension, so ideally we would be able to build the C++ library without it. Currently the LLVM C library doesn't support / provide it. This allows us to build the C++ library with locales enabled. We can either disable it here, or just provide stubs that do nothing as in https://github.com/llvm/llvm-project/pull/106620.
2024-08-30[libc++][NFC] Run clang-format on libcxx/includeLouis Dionne1-1/+1
This re-formats a few headers that had become out-of-sync with respect to formatting since we ran clang-format on the whole codebase. There's surprisingly few instances of it.
2024-08-28[libc++] Run the Lit test suite against an installed version of the library ↵Louis Dionne1-2/+0
(#96910) We always strive to test libc++ as close as possible to the way we are actually shipping it. This was approximated reasonably well by setting up the minimal driver flags when running the test suite, however we were running the test suite against the library located in the build directory. This patch improves the situation by installing the library (the headers, the built library, modules, etc) into a fake location and then running the test suite against that fake "installation root". This should open the door to getting rid of the temporary copy of the headers we make during the build process, however this is left for a future improvement. Note that this adds quite a bit of verbosity whenever running the test suite because we install the headers beforehand every time. We should be able to override this to silence it, however CMake doesn't currently give us a way to do that, see https://gitlab.kitware.com/cmake/cmake/-/issues/26085.
2024-08-27[libc++] Deprecate and remove std::uncaught_exception (#101830)A. Jiang1-0/+3
Works towards P0619R4/#99985. - std::uncaught_exception was not previously deprecated. This patch deprecates it since C++17 as per N4259. std::uncaught_exceptions is used instead as libc++ unconditionally provides this function. - _LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION restores std::uncaught_exception. - As a drive-by, this patch updates the C++20 status page to explain that D.11 is already done, since it was done in 578d09c1b195d859ca7e62840ff6bb83421a77b5.
2024-08-27[libc++] Simplify the implementation of std::sort a bit (#104902)Nikolas Klauser1-2/+1
This does a few things to canonicalize the library a bit. Specifically - use `__desugars_to_v` instead of the custom `__is_simple_comparator` - make `__use_branchless_sort` an inline variable - remove the `_maybe_branchless` versions of the `__sortN` functions and overload based on whether we can do branchless sorting instead.
2024-08-16[libc++] Fix backslash as root dir breaks lexically_relative, ↵RichardLuo1-2/+3
lexically_proximate and hash_value on Windows (#99780) Various functions like hash_value, lexically_proximate and lexically_relative would incorrectly handle backslashes in the root directory on Windows, causing behavior that is inconsistent with the equality comparison for a path.