aboutsummaryrefslogtreecommitdiff
path: root/libcxx/src
AgeCommit message (Collapse)AuthorFilesLines
10 days[libc++] Refactor memory allocation in basic_string (#128423)Nikolas Klauser1-16/+4
This patch introduces a string-internal API to make the allocation and deallocation the long string simpler. Before this we had a lot of code duplication, so ensuring that things were actually correct was non-trivial.
12 days[libc++] Replace __resize_default_init with resize_and_overwrite (#157121)Nikolas Klauser1-7/+6
Since `__resize_default_init` is only ever used inside the dylib we can remove the libc++-internal API and switch to the public one. This patch inlines a bunch of functions that aren't required anymore and simplifies the code that way.
2025-09-04[libc++][NFC] Use llvm.org/PR to link to bug reports (#156288)Nikolas Klauser2-2/+2
We've built up quite a few links directly to github within the code base. We should instead use `llvm.org/PR<issue-number>` to link to bugs, since that is resilient to the bug tracker changing in the future. This is especially relevant for tests linking to bugs, since they will probably be there for decades to come. A nice side effect is that these links are significantly shorter than the GH links, making them much less of an eyesore. This patch also replaces a few links that linked to the old bugzilla instance on llvm.org.
2025-08-28[libc++] Fix broken precondition of __bit_log2 (#155476)Louis Dionne1-0/+3
In #135303, we started using `__bit_log2` instead of `__log2i` inside `std::sort`. However, `__bit_log2` has a precondition that `__log2i` didn't have, which is that the input is non-zero. While it technically makes no sense to request the logarithm of 0, `__log2i` handled that case and returned 0 without issues. After switching to `__bit_log2`, passing 0 as an input results in an unsigned integer overflow which can trigger `-fsanitize=unsigned-integer-overflow`. While not technically UB in itself, it's clearly not intended either. To fix this, we add an internal assertion to `__bit_log2` which catches the issue in our test suite, and we make sure not to violate `__bit_log2`'s preconditions before we call it from `std::sort`.
2025-08-20[libc++] Avoid string reallocation in ↵Timothy Choi1-1/+3
`std::filesystem::path::lexically_relative` (#152964) Improves runtime by around 20 to 40%. (1.3x to 1.7x) ``` Benchmark Time CPU Time Old Time New CPU Old CPU New ------------------------------------------------------------------------------------------------------------------------------------------------ BM_LexicallyRelative/small_path/2 -0.2111 -0.2082 229 181 228 180 BM_LexicallyRelative/small_path/4 -0.2579 -0.2550 455 338 452 337 BM_LexicallyRelative/small_path/8 -0.2643 -0.2616 844 621 838 619 BM_LexicallyRelative/small_path/16 -0.2582 -0.2556 1562 1158 1551 1155 BM_LexicallyRelative/small_path/32 -0.2518 -0.2496 3023 2262 3004 2254 BM_LexicallyRelative/small_path/64 -0.2806 -0.2775 6344 4564 6295 4549 BM_LexicallyRelative/small_path/128 -0.2165 -0.2137 11762 9216 11683 9186 BM_LexicallyRelative/small_path/256 -0.2672 -0.2645 24499 17953 24324 17891 BM_LexicallyRelative/large_path/2 -0.3268 -0.3236 426 287 422 285 BM_LexicallyRelative/large_path/4 -0.3274 -0.3248 734 494 729 492 BM_LexicallyRelative/large_path/8 -0.3586 -0.3560 1409 904 1399 901 BM_LexicallyRelative/large_path/16 -0.3978 -0.3951 2764 1665 2743 1659 BM_LexicallyRelative/large_path/32 -0.3934 -0.3908 5323 3229 5283 3218 BM_LexicallyRelative/large_path/64 -0.3629 -0.3605 10340 6587 10265 6564 BM_LexicallyRelative/large_path/128 -0.3450 -0.3423 19379 12694 19233 12649 BM_LexicallyRelative/large_path/256 -0.3097 -0.3054 36293 25052 35943 24965 ``` --------- Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-07-24[libc++][hardening] Add an experimental function to log hardening errors ↵Konstantin Varlamov2-0/+32
(#149452) Unlike `verbose_abort`, this function merely logs the error but does not terminate execution. It is intended to make it possible to implement the `observe` semantic for Hardening.
2025-07-18Remove last few bits for Native Client support (#148983)Brad Smith1-26/+0
2025-07-16[libc++] Annotate barrier functions that are defined in the dylib (#148542)Nikolas Klauser1-3/+4
This can improve code gen slightly.
2025-07-15Revert "[libc++][hardening] Introduce a dylib function to log hardening ↵Nikolas Klauser2-51/+0
errors." (#148787) Reverts llvm/llvm-project#148266 I'm reverting this temporarily, since the release branch is today and this is ABI sensitive. Let's wait until after the branch so that we have plenty time to discuss the patch.
2025-07-14[libc++][hardening] Introduce a dylib function to log hardening errors. ↵Konstantin Varlamov2-0/+51
(#148266) Unlike `verbose_abort`, this function merely logs the error but does not terminate execution. It is intended to make it possible to implement the `observe` semantic for Hardening.
2025-07-14Revert "[libc++][NFC] atomic::wait use public API on macOS" (#148705)Michael Buch1-6/+11
Reverts llvm/llvm-project#147146 This is failing to build on our public macOS CI: https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake-sanitized/ ``` 06:48:56 FAILED: libcxx/src/CMakeFiles/cxx_shared.dir/atomic.cpp.o 06:48:56 /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-sanitized/lldb-build/bin/clang++ --target=arm64-apple-darwin23.1.0 -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/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-sanitized/llvm-project/libcxx/src -I/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-sanitized/lldb-build/include/c++/v1 -I/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-sanitized/llvm-project/libcxxabi/include -I/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-sanitized/llvm-project/cmake/Modules/../../libc -fPIC -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 -fdiagnostics-color -O3 -DNDEBUG -std=c++23 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -mmacosx-version-min=14.1 -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-nullability-completeness -Wno-user-defined-literals -Wno-covered-switch-default -Wno-suggest-override -Wno-error -fdebug-prefix-map=/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-sanitized/lldb-build/include/c++/v1=/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-sanitized/llvm-project/libcxx/include -MD -MT libcxx/src/CMakeFiles/cxx_shared.dir/atomic.cpp.o -MF libcxx/src/CMakeFiles/cxx_shared.dir/atomic.cpp.o.d -o libcxx/src/CMakeFiles/cxx_shared.dir/atomic.cpp.o -c /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-sanitized/llvm-project/libcxx/src/atomic.cpp 06:48:56 /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-sanitized/llvm-project/libcxx/src/atomic.cpp:46:12: fatal error: 'os/os_sync_wait_on_address.h' file not found 06:48:56 46 | # include <os/os_sync_wait_on_address.h> 06:48:56 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 06:48:56 1 error generated. ``` This is the configuration the failing bots are running: ``` 06:25:12 + sw_vers 06:25:12 ProductName: macOS 06:25:12 ProductVersion: 14.1 06:25:12 BuildVersion: 23B74 06:25:12 + xcodebuild -version 06:25:12 Xcode 15.2 06:25:12 Build version 15C5500c ``` The Intel bots are building fine though. Probably because they're on a newer OS where the headers are available? ``` 10:03:35 + sw_vers 10:03:35 ProductName: macOS 10:03:35 ProductVersion: 15.1.1 10:03:35 BuildVersion: 24B91 10:03:35 + xcodebuild -version 10:03:39 Xcode 16.2 10:03:39 Build version 16C5031c 10:03:39 + cmake --version 10:03:39 cmake version 3.30.2 ```
2025-07-11[libc++][NFC] atomic::wait use public API on macOS (#147146)Hui1-11/+6
At the moment, we use the os internal functions `__ulock_wait`. This patch updates the code on macOS to use the public API `os_sync_wait_on_address`. Fixes #146142
2025-07-09[libc++] Optimize ctype::to{lower,upper} (#145344)Nikolas Klauser1-107/+22
``` ---------------------------------------------- Benchmark old new --------------------------- ------------------ BM_tolower_char<char> 1.64 ns 1.41 ns BM_tolower_char<wchar_t> 1.64 ns 1.41 ns BM_tolower_string<char> 32.4 ns 12.8 ns BM_tolower_string<wchar_t> 32.9 ns 15.1 ns BM_toupper_char<char> 1.63 ns 1.64 ns BM_toupper_char<wchar_t> 1.63 ns 1.41 ns BM_toupper_string<char> 32.2 ns 12.7 ns BM_toupper_string<wchar_t> 33.0 ns 15.1 ns ```
2025-07-09[libcxxabi][libunwind] Support for using LLVM libc (#134893)Petr Hosek1-2/+2
This generalizes the support added in #99287 renaming the option to RUNTIMES_USE_LIBC and integrating the module into libc++abi and libunwind as well.
2025-07-06[libc++] fix atomic::wait memory order (#146267)Hui1-2/+5
Fixes #109290 See the GH issue for the details. In conclusion, we have two issues in the `atomic<T>::wait` when `T` does not match our `contention_t`: - We don't have a total single order which can leads to missed notification based on the Herd7 simulation on relaxed architectural like PowerPC - We assumed the platform wait (`futex_wait`/`__ulock_wait`) has seq_cst barrier internally but there is no such guarantee
2025-06-17Revert "[libc++] Remove trailing newline from _LIBCPP_ASSERTION_HANDLER ↵Daniel Thornburgh1-3/+0
calls" (#144615) Reverts llvm/llvm-project#143573
2025-06-17[libc++] Remove trailing newline from _LIBCPP_ASSERTION_HANDLER calls (#143573)Sam Clegg1-0/+3
This newline was originally added in https://reviews.llvm.org/D142184 but I think updating `__libcpp_verbose_abort` to add newline instead is more consistent, and works for other callers of `_LIBCPP_VERBOSE_ABORT`. The `_LIBCPP_ASSERTION_HANDLER` calls through to either `_LIBCPP_VERBOSE_ABORT` macro or the `__builtin_verbose_trap`. From what I can tell neither of these function expect a trailing newline (at least none of the usage of `_LIBCPP_VERBOSE_ABORT` or `__builtin_verbose_trap` that I can find include a trailing newline except `_LIBCPP_ASSERTION_HANDLER`). I noticed this discrepancy when working on https://github.com/emscripten-core/emscripten/pull/24543
2025-06-11[libc++] Remove static_assert from hash.cpp that fires unconditionallNikolas Klauser1-1/+0
2025-06-11[libc++] Simplify the implementation of __next_prime a bit (#143512)Nikolas Klauser1-11/+9
2025-06-11[libc++] Upgrade to GCC 15 (#138293)Nikolas Klauser1-0/+9
2025-06-02[libc++] Remove availability annotations which can't fire anymore (#140049)Nikolas Klauser2-2/+2
According to https://developer.apple.com/support/xcode/ the removed annotations can't fire anymore, since the targets they would fire for aren't supported anymore.
2025-06-02[libc++] Remove unused include caused by wrong __has_include (#141328)Tomohiro Kashiwada1-4/+0
The parameter passed to __has_include has to be quoted by `<>` or `"`, not both.
2025-05-28Revert "[libc++] Introduce ABI sensitive areas to avoid requiring ↵James Y Knight47-97/+0
_LIBCPP_HIDE_FROM_ABI everywhere (#131156)" (#141756) This reverts commit c861fe8a71e64f3d2108c58147e7375cd9314521. Unfortunately, this use of hidden visibility attributes causes user-defined specializations of standard-library types to also be marked hidden by default, which is incorrect. See discussion thread on #131156. ...and also reverts the follow-up commits: Revert "[libc++] Add explicit ABI annotations to functions from the block runtime declared in <__functional/function.h> (#140592)" This reverts commit 3e4c9dc299c35155934688184319d391b298fff7. Revert "[libc++] Make ABI annotations explicit for windows-specific code (#140507)" This reverts commit f73287e623a6c2e4a3485832bc3e10860cd26eb5. Revert "[libc++][NFC] Replace a few "namespace std" with the correct macro (#140510)" This reverts commit 1d411f27c769a32cb22ce50b9dc4421e34fd40dd.
2025-05-28Revert "[libc++] Fix build failure with libdispatch backend (#141606)"Louis Dionne1-2/+0
It turns out that we're about to revert the patches that added these annotations in the first place. I was too hasty to land this. This reverts commit 56594710c7ffdaf82e07b1ff63f01226c117b2ce.
2025-05-28[libc++] Fix build failure with libdispatch backend (#141606)Louis Dionne1-0/+2
We get an error "cannot add 'abi_tag' attribute in a redeclaration" because functions like `__dispatch_apply` are first declared without an ABI tag due to `_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS` inside the header, and then redeclared with an ABI tag in the .cpp file.
2025-05-20[libc++] Make ABI annotations explicit for windows-specific code (#140507)Nikolas Klauser2-0/+4
This doesn't show up in the CI, since we don't have abilists for windows. I'm also not sure whether we want them, so I don't think we can easily test this change.
2025-05-18[libc++] Introduce ABI sensitive areas to avoid requiring ↵Nikolas Klauser45-0/+93
_LIBCPP_HIDE_FROM_ABI everywhere (#131156) This patch introduces `_LIBCPP_{BEGIN,END}_EXPLICIT_ABI_ANNOTATIONS`, which allow us to have implicit annotations for most functions, and just where it's not "hide_from_abi everything" we add explicit annotations. This allows us to drop the `_LIBCPP_HIDE_FROM_ABI` macro from most functions in libc++.
2025-05-16[libc++][NFC] Update the documentation for _LIBCPP_OVERRIDABLE_FUNCTION ↵Louis Dionne1-5/+5
(#140121)
2025-05-15[libc++] run clang-tidy on src/ in the CI (#121198)Nikolas Klauser1-1/+15
This adds a new test to run clang-tidy on the `src/` directory and temporarily disables and clang-tidy checks that currently fail. They will be enabled in follow-up patches.
2025-05-14[libcxx] Fix a comment link for the unicode NBSP char. NFC. (#139692)Martin Storsjö1-1/+1
2025-05-12[libc++] Fix missing #includes (#130536)Matt15-0/+24
Adds missing includes that were detected when I tried to build libc++ as a module. Working towards #127012
2025-05-09[libcxx][NFC] Use macros for functions that support overriding detection ↵Petr Hosek2-24/+20
(#133876) We plan to replace the existing mechanism for overriding detection with one that doesn't require the use of a special section as an alternative to llvm/llvm-project#120805 which had other downsides. This change is a pure refactoring that lays the foundation for a subsequent change that will introduce the new detection mechanism.
2025-04-25[libc++] Make bad_function_call::what() existence a matter of availability ↵Nikolas Klauser1-2/+0
instead of ABI (#127697) We're currently adding `bad_function_call::what()` behind an ABI flag, even though adding it is not an ABI break and can be handled through availability.
2025-04-25[libc++][NFC] Refactor string's extern template lists (#137264)Nikolas Klauser1-1/+1
This patch moves the functions common between our two extern template lists into a common list and avoids some unnecessary _Uglification. This makes the code a lot nicer to read and makes the differences between the two lists obvious.
2025-04-14[libc++] Removes the _LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT macro. (#135494)Mark de Wever1-1/+1
This makes __libcpp_verbose_abort unconditionally noexcept. This was planned for the upcomming release.
2025-04-11[libc++][NFC] Inline _LIBCPP_FALLTHROUGH() (#135001)Nikolas Klauser1-1/+1
We have `[[fallthrough]]` available in all standards modes, so we can just inline it like other stanard attributes we use.
2025-03-27[libc++] Instantiate hash function externally (#127040)Nikolas Klauser1-0/+4
This has multiple benefits: - There is a single instance of our hash function, reducing object file size - The hash implementation isn't instantiated in every TU anymore, reducing compile times - Behind an ABI configuration macro it would be possible to salt the hash
2025-02-21[libc++] Qualify calls to nullary functions like __throw_foo (#122465)Louis Dionne14-91/+91
This is technically not necessary in most cases to prevent issues with ADL, but let's be consistent. This allows us to remove the libcpp-qualify-declval clang-tidy check, which is now enforced by the robust-against-adl clang-tidy check.
2025-02-20[NFC][libc++][TZDB] Fixes formatting.Mark de Wever1-2/+3
This was broken by #127339
2025-02-18[libc++][TZDB] Improves system time zone detection. (#127339)Mark de Wever1-18/+49
On some (Linux) systems /etc/localtime is not a symlink to the time zone, but contains a copy of the binary time zone file. In these case there usually is a file named /etc/timezone which contains the text for the current time zone name. Instead of throwing when /etc/localtime does not exist or is not a symlink use this fallback. Fixes: #105634 --------- Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-02-15[libc++] Fix initialization-order-fiasco with iostream.cpp constructors ↵Vitaly Buka1-4/+10
(#126995) Asan reports it after #124103. It's know case of false positive for Asan. https://github.com/google/sanitizers/wiki/AddressSanitizerInitializationOrderFiasco#false-positives It's can be avoided with `constexpr` constructors. In general order global constructors in different modules is undefined. If global constructor uses external global, they can be not constructed yet. However, implementation may contain workaround for that, or the state of non-constructed global can be still valid. Asan will still falsely report such cases, as it has no machinery to detect correctness of such cases. We need to fix/workaround the issue in libc++, as it will affect many libc++ with Asan users.
2025-02-15[libc++] Move unused basic_string function definition to the dylib sources ↵Nikolas Klauser1-0/+38
(#126219) `__init(const value_type*, size_type, size_type)` is part of our ABI, but we don't actually use the function anymore in the dylib. THis moves the definition to the `src/` directory to make it clear that the code is unused. This also allows us to remove it entirely in the unstable ABI.
2025-02-04[libc++][TZDB] Fixes %z escaping. (#125399)Mark de Wever1-1/+1
The previous tested TZDB did not contain %z for the rule letters. The usage of %z in TZDB 2024b revealed a bug in the implementation. The patch fixes it and has been locally tested with TZDB 2024b. Fixes #108957
2025-01-30[libc++] Refactor num_get optimization to not be ABI breaking (#121690)Nikolas Klauser1-0/+10
``` ---------------------------------------------------- Benchmark old new ---------------------------------------------------- BM_num_get<bool> 81.8 ns 79.6 ns BM_num_get<long> 80.2 ns 75.4 ns BM_num_get<long long> 81.5 ns 76.4 ns BM_num_get<unsigned short> 82.5 ns 78.4 ns BM_num_get<unsigned int> 82.8 ns 78.6 ns BM_num_get<unsigned long> 81.2 ns 78.1 ns BM_num_get<unsigned long long> 83.6 ns 76.7 ns BM_num_get<float> 119 ns 120 ns BM_num_get<double> 113 ns 109 ns BM_num_get<long double> 115 ns 119 ns BM_num_get<void*> 147 ns 139 ns ```
2025-01-29[libc++] Simplify the implementation of iostream.cpp (#124103)Nikolas Klauser1-98/+63
This refactors the standard stream implementation in multiple ways: - The streams are now `stream_data` structs, which contain all the data required for a stream - The windows mangling is generated via a macro instead of having magic strings for the different streams. (i.e. it's now only partially magic)
2025-01-29[libc++] Remove some private symbols from the ABI (#121497)Nikolas Klauser1-2/+2
These symbols are never referenced directly outside the dylib, so we can make them hidden instead. They are still in the dylib since can be referenced through the `memory_resource*`, but dynamic linkers don't have to do any work to deduplicate them.
2025-01-28[libc++] Update the CI to Clang-20 and drop Clang-17 support (#117429)Nikolas Klauser1-3/+3
2025-01-28[libc++] Remove Android header no longer in use (#124691)Brad Smith1-4/+0
929f159777bec47c80a3b302f190261d426e1c3b removed the use of `__ANDROID_API__`
2025-01-27Revert "[libcxx] Use alias for detecting overriden function" (#124431)Petr Hosek2-55/+82
Reverts llvm/llvm-project#120805 This change while desirable has two issues we discovered: - It is incompatible with `-funique-internal-linkage-names`, see https://github.com/llvm/llvm-project/pull/120805#discussion_r1913709817 - It is incompatible with `-fvisibility-global-new-delete=force-hidden`, see https://github.com/llvm/llvm-project/issues/123224#issuecomment-2607963878 We were hoping to address both of these issues with https://github.com/llvm/llvm-project/pull/122983, but that change has other issues we haven't yet managed to resolve. For now, we have decided to revert the change to avoid shipping a broken feature in LLVM 20, and we plan to follow up with a new approach post branch.
2025-01-27[libc++] Add more missing bits to the locale base API (#122531)Louis Dionne3-24/+24
This patch adds the following pieces to the locale base API: - __setlocale (for std::setlocale) - __lconv_t (for std::lconv) - _LIBCPP_FOO_MASK and _LIBCPP_LC_ALL This should be sufficient to implement all of the platform-agnostic localization support in libc++ without relying directly on any public API names from the C library. This makes it possible to port libc++ to platforms that don't provide the usual locale APIs.