Commit Graph

9054 Commits

Author SHA1 Message Date
Nikolas Klauser
80045e9afa [libc++] Implement ranges::for_each{, _n}
Reviewed By: var-const, #libc

Spies: libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D124332
2022-05-04 20:28:01 +02:00
Louis Dionne
0e2fb8ac84 [libc++] Refactor max_size.pass.cpp
Reorganize the test and simplify the #ifdefs. Fix a typo in __powerpc64__
as a fly-by, and also add a test for the unstable ABI.

Differential Revision: https://reviews.llvm.org/D124403
2022-05-04 11:05:29 -07:00
Nikolas Klauser
639b9618f4 [libc++][NFC] Replace _LIBCPP_INLINE_VISIBILTIY and _VSTD in <string>
Replace all the instances of `_LIBCPP_INLINE_VISIBILITY` with `_LIBCPP_HIDE_FROM_ABI` and `_VSTD` with `std`.

Reviewed By: Mordante, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D124662
2022-05-01 12:59:52 +02:00
Mark de Wever
d563df88e9 Revert "[msan][libcxx] Enable -fsanitize-memory-param-retval"
This reverts commit beff64ee44.

The original commit was reviewed as D123979.

This commit caused the libc++ pre-commit CI to fail
https://buildkite.com/llvm-project/libcxx-ci/builds/10483

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D124713
2022-04-30 15:19:16 +02:00
Vitaly Buka
beff64ee44 [msan][libcxx] Enable -fsanitize-memory-param-retval
We are considering to make -fsanitize-memory-param-retval enabled by default so probably this patch is unnneded.

Reviewed By: #libc, EricWF

Differential Revision: https://reviews.llvm.org/D123979
2022-04-28 19:12:41 -07:00
Mark de Wever
d03bc249d8 [NFC][libc++][format] Enable unit tests.
The GCC failures were partly fixed in D124103.

The format functions tests are fixed on GCC but they require a huge
amount of RAM (>10 GB). This fails with parallel testing in the CI. It
can be solved by splitting the test, but GCC-12 will be released shortly
and might fix the memory usage in these tests. Therefore these tests
remain disabled.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D124335
2022-04-28 17:11:47 +02:00
Nikolas Klauser
425620ccdd [libc++] Implement P0980R1 (constexpr std::string)
Reviewed By: #libc, ldionne

Spies: daltenty, sdasgup3, ldionne, arichardson, MTC, ChuanqiXu, mehdi_amini, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, Kayjukh, jurahul, msifontes, tatianashp, rdzhabarov, teijeong, cota, dcaballe, Chia-hungDuan, wrengr, wenzhicui, arphaman, Mordante, miscco, Quuxplusone, smeenai, libcxx-commits

Differential Revision: https://reviews.llvm.org/D110598
2022-04-27 12:25:34 +02:00
Mark de Wever
0289c90d70 [NFC][libc++] Fixes some tests on Linux.
The tests are adapted to the output produced on Linux.

Reviewed By: #libc, philnik, ldionne

Differential Revision: https://reviews.llvm.org/D124331
2022-04-26 17:50:17 +02:00
Nikolas Klauser
a83f4b9cda [libc++] Remove <functional> includes
Reviewed By: var-const, #libc, ldionne

Spies: #libc_vendors, ldionne, libcxx-commits, miyuki

Differential Revision: https://reviews.llvm.org/D124123
2022-04-26 08:54:37 +02:00
Vitaly Buka
0c99575df4 [libc++] Avoid lifetime UB in __thread_local_data()
Detected on many lld tests with -fsanitize-memory-use-after-dtor.
Also https://lab.llvm.org/buildbot/#/builders/sanitizer-x86_64-linux-fast after D122869 will report a lot of them.

Threads may outlive static variables. Even if ~__thread_specific_ptr() does nothing, lifetime of members ends with ~ and accessing the value is UB https://eel.is/c++draft/basic.life#1

