aboutsummaryrefslogtreecommitdiff
path: root/libcxx/src
AgeCommit message (Collapse)AuthorFilesLines
2024-08-14[libcxx] Disable invalid `__start/__stop` reference on NVPTX (#99381)Joseph Huber1-1/+2
Summary: The logic for this `__is_function_overridden` check requires accessing a runtime array normally created by the linker. The NVPTX target is an `__ELF__` target, however it does not support emitting the `__start/__stop` symbols for C-identifier named sections. This needs to be disabled explicitly so that the user can compile this with anything.
2024-08-14[libcxx] Set `_LIBCPP_HAS_CLOCK_GETTIME` for GPU targets (#99243)Joseph Huber2-3/+5
Summary: I am attempting to get the GPU to build and support libc++. One issue I've encountered is that it will look for `timeval` unless this macro is set. We can support `CLOCK_MONOTONIC` on the GPU fairly easily as we have access to a fixed-frequency clock via `__builtin_readsteadycounter` intrinsics with a known frequency. This also requires `CLOCK_REALTIME` which we can't support, but provide anyway from the GPU `libc` to make this happy. It will return an error so at least that will be obvious. I may need a more consistent configuration for this in the future, maybe I should put a common macro in a different common header that's just `__GPU__`? I don't know where I would put such a thing however.
2024-08-05[libc++] Check correctly ref-qualified __is_callable in algorithms (#101553)Louis Dionne1-2/+2
We were only checking that the comparator was rvalue callable, when in reality the algorithms always call comparators as lvalues. This patch also refactors the tests for callable requirements and expands it to a few missing algorithms. This is take 2 of #73451, which was reverted because it broke some CI bots. The issue was that we checked __is_callable with arguments in the wrong order inside std::upper_bound. This has now been fixed and a test was added. Fixes #69554
2024-08-01[libc++] Revert "Check correctly ref-qualified __is_callable in algorithms ↵Louis Dionne1-2/+2
(#73451)" This reverts commit 8d151f804ff43aaed1edf810bb2a07607b8bba14, which broke some build bots. I think that is caused by an invalid argument order when checking __is_comparable in upper_bound.
2024-08-01[libc++] Check correctly ref-qualified __is_callable in algorithms (#73451)Nhat Nguyen1-2/+2
We were only checking that the comparator was rvalue callable, when in reality the algorithms always call comparators as lvalues. This patch also refactors the tests for callable requirements and expands it to a few missing algorithms. Fixes #69554
2024-07-26[libc++] Remove unmaintained support for generating code coverage (#100630)Louis Dionne1-5/+0
This patch removes support for generating code coverage information of libc++, which is unmaintained and I've never been able to utilize. It would be great to have support for generating code coverage in the test suite, however this incarnation of it doesn't seem to be properly hooked up into the test suite. Since it gets in the way of making the test suite more standalone, remove it.
2024-07-25[libc++] Remove unmaintained LIBCXX_CONFIGURE_IDE (#100574)Louis Dionne1-14/+0
The premise of LIBCXX_CONFIGURE_IDE is nice, however in practice this setting has not been maintained and as a result it basically doesn't work properly. For example, it doesn't take into account the headers we generate, and its handling of the tests is too naive for it to be really helpful. This patch removes the setting in order to simplify the CMake setup a bit, but most importantly to remove unnecessary interactions between our main CMake build of the library and the test suite.
2024-07-23[libc++][libc++abi] Minor follow-up changes after ptrauth upstreaming (#87481)Louis Dionne1-3/+3
This patch applies the comments provided on #84573. This is done as a separate PR to avoid merge conflicts with downstreams that already had ptrauth support.
2024-07-18[libc][libcxx] Support for building libc++ against LLVM libc (#99287)Petr Hosek1-2/+2
Provide an option to build libc++ against LLVM libc and set the CMake compile and link options appropriately when the option is enabled.
2024-07-12[libc++][NFC] Remove outdated comment about overridable_function being in ↵Louis Dionne1-2/+0
libcxx/include
2024-07-07[libc++][TZDB] Makes implementation experimental. (#95657)Mark de Wever9-8/+8
This moves the files to libcxx/src/experimental/ as discussed in #90394. Fixes: https://github.com/llvm/llvm-project/issues/94902
2024-07-06[NFC][libc++] removes std:: qualification,Mark de Wever1-5/+5
Elements in nested namespaces in the std namespace do not use fully qualified names in libc++. This adjusts a few cases found.
2024-07-05[libc++] Use _Complex for multiplication and division of complex floating ↵Nikolas Klauser2-0/+111
point types (#83575) This significantly simplifies the implementation and improves the codegen. The only downside is that the accuracy can be marginally worse, but that is up to the compiler to decide with this change, which means it can be controlled by compiler flags. Differential Revision: https://reviews.llvm.org/D155312
2024-07-04[libc++][chrono] Fixes leap seconds. (#90070)Mark de Wever1-24/+40
While implementing the UTC clock it turns out that the implementation of the leap seconds was not correct, it should store the individual value, not the sum. It also looks like LWG3359 has not been fully implemented. Implements parts of: - LWG3359 <chrono> leap second support should allow for negative leap seconds
2024-06-28[libc++] Fix how we pass /MANIFEST flag on Windows without clang-cl (#96967)Louis Dionne1-2/+7
If we're compiling with Clang (not clang-cl) on Windows, we need to use -Xlinker to pass the /MANIFEST option. Fixes #96430
2024-06-25[libc++] Get the GCC build mostly clean of warnings (#96604)Nikolas Klauser5-41/+41
The GCC build has gotten to the point where it's often hard to find the actual error in the build log. We should look into enabling these warnings again in the future, but it looks like a lot of them are bogous.
2024-06-12[libcxx] Correct and clean-up filesystem operations error_code paths (#88341)Rodrigo Salazar1-13/+15
3 error_code related cleanups/corrections in the std::filesystem operations functions. 1. In `__copy`, the `ec->clear()` is unnecessary as `ErrorHandler` at the start of each function clears the error_code as part of its initialization. 2. In `__copy`, in the recursive codepath we are not checking the error_code result of `it.increment(m_ec2)` immediately after use in the for loop condition (and we aren't checking it after the final increment when we don't enter the loop). 3. In `__weakly_canonical`, it makes calls to `__canonical` (which internally uses OS APIs implementing POSIX `realpath`) and we are not checking the error code result from the `__canonical` call. Both `weakly_canonical` and `canonical` are supposed to set the error_code when underlying OS APIs result in an error (https://eel.is/c++draft/fs.err.report#3.1). With this change we propagate up the error_code from `__canonical` caused by any underlying OS API failure up to the `__weakly_canonical`. Essentially, if `__canonical` thinks an error code should be set, then `__weakly_canonical` must as well. Before this change it would be throwing an exception in the non-error_code form of the function when `__canonical` fails, while not setting the error code in the error_code form of the function (an inconsistency). Added a little coverage in weakly_canonical.pass.cpp for the error_code forms of the API that was missing. Though I am lacking utilities in libcxx testing to add granular testing of the failure scenarios (like forcing realpath to fail for a given path, as it could if you had something like a flaky remote filesystem).
2024-06-11[libc++] Mark a few functions in the dylib as noexcept (#94098)Nikolas Klauser2-10/+11
This avoids generating landing pads in some of the `atomic` functions that will never be used, since these functions never throw exceptions.
2024-06-11[libc++] Fix UB in filesystem::__copy for non-existent destination. (#87615)Afanasyev Ivan1-3/+3
The lstat/stat/fstat functions have no guarantee whether the `struct stat` buffer is changed or not on failure. The filesystem::__copy function assumes that the `struct stat` buffer is not updated on failure, which is not necessarily correct. It appears that for a non-existing destination `detail::posix_lstat(to, t_st, &m_ec1)` returns a failure indicator and overwrites the `struct stat` buffer with a garbage value, which is accidentally equal to the `f_st` from stack internals from the previous `detail::posix_lstat(from, f_st, &m_ec1)` call. file_type::not_found is a known status, so checking against `if (not status_known(t))` passes spuriously and execution continues. Then the __copy function returns errc::function_not_supported because stats are accidentally equivalent, which is incorrect. Before checking for `detail::stat_equivalent`, we instead need to make sure that the call to lstat/stat/fstat was successful. As a result of `f_st` and `t_st` not being accessed anymore without checking for the lstat/stat/fstat success indicator, it is not needed to zero-initialize them.
2024-06-10[libc++][TZDB] Implements time_zone::to_sys. (#90394)Mark de Wever2-0/+25
This implements the throwing overload and the exception classes throw by this overload. Implements parts of: - P0355 Extending chrono to Calendars and Time Zones
2024-06-09[libc++][TZDB] Implements time_zone get_info(local_time). (#89537)Mark de Wever1-0/+147
Implements parts of: - P0355 Extending chrono to Calendars and Time Zones
2024-06-01[libc++] Fix `std::atomic::wait` ulock wait UL_COMPARE_AND_WAIT64 (#92783)Hui1-3/+6
in `atomic::wait`, when we call the platform wait ulock_wait , we are using UL_COMPARE_AND_WAIT. But we should use UL_COMPARE_AND_WAIT64 instead as the address we are waiting for is a 64 bit integer. fixes https://github.com/llvm/llvm-project/issues/85107 It is rather hard to test directly because in `atomic::wait`, before calling into the platform wait, our c++ code has some poll logic which checks the value not changing. Thus in this patch, the test is using the internal function.
2024-05-28[runtimes][CMake] Simplify the propagation of test dependencies (#93558)Louis Dionne1-0/+2
Instead of using FOO_TEST_DEPS global variables that don't get updated properly from subdirectories, use targets to propagate the dependencies across directories.
2024-05-28[libc++] Make the __availability header a sub-header of __config (#93083)Louis Dionne2-2/+0
In essence, this header has always been related to configuration of the library but we didn't want to put it inside <__config> due to complexity reasons. Now that we have sub-headers in <__config>, we can move <__availability> to it and stop including it everywhere since we already obtain the required macros via <__config>.
2024-05-20[libcxx] Add cast to avoid pointer casting warning on Windows (#92738)Martin Storsjö1-2/+2
This avoids the following build time warning, when building with the latest nightly Clang: warning: cast from 'FARPROC' (aka 'int (*)() __attribute__((stdcall))') to 'GetSystemTimeAsFileTimePtr' (aka 'void (*)(_FILETIME *) __attribute__((stdcall))') converts to incompatible function type [-Wcast-function-type-mismatch] This warning seems to have appeared since Clang commit 999d4f840777bf8de26d45947192aa0728edc0fb, which restructured. The GetProcAddress function returns a `FARPROC` type, which is `int (WINAPI *)()`. Directly casting this to another function pointer type triggers this warning, but casting to a `void*` inbetween avoids this issue. (On Unix-like platforms, dlsym returns a `void*`, which doesn't exhibit this casting problem.)
2024-05-20[libcxx] locale.cpp: Move build_name helper into unnamed namespace (#92461)Hubert Tong1-2/+2
Fix linkage of `build_name`; it is not supposed to have external linkage.
2024-05-17[libcxx][libcxxabi] Fix build for OpenBSD (#92186)John Ericson2-3/+17
- No indirect syscalls on OpenBSD. Instead there is a `futex` function which issues a direct syscall. - Monotonic clock is available despite the full POSIX suite of timers not being available in its entirety. See https://lists.boost.org/boost-bugs/2015/07/41690.php and https://github.com/boostorg/log/commit/c98b1f459add14d5ce3e9e63e2469064601d7f71 for a description of an analogous problem and fix for Boost.
2024-04-23[libc++][TZDB] Fixes reverse time lookups. (#89502)Mark de Wever1-4/+15
Testing with the get_info() returning a local_info revealed some issues in the reverse lookup. This needed an additional quirk. Also the skipping when not in the current continuation optimization was wrong. It prevented merging two sys_info objects.
2024-04-22[libc++] Remove _LIBCPP_DISABLE_NODISCARD_EXTENSIONS and refactor the tests ↵Nikolas Klauser1-2/+2
(#87094) This also adds a few tests that were missing.
2024-04-17[libc++][pstl] Promote CPU backends to top-level backends (#88968)Louis Dionne2-2/+2
This patch removes the two-level backend dispatching mechanism we had in the PSTL. Instead of selecting both a PSTL backend and a PSTL CPU backend, we now only select a top-level PSTL backend. This greatly simplifies the PSTL configuration layer. While this patch technically removes some flexibility from the PSTL configuration mechanism because CPU backends are not considered separately, it opens the door to a much more powerful configuration mechanism based on chained backends in a follow-up patch. This is a step towards overhauling the PSTL dispatching mechanism.
2024-04-16[libc++] Use availability to rely on key functions for bad_expected_access ↵Louis Dionne3-2/+14
and bad_function_call (#87390) This patch uses our availability machinery to allow defining a key function for bad_function_call and bad_expected_access at all times but only rely on it when we can. This prevents compilers from complaining about weak vtables and reduces code bloat and the amount of work done by the dynamic linker. rdar://111917845
2024-04-15[libc++][PSTL] Introduce cpu traits (#88134)Louis Dionne1-5/+2
Currently, CPU backends in the PSTL are created by defining functions in the __par_backend namespace. Then, the PSTL includes the CPU backend that gets configured via CMake and gets those definitions. This prevents CPU backends from easily co-existing and is a bit confusing. To solve this problem, this patch introduces the notion of __cpu_traits, which is a cheap encapsulation of the basis operations required to implement a CPU-based PSTL. Different backends can now define their own tag and coexist, and the CPU-based PSTL will simply use __cpu_traits to dispatch to the right implementation of e.g. __for_each. Note that this patch doesn't change the actual implementation of the backends in any way, it only modifies how that implementation is accessed to implement PSTL algorithms. This patch is a step towards #88131.
2024-04-13[tzdb] Replace shared_mutex with mutex. (#87929)Eric1-4/+7
The overhead of taking a std::mutex is much lower than taking a reader lock on a shared mutex, even under heavy contention. The benefit of shared_mutex only occurs as the amount of time spent in the critical sections grows large enough. In our case all we do is read a pointer and return the lock. As a result, using a shared lock can be ~50%-100% slower Here are the results for the provided benchmark on my machine: ``` 2024-04-07T12:48:51-04:00 Running ./libcxx/benchmarks/shared_mutex_vs_mutex.libcxx.out Run on (12 X 400 MHz CPU s) CPU Caches: L1 Data 32 KiB (x6) L1 Instruction 32 KiB (x6) L2 Unified 1024 KiB (x6) L3 Unified 32768 KiB (x1) Load Average: 2.70, 2.70, 1.63 --------------------------------------------------------------------- Benchmark Time CPU Iterations --------------------------------------------------------------------- BM_shared_mutex/threads:1 13.9 ns 13.9 ns 50533700 BM_shared_mutex/threads:2 34.5 ns 68.9 ns 9957784 BM_shared_mutex/threads:4 38.4 ns 137 ns 4987772 BM_shared_mutex/threads:8 51.1 ns 358 ns 1974160 BM_shared_mutex/threads:32 57.1 ns 682 ns 1043648 BM_mutex/threads:1 5.54 ns 5.53 ns 125867422 BM_mutex/threads:2 15.5 ns 30.9 ns 21830116 BM_mutex/threads:4 15.4 ns 57.2 ns 12136920 BM_mutex/threads:8 19.3 ns 140 ns 4997080 BM_mutex/threads:32 20.8 ns 252 ns 2859808 ```
2024-04-10[libc++] Adds a global private constructor tag. (#87920)Mark de Wever5-61/+3
This removes the similar tags used in the chrono tzdb implementation. Fixes: https://github.com/llvm/llvm-project/issues/85432
2024-04-10[libc++][chrono] Adds the sys_info class. (#85619)Mark de Wever4-4/+889
Adds the sys_info class and time_zone::get_info(). The code still has a few quirks and has not been optimized for performance yet. The returned sys_info is compared against the output of the zdump tool in the test giving confidence the implementation is correct. Implements parts of: - P0355 Extending <chrono> to Calendars and Time Zones Implements: - LWGXXXX The sys_info range should be affected by save
2024-04-09[libc++] Avoids using ENODATA. (#86165)Mark de Wever1-3/+1
This macro is deprecated in C++26. Fixes https://github.com/llvm/llvm-project/issues/81360 --------- Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-04-09[libc++][TZDB] Fixes relative path resolving. (#87882)Mark de Wever1-1/+5
The path /etc/localtime is a symlink. This symlink can be a relative path. This fixes resolving a relative symlink. Since the path used is hard-coded based on the user's system there is no good way to test this. Fixes: https://github.com/llvm/llvm-project/issues/87872
2024-04-04[libc++][chrono] Completes the tzdb class. (#82157)Mark de Wever1-0/+59
It adds the missing member functions of the tzdb class and adds the free functions that use these member functions. Implements parts of: - P0355 Extending <chrono> to Calendars and Time Zones
2024-04-03[libc++][chrono] Loads leap-seconds.list in tzdb. (#82113)Mark de Wever3-0/+70
This implements the loading of the leap-seconds.list file and store its contents in the tzdb struct. This adds the required `leap_seconds` member. The class leap_seconds is fully implemented including its non-member functions. Implements parts of: - P0355 Extending <chrono> to Calendars and Time Zones - P1614 The Mothership has Landed Implements: - P1981 Rename leap to leap_second - LWG3359 <chrono> leap second support should allow for negative leap seconds - LWG3383 §[time.zone.leap.nonmembers] sys_seconds should be replaced with seconds
2024-04-03[libc++] Upstream ptrauth support in libc++ and libc++abi (#84573)Louis Dionne1-0/+12
This is an exact upstreaming of the downstream diff. Minor simplifications can be made in the future but upstreaming as-is will make it easier for us to deal with downstream merge conflicts. Partially fixes #83805
2024-03-27[NFC][libc++][TZDB] Improves some internals. (#84800)Mark de Wever2-20/+15
Removes some unneeded overloads in the pimpl class; they implementation could be in the caller. The pimpl member functions are __uglified.
2024-03-21[libc++] Deprecates std::errc constants. (#80542)Mark de Wever1-1/+3
Implements: - LWG3869 Deprecate std::errc constants related to UNIX STREAMS
2024-03-13[runtimes] Prefer -fvisibility-global-new-delete=force-hidden (#84917)Martin Storsjö1-1/+4
27ce26b06655cfece3d54b30e442ef93d3e78ac7 added the new option -fvisibility-global-new-delete=, where -fvisibility-global-new-delete=force-hidden is equivalent to the old option -fvisibility-global-new-delete-hidden. At the same time, the old option was deprecated. Test for and use the new option form first; if unsupported, try using the old form. This avoids warnings in the MinGW builds, if built with Clang 18 or newer.
2024-03-12[libc++] Improves UB handling in ios_base destructor. (#76525)Mark de Wever1-0/+4
Destroying an ios_base object before it is properly initialized is undefined behavior. Unlike typical C++ classes the initialization is not done in the constructor, but in a dedicated init function. Due to virtual inheritance of the basic_ios object in ostream and friends this undefined behaviour can be triggered when inheriting from classes that can throw in their constructor and inheriting from ostream. Use the __loc_ member of ios_base as sentinel to detect whether the object has or has not been initialized. Addresses https://github.com/llvm/llvm-project/issues/57964
2024-03-12[libc++][TZDB] Fixes parsing interleaved rules. (#84808)Mark de Wever1-4/+23
Typically the rules in the database are contiguous, but that is not a requirement. This fixes the case when they are not. --------- Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-03-03[libc++][NFC] Replace _ALIGNAS_TYPE with alignas in iostream.cppNikolas Klauser1-22/+14
2024-02-29[libc++] Include missing <__assert> after #80091 (#83480)Fangrui Song1-0/+1
_LIBCPP_ASSERT_SHIM used by the -fno-exceptions and LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=on configuration needs _LIBCPP_ASSERT from <__assert>.
2024-02-26[libc++] Always keep libc++abi re-exports up-to-date (#79012)Louis Dionne1-7/+2
Previously, the list of libc++abi symbols that we re-export from libc++ would be partly encoded in libc++abi (and re-exported automatically via the cxxabi-reexports target), and partly hard-coded in libcxx/lib/libc++abi.exp. The duplication of information led to symbols not being exported from libc++ after being added to libc++abi when they should have been. This patch removes the duplication of information. After this patch, the full list of symbols to re-export from libc++abi is handled by the cxxabi-reexports target and is stored in libcxxabi. The symbols newly re-exported from libc++ are mainly new fundamental typeinfos and a bunch of functions and classes that are part of libc++abi but are most likely implementation details. In the future, it would be possible to try to trim down the set of what we export from libc++abi (and hence what we re-export from libc++) to remove some implementation detail symbols. Fixes #79008
2024-02-19[libc++] Refactor the predicate taking variant of `__cxx_atomic_wait` (#80596)Jan Kokemüller1-0/+1
This is a follow-up PR to <https://github.com/llvm/llvm-project/pull/79265>. It aims to be a gentle refactoring of the `__cxx_atomic_wait` function that takes a predicate. The key idea here is that this function's signature is changed to look like this (`std::function` used just for clarity): ```c++ __cxx_atomic_wait_fn(Atp*, std::function<bool(Tp &)> poll, memory_order __order); ``` ...where `Tp` is the corresponding `value_type` to the atomic variable type `Atp`. The function's semantics are similar to `atomic`s `.wait()`, but instead of having a hardcoded predicate (is the loaded value unequal to `old`?) the predicate is specified explicitly. The `poll` function may change its argument, and it is very important that if it returns `false`, it leaves its current understanding of the atomic's value in the argument. Internally, `__cxx_atomic_wait_fn` dispatches to two waiting mechanisms, depending on the type of the atomic variable: 1. If the atomic variable can be waited on directly (for example, Linux's futex mechanism only supports waiting on 32 bit long variables), the value of the atomic variable (which `poll` made its decision on) is then given to the underlying system wait function (e.g. futex). 2. If the atomic variable can not be waited on directly, there is a global pool of atomics that are used for this task. The ["eventcount" pattern](<https://gist.github.com/mratsim/04a29bdd98d6295acda4d0677c4d0041>) is employed to make this possible. The eventcount pattern needs a "monitor" variable which is read before the condition is checked another time. libcxx has the `__libcpp_atomic_monitor` function for this. However, this function only has to be called in case "2", i.e. when the eventcount is actually used. In case "1", the futex is used directly, so the monitor must be the value of the atomic variable that the `poll` function made its decision on to continue blocking. Previously, `__libcpp_atomic_monitor` was _also_ used in case "1". This was the source of the ABA style bug that PR#79265 fixed. However, the solution in PR#79265 has some disadvantages: - It exposes internals such as `cxx_contention_t` or the fact that `__libcpp_thread_poll_with_backoff` needs two functions to higher level constructs such as `semaphore`. - It doesn't prevent consumers calling `__cxx_atomic_wait` in an error prone way, i.e. by providing to it a predicate that doesn't take an argument. This makes ABA style issues more likely to appear. Now, `__cxx_atomic_wait_fn` takes just _one_ function, which is then transformed into the `poll` and `backoff` callables needed by `__libcpp_thread_poll_with_backoff`. Aside from the `__cxx_atomic_wait` changes, the only other change is the weakening of the initial atomic load of `semaphore`'s `try_acquire` into `memory_order_relaxed` and the CAS inside the loop is changed from `strong` to `weak`. Both weakenings should be fine, since the CAS is called in a loop, and the "acquire" semantics of `try_acquire` come from the CAS, not from the initial load.
2024-02-17[libc++][chrono] Loads tzdata.zi in tzdb. (#74928)Mark de Wever10-216/+994
This implements the loading of the tzdata.zi file and store its contents in the tzdb struct. This adds all required members except: - the leap seconds, - the locate_zone, and - current_zone. The class time_zone is incomplete and only contains the parts needed for storing the parsed data. The class time_zone_link is fully implemented including its non-member functions. Implements parts of: - P0355 Extending <chrono> to Calendars and Time Zones - P1614 The Mothership has Landed Implements: - P1982 Rename link to time_zone_link