```
==9214==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x557e1cec4539 in __libcpp_tls_set ../include/c++/v1/__threading_support:428:12
    #1 0x557e1cec4539 in set_pointer ../include/c++/v1/thread:196:5
    #2 0x557e1cec4539 in void* std::__msan::__thread_proxy<
      std::__msan::tuple<...>, llvm::parallel::detail::(anonymous namespace)::ThreadPoolExecutor::ThreadPoolExecutor(llvm::ThreadPoolStrategy)::'lambda'()::operator()() const::'lambda'()> >(void*) ../include/c++/v1/thread:285:27

  Memory was marked as uninitialized
    #0 0x557e10a0759d in __sanitizer_dtor_callback compiler-rt/lib/msan/msan_interceptors.cpp:940:5
    #1 0x557e1d8c478d in std::__msan::__thread_specific_ptr<std::__msan::__thread_struct>::~__thread_specific_ptr() libcxx/include/thread:188:1
    #2 0x557e10a07dc0 in MSanCxaAtExitWrapper(void*) compiler-rt/lib/msan/msan_interceptors.cpp:1151:3
```

The test needs D123979 or  -fsanitize-memory-param-retval enabled by default.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D122864
2022-04-25 14:56:44 -07:00
Quinn Pham
09e75d3f09 [libcxx][NFC] Inclusive language: remove use of sanity check
from libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/

[NFC] As part of using inclusive language within the llvm project, this
patch rewords comments to remove sanity check.

Reviewed By: #libc, philnik

Differential Revision: https://reviews.llvm.org/D124391
2022-04-25 16:53:51 -05:00
Vitaly Buka
bf0d613690 [libcxx] Disable long double -> int128 test with msan
On x86 long double is 80 bit with padding, which produces
uninitialized bits in the result.
This will trigger errors with -fsanitize-memory-param-retval.

Can be triggered with D123979.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D123980
2022-04-25 10:42:10 -07:00
Louis Dionne
4051cac256 [libc++][NFC] Use brace-init instead of parens to workaround macro expansion in badly behaved systems 2022-04-25 11:17:11 -06:00
Nikolas Klauser
6b257af822 [libc++] Fix C++03 with the unstable ABI enabled 2022-04-25 15:17:24 +02:00
Hui Xie
042dc3c46d [libc++] add zip_view and views::zip for C++23
- add zip_view and views::zip for C++23
- added unit tests
- implemented section 5.6 (zip) in P2321R2

I used clang-format to format the files but they look nothing like the rest of the code base. Manually indenting each line to match the styles sounds like an impossible task. Is there any clang-format file which can format it reasonable similar to the rest of the code base so that I can manually format the rest lines that look weird?

Reviewed By: ldionne, #libc, philnik, var-const

Spies: Mordante, philnik, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D122806
2022-04-25 12:22:22 +02:00
Brad Smith
d13f502389 [libcxx] random_device, use arc4random() on FreeBSD, NetBSD and DragonFlyBSD
Reviewed By: ldionne, emaste, dim

Differential Revision: https://reviews.llvm.org/D122628
2022-04-24 21:45:49 -04:00
Petr Hosek
b3df14b6c9 [runtimes] [CMake] Unify variable names
Avoid repeating CMake checks across runtimes by unifying names of
variables used for results to leverage CMake caching.

Differential Revision: https://reviews.llvm.org/D110005
2022-04-24 13:06:36 +03:00
Mark de Wever
7a98d8351b [libc++] Fixes concepts overload resolution.
D123182 fixes a bug in Clang's overload resolution. After it landed it
was discovered `basic_format_arg`'s constructors contains this bug. This
fixes the bug in libc++, unblocking D123182.

The code has been tested in combination with D123182.

Reviewed By: royjacobson, #libc

Differential Revision: https://reviews.llvm.org/D124103
2022-04-23 18:19:11 +02:00
Nikolas Klauser
907ed12d95 [libc++] Change vector<bool>::const_iterator::reference to bool in ABIv2
`vector<bool>::const_reference` and `vector<bool>::const_iterator::reference` should be the same type.

Reviewed By: Mordante, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D123851
2022-04-22 20:57:30 +02:00
Brad Smith
a0d40a579a [libcxx] Add some missing xlocale wrapper functions for OpenBSD
Reviewed By: Mordante

Differential Revision: https://reviews.llvm.org/D122861
2022-04-21 20:00:59 -04:00
zhijian
bf4ddf1840 [libc++][CI] added XFAIL LIBCXX-AIX-FIXME to new runnning test cases after install locale fileset on AIX OS.
Summary:

1. there are 23 test cases which do not run because of locale fileset not install, after the locale installed, these test cases will be run and fail. "LIBCXX-AIX-FIXME" on the 23 test cases which remain to be investigated on AIX.

2.after installed the locale fileset ,
the test case
libcxx/test/std/localization/locale.categories/category.collate/locale.collate.byname/compare.pass.cpp pass
remove XFAIL: LIBCXX-AIX-FIXME from the file

Reviewers: David Tenty
Differential Revision: https://reviews.llvm.org/D124174
2022-04-21 15:25:40 -04:00
Nikolas Klauser
29c8c070a1 [libc++] Use bit field for checking if string is in long or short mode
This makes the code a bit simpler and (I think) removes the undefined behaviour from the normal string layout.

Reviewed By: ldionne, Mordante, #libc

Spies: labath, dblaikie, JDevlieghere, krytarowski, jgorbe, jingham, saugustine, arichardson, libcxx-commits

Differential Revision: https://reviews.llvm.org/D123580
2022-04-21 14:20:21 +02:00
Hui Xie
3d3103b733 [libcxx][ranges] add views::join adaptor object. added test coverage to join_view
- added views::join adaptor object
- added test for the adaptor object
- fixed some join_view's tests. e.g iter_swap test
- added some negative tests for join_view to test that operations do not exist when constraints aren't met
- added tests that locks down issues that were already addressed in previous change
  - LWG3500 `join_view::iterator::operator->()` is bogus
  - LWG3313 `join_view::iterator::operator--` is incorrectly constrained
  - LWG3517 `join_view::iterator`'s `iter_swap` is underconstrained
  - P2328R1 join_view should join all views of ranges
- fixed some issues in join_view and added tests
  - LWG3535 `join_view::iterator::iterator_category` and `::iterator_concept` lie
  - LWG3474 Nesting ``join_views`` is broken because of CTAD
- added tests for an LWG issue that isn't resolved in the standard yet, but the previous code has workaround.
  - LWG3569 Inner iterator not default_initializable

Reviewed By: #libc, var-const

Spies: var-const, libcxx-commits

Differential Revision: https://reviews.llvm.org/D123466
2022-04-21 13:10:46 +02:00
Richard Smith
72315d02c4 Treat std::move, forward, etc. as builtins.
This is extended to all `std::` functions that take a reference to a
value and return a reference (or pointer) to that same value: `move`,
`forward`, `move_if_noexcept`, `as_const`, `addressof`, and the
libstdc++-specific function `__addressof`.

We still require these functions to be declared before they can be used,
but don't instantiate their definitions unless their addresses are
taken. Instead, code generation, constant evaluation, and static
analysis are given direct knowledge of their effect.

This change aims to reduce various costs associated with these functions
-- per-instantiation memory costs, compile time and memory costs due to
creating out-of-line copies and inlining them, code size at -O0, and so
on -- so that they are not substantially more expensive than a cast.
Most of these improvements are very small, but I measured a 3% decrease
in -O0 object file size for a simple C++ source file using the standard
library after this change.

We now automatically infer the `const` and `nothrow` attributes on these
now-builtin functions, in particular meaning that we get a warning for
an unused call to one of these functions.

In C++20 onwards, we disallow taking the addresses of these functions,
per the C++20 "addressable function" rule. In earlier language modes, a
compatibility warning is produced but the address can still be taken.

The same infrastructure is extended to the existing MSVC builtin
`__GetExceptionInfo`, which is now only recognized in namespace `std`
like it always should have been.

This is a re-commit of
  fc30901096,
  a571f82a50,
  64c045e25b, and
  de6ddaeef3,
and reverts aa643f455a.
This change also includes a workaround for users using libc++ 3.1 and
earlier (!!), as apparently happens on AIX, where std::move sometimes
returns by value.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D123345

Revert "Fixup D123950 to address revert of D123345"

This reverts commit aa643f455a.
2022-04-20 17:58:31 -07:00
David Tenty
de6ddaeef3 Revert "Don't treat 'T &forward(T&&)' as builtin."
This reverts commit e43c93dd63 as the
parent https://reviews.llvm.org/D123345 breaks the AIX CI.
2022-04-20 19:14:36 -04:00
Nikolas Klauser
faef447e72 [libc++] Granularize <functional> includes
Reviewed By: Mordante, #libc

Spies: libcxx-commits, miyuki

Differential Revision: https://reviews.llvm.org/D123912
2022-04-20 22:49:18 +02:00
Konstantin Varlamov
bcdb11e741 [libc++][NFC] Reindent take_view in accordance with the style guide. 2022-04-18 20:54:50 -07:00
Richard Smith
e43c93dd63 Don't treat 'T &forward(T&&)' as builtin.
This allows the standard library to diagnose it properly. Suppress
warning in libc++ testsuite for unused result of call to std::forward.
2022-04-18 11:11:21 -07:00
Richard Smith
c105bcbf98 Specify -fno-builtin when testing to make sure that certain stdlib
functions are not treated as [[nodiscard]].

The compiler might choose to treat them as [[nodiscard]] without the
involvement of libc++ if we allow it to recognize them as builtins.
2022-04-17 19:41:34 -07:00
Jonathan Wakely
ef94609d6e [libcxx] [test] Use LIBCPP_ASSERT for libc++-specific checks
This makes it a little easier to reuse the libc++ tests for another
std::lib (specifically libstdc++).

The regex_error::what() strings are different in other
implementations, so should be tested with LIBCPP_ASSERT so that those
checks are skipped for other implementations.

The value of ECMAScript constant is non-zero in other implementations,
and conditionally for libc++, so adjust the preprocessor condition for
that too.

Reviewed By: ldionne, #libc, philnik, Mordante

Spies: Mordante, philnik, libcxx-commits

Differential Revision: https://reviews.llvm.org/D122574
2022-04-17 01:23:24 +02:00
Nikolas Klauser
1d83750f63 [libc++] Implement ranges::copy{, _n, _if, _backward}
Reviewed By: Mordante, var-const, #libc

Spies: sstefan1, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D122982
2022-04-15 13:44:11 +02:00
Louis Dionne
c4f059e509 [libc++][NFC] Add missing 'return 0' to test 2022-04-14 16:08:43 -04:00
Mark de Wever
48fbcedb38 [libc++] Adds a missing include.
This fixes the modular build.
2022-04-14 19:28:00 +02:00
Fabian Wolff
4ff70dba38 [libc++] Fix undefined behavior in std::filebuf
Fixes https://github.com/llvm/llvm-project/issues/49267.
Fixes https://github.com/llvm/llvm-project/issues/49282.
Fixes https://github.com/llvm/llvm-project/issues/49789.

Reviewed By: ldionne

Differential Revision: https://reviews.llvm.org/D122257
2022-04-14 16:20:51 +02:00
Nikolas Klauser
58d9ab70ae [libc++][ranges] Implement ranges::minmax and ranges::minmax_element
Reviewed By: var-const, #libc, ldionne

Spies: sstefan1, ldionne, BRevzin, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D120637
2022-04-14 15:37:22 +02:00
Nikolas Klauser
667925d45a [libc++] bitset::operator[] const should return bool
Fixes https://github.com/llvm/llvm-project/issues/10686

Reviewed By: Mordante, ldionne, var-const, #libc

Spies: jloser, libcxx-commits, arphaman

Differential Revision: https://reviews.llvm.org/D122092
2022-04-13 22:55:04 +02:00
Louis Dionne
1352ea4ea1 [libc++] Mark completed paper as complete 2022-04-13 10:16:44 -04:00
Louis Dionne
db6421ec58 [libc++] Post-commit adjustments after rebasing D117656 2022-04-13 09:51:43 -04:00
Arthur O'Dwyer
2fb026ee4d Implement move_sentinel and C++20 move_iterator.
Differential Revision: https://reviews.llvm.org/D117656
2022-04-13 09:51:43 -04:00
Louis Dionne
2b424f4ea8 [libc++] Implement ranges::filter_view
Differential Revision: https://reviews.llvm.org/D109086
2022-04-13 09:03:46 -04:00
Konstantin Varlamov
e53c461bf3 [libc++][ranges] Implement lazy_split_view.
Note that this class was called just `split_view` in the original One
Ranges Proposal and was renamed to `lazy_split_view` by
[P2210](https://wg21.link/p2210).

Co-authored-by: zoecarver <z.zoelec2@gmail.com>

Differential Revision: https://reviews.llvm.org/D107500
2022-04-12 22:28:38 -07:00
Yuanfang Chen
81b51b61f8 Fix libcxx build after cd0a5889d7 2022-04-12 15:42:56 -07:00
Louis Dionne
0cc34ca7ec [libc++] Define legacy symbols for inline functions at a finer-grained level
When we build the library with the stable ABI, we need to include some
functions in the dylib that were made inline in later versions of the
library (to avoid breaking code that might be relying on those symbols).

However, those methods were made non-inline whenever we'd be building
the library, which means that all translation units would end up using
the old out-of-line definition of these methods, as opposed to the new
inlined version. This patch makes it so that only the translation units
that actually define the out-of-line methods use the old definition,
opening up potential optimization opportunities in other translation
units.

This should solve some of the issues encountered in D65667.

Differential Revision: https://reviews.llvm.org/D123519
2022-04-12 13:44:30 -04:00
Mark de Wever
7738db2c06 [NFC][libc++][test] Move time tests.
In the C++20 Standard time is no longer section under utilities, but
became its own chapter. This moves the time tests accordingly so their
location matches the current Standard.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D122745
2022-04-12 17:49:48 +02:00
Louis Dionne
8b5e4c038e [runtimes][CI] Add a 20 minutes individual test time out
If a single test has been running for more than 20 minutes on a CI node,
something is wrong and it should time-out instead of running until the
node potentially times out itself.

Differential Revision: https://reviews.llvm.org/D114896
2022-04-11 17:47:05 -04:00
zijunzhao
2d0475e371 [libcxx] locale_bionic.h: skip ndk-version.h on Android platform
The Android platform does not have ndk-version.h, but it will always
have up-to-date libc headers, so it does not need any compatibility
code intended for past versions of NDK_MAJOR. If ndk-version.h is missing,
assume NDK_MAJOR is (conceptually) infinite

Bug: https://buganizer.corp.google.com/issues/222341313
Test: None
2022-04-11 17:51:12 +00:00
Martin Storsjö
64e4dd329c [libcxx] [test] Fix back-to-back use of get_temp_file_name() on Windows
On non-Windows platforms, get_temp_file_name() uses `mkstemp()`,
which picks a unique name and creates a file atomically. The
Windows implementation uses `_mktemp_s()`, which doesn't create the
file. The documentation of `_mktemp_s()` also says that by design,
the function uses the same pattern within a process, as long as that
file doesn't exist.

Thus previously, two consecutive calls to `get_temp_file_name()`
on Windows returned the same file name.

Try to create the suggested temp file with `_O_EXCL` (marking the
file name as already used for future calls to `_mktemp_s`) and retry
if we weren't able to exclusively create the file.

This fixes the test failures on Windows observed in D122257.

Differential Revision: https://reviews.llvm.org/D122612
2022-04-11 19:46:40 +03:00
Louis Dionne
b9ca1e5a5a [libc++][NFC] Use noexcept instead of _NOEXCEPT for code compiled into the library
We build the library with C++20 anyways, so we can use noexcept directly.
2022-04-11 12:30:38 -04:00
Louis Dionne
c292b6066c [libc++] Implement P1007R3: std::assume_aligned
This supersedes and incoroporates content from both D108906 and D54966,
and also some original content.

Co-Authored-by: Marshall Clow <mclow.lists@gmail.com>
Co-Authored-by: Gonzalo Brito Gadeschi

Differential Revision: https://reviews.llvm.org/D118938
2022-04-11 10:46:52 -04:00
Louis Dionne
2c6217f252 [libc++] Make .version.pass.cpp tests be compile-only tests
We don't really need to run them.
2022-04-11 10:40:04 -04:00