Commit Graph

11347 Commits

Author SHA1 Message Date
Mark de Wever
ab398416a7 [libc++][modules] Fixes RTTI build.
This was reviewed in https://github.com/llvm/llvm-project/pull/76246
2024-01-16 20:16:29 +01:00
Louis Dionne
127c390fc4
[libc++] Rewrite the IWYU generation (#78295)
This simplifies the IWYU generation script by treating everything as a
file, instead of dealing with directories and files separately.

This has the downside that the `libcxx.imp` file is a lot larger than it
used to be, however we now have the flexibility of mapping files under
detail directories to different public headers. For example, this allows
us to map <__fwd/subrange.h> to <ranges> but <__fwd/pair.h> to
<utility>.

This patch also adds basic validation to ensure that we never map a
header to a public header that doesn't exist. We may still be missing
some mappings or we may be mapping to incorrect headers, but we won't be
mapping to headers that downright don't exist.

Fixes #63346
2024-01-16 13:45:05 -05:00
Louis Dionne
8803112bee [libc++][NFC] Add deprecated mention for _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS in the docs
This was missed in the patch where I marked the macro as deprecated.
2024-01-16 13:16:15 -05:00
Mark de Wever
4a87db6b10
[libc++][print] Enables it on Apple backdeployment. (#76293)
As suggested in #73262 this enable the stream printing on Apple
backdeployment targets. This omits the check whether the file is a
terminal. This is not entirely conforming, but the differences should be
minor and are typically not observable.

Fixes https://github.com/llvm/llvm-project/issues/75225
2024-01-16 19:14:33 +01:00
Mark de Wever
34933d1872
[libc++] Improves _LIBCPP_HAS_NO_THREADS guards. (#76624)
Previously the header included several headers, possibly granularized
threading headers. This could lead to build errors when these headers
were incompatible with threading disabled.

Now test the guard before inclusion. This matches the pattern used for
no localization and no wide characters.

Fixes: https://github.com/llvm/llvm-project/issues/76620
2024-01-16 19:13:40 +01:00
Mark de Wever
e0443624b9
[libc++] Deprecate removed features macros. (#77879)
We discussed the removal of these enable-all macros in the libc++
monthly meeting and we agreed that we should deprecate these macros in
LLVM 18, and then remove them in LLVM 19 since they can silently enable
deprecated features that are implemented after the first release of the
macro.

This patch does the first part of this -- it deprecates the macro.

Note that the file
  test/libcxx/depr/enable_removed_cpp20_features.compile.pass.cpp
does not exist so this file is not adapted. Since the feature is
deprecated and slated for removal soon the missing test is not
implemented.

Partly addresses: https://github.com/llvm/llvm-project/issues/75976

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-01-16 19:12:59 +01:00
Mark de Wever
82d21814e6
[libc++][print] Includes <format>. (#76333)
The overloads of `println` are specified in terms of `format`. The
function `format` is specified to work with ranges.

The implementations for `println` do not include `<format>`, but
libc++'s granularized header. This means the following example does not
work

  #include <vector>
  #include <print>

  int main() {
      std::vector<int> v{1, 2, 3};
      std::println("{}", v);
  }

(The other print functions also require this to work, they are specified
in terms of other format functions.)

Fixes: https://github.com/llvm/llvm-project/issues/71925
2024-01-16 17:33:01 +01:00
Mark de Wever
a8b3deb2c8
[libc++][print] Renames __use_unicode. (#76290)
This is addresses a review comment in #73262.
2024-01-16 17:32:11 +01:00
Mark de Wever
127fc7930a
[libc++][doc] Removes LLVM-17 release notes. (#78062)
The old notes are kept to make it easier to backport changes to the
release branch. There are no LLVM-17 releases expected and this
documentation should not be available in the LLVM-18 release.

Note after branching LLVM-18 both LLVM-18 and LLVM-19 release notes
should be available.
2024-01-16 17:26:08 +01:00
Hristo Hristov
17058940c0
[libc++][utility][NFC] Refactored safe integer cmp_xxxx functions to use the __libcpp_is_integer concept (#78115)
Replaced a functionally identical internal concept helper.

References:
- https://eel.is/c++draft/utility.intcmp
- https://eel.is/c++draft/basic.fundamental

Co-authored-by: Zingam <zingam@outlook.com>
2024-01-16 13:17:59 +02:00
Hristo Hristov
bddd8f46f8
[libc++][concepts] Implements concept helper __libcpp_integer (#78086)
...and tests.

---------

Co-authored-by: Zingam <zingam@outlook.com>
2024-01-15 00:00:57 +02:00
Mark de Wever
270c6cbda2 [libc++][doc] Bump required GCC version.
GCC 13 is the latest GCC release and tested in the libc++ CI for several
month. According to our policy we only support the latest version,
update the documentation to the latest version.
2024-01-13 20:04:40 +01:00
Hristo Hristov
3f21253ddd
[libc++][NFC] Release notes: fixed formatting (#78058)
Co-authored-by: Zingam <zingam@outlook.com>
2024-01-13 20:14:38 +02:00
Tacet
60ac394dc9
[ASan][libc++] Annotating std::basic_string with all allocators (#75845)
This commit turns on ASan annotations in `std::basic_string` for all
allocators by default.

Originally suggested here: https://reviews.llvm.org/D146214

String annotations added here:
https://github.com/llvm/llvm-project/pull/72677

This commit is part of our efforts to support container annotations with
(almost) every allocator. Annotating `std::basic_string` with default
allocator is implemented in
https://github.com/llvm/llvm-project/pull/72677.

Additionally it removes `__begin != nullptr` because `data()` should
never return a nullptr.

Support in ASan API exists since
1c5ad6d2c0.
This patch removes the check in std::basic_string annotation member
function (__annotate_contiguous_container) to support different
allocators.

You can turn off annotations for a specific allocator based on changes
from
2fa1bec7a2.

The motivation for a research and those changes was a bug, found by
Trail of Bits, in a real code where an out-of-bounds read could happen
as two strings were compared via a call to `std::equal` that took
`iter1_begin`, `iter1_end`, `iter2_begin` iterators (with a custom
comparison function). When object `iter1` was longer than `iter2`, read
out-of-bounds on `iter2` could happen. Container sanitization would
detect it.

If you have any questions, please email:
- advenam.tacet@trailofbits.com
- disconnect3d@trailofbits.com
2024-01-13 18:11:53 +01:00
Dominik Wójt
2b2310484f
[libc++] tests with picolibc: update picolibc (#77908)
The updated picolibc version has "isblank" function with external
linkage. This is required for C++ modules support.

This should solve all the problems reported in #76980, but
we'll wait to validate this with the modules build without
closing that issue.
2024-01-12 17:32:04 -05:00
Ryan Prichard
4c41449edd
[libc++][Android] Add NDK ABI lists for i686 and x86_64 (#69272)
This commit adds ABI lists for the Android NDK.

Fixes: https://github.com/llvm/llvm-project/issues/69270
Differential Revision: https://reviews.llvm.org/D155341
2024-01-12 13:00:16 -08:00
Will Hawkins
882b4fccd2
[libc++][NFC] Make AssertionInfoMatcher::CheckMessageMatches Stricter (#77721)
Rather than allow for a message to be considered a match for the actual
assertion if it is anywhere in the assertion text, make sure that the
expected and the actual assertion are identical.

Addresses #77701
2024-01-12 14:45:52 -05:00
Wu Yingcong
dc1ae83789
[libc++][test] Fix a logical mistake introduced by #77058 (#77867)
A logical mistake is made in #77058, we should try to find a new file
path for socket creation when the path's length generated is bigger than
the socket length limit.
2024-01-12 17:48:34 +01:00
Louis Dionne
8751bbe7d3
[libc++] Deprecate the _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS macro (#77692)
As described in #69994, using the escape hatch makes us non-conforming
in C++20 due to incorrect constexpr-ness. It also leads to bad
diagnostics as reported by #63900. We discussed the issue in the libc++
monthly meeting and we agreed that we should deprecate the macro in LLVM
18, and then remove it in LLVM 19 since it causes too many problems.

This patch does the first part of this -- it deprecates the macro.

Fixes #69994
Fixes #63900
Partially addresses #75975
2024-01-12 09:51:14 -05:00
a-n-n-a-l-e-e
b3981edb51
[libc++] Re-export libc++abi symbols on Apple platforms when using system-libcxxabi (#77218)
When using LIBCXX_CXX_ABI=system-libcxxabi on Apple platforms, we would not
re-export the libc++abi symbols unlike when LIBCXX_CXX_ABI=libcxxabi. This
was caused by overly strict string matching in CMake.

https://github.com/NixOS/nixpkgs/issues/269548
2024-01-11 17:07:11 -05:00
Tacet
75efddba0f
[ASan][libc++] Initialize __r_ variable with lambda (#77394)
This commit is a refactor (increases readability) and optimization fix.

This is a fixed commit of
https://github.com/llvm/llvm-project/pull/76200 First reverthed here:
1ea7a56057

Please, check original PR for details.

The difference is a return type of the lambda.

Original description:

This commit addresses optimization and instrumentation challenges
encountered within comma constructors.
1) _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS does not work in comma
constructors.
2) Code inside comma constructors is not always correctly optimized.
Problematic code examples:
- `: __r_(((__str.__is_long() ? 0 : (__str.__annotate_delete(), 0)),
std::move(__str.__r_))) {`
- `: __r_(__r_([&](){ if(!__s.__is_long()) __s.__annotate_delete();
return std::move(__s.__r_);}())) {`

However, lambda with argument seems to be correctly optimized. This
patch uses that fact.

Use of lambda based on idea from @ldionne.
2024-01-11 21:40:00 +01:00
Louis Dionne
8f90e6937a
[runtimes] Use LLVM libunwind from libc++abi by default (#77687)
I recently came across LIBCXXABI_USE_LLVM_UNWINDER and was surprised to
notice it was disabled by default. Since we build libunwind by default
and ship it in the LLVM toolchain, it would seem to make sense that
libc++ and libc++abi rely on libunwind for unwinding instead of using
the system-provided unwinding library (if any).

Most importantly, using the system unwinder implies that libc++abi is
ABI compatible with that system unwinder, which is not necessarily the
case. Hence, it makes a lot more sense to instead default to using the
known-to-be-compatible LLVM unwinder, and let vendors manually select a
different unwinder if desired.

As a follow-up change, we should probably apply the same default to
compiler-rt.

Differential Revision: https://reviews.llvm.org/D150897
Fixes #77662
rdar://120801778
2024-01-11 10:13:21 -05:00
S. B. Tam
e0c734561d
[libc++][test] Replace uses of _LIBCPP_ABI_MICROSOFT in tests (#77233) 2024-01-11 10:55:52 +08:00
Christopher Di Bella
98e3d98bf3
[libc++] Rename local variable to avoid shadowing error (#77672)
Due to the inclusion of a header, a global type is was being shadowed,
which upset GCC.
2024-01-10 17:28:22 -05:00
Louis Dionne
5c9b713394 [libc++][NFC] Fix typo in comments 2024-01-10 13:41:59 -05:00
Louis Dionne
761b9d9e46
[libc++] Remove _LIBCPP_C_HAS_NO_GETS (#77346)
Since we use _LIBCPP_USING_IF_EXISTS to handle missing C library functions
now, _LIBCPP_C_HAS_NO_GETS shouldn't be necessary anymore.
See the discussion thread in #77242 for more details.
2024-01-10 13:34:03 -05:00
Louis Dionne
f502b981b4 [libc++][NFC] Add comment in test to explain the presence of some assertions 2024-01-10 13:02:50 -05:00
Will Hawkins
d301539b77
[libc++][docs] Document the libc++ Lit testing format naming scheme (#73136)
As a new contributor, I found it hard to find the documentation for the
meaning of the names of different tests and how those names translate to
Lit. This patch moves the documentation to the RST documentation we
publish on the website instead of leaving it in the source code only.
2024-01-10 10:51:06 -05:00
Will Hawkins
e07a2f49e3
[libc++][NFC] Create and use test-defined simple_view concept (#77334)
Instead of using a concept defined in the internal implementation, use a
definition of the simple_view ranges concept separately defined and
included in test code.
2024-01-09 14:07:32 -08:00
James Touton
65a1efc60c
Fixed shared_ptr comparisons with nullptr_t when spaceship is unavailable. (#76781)
This was causing compilation errors when attempting to compare a
`shared_ptr<T[]>` with `nullptr`, as `get()` returns `T*` rather than `T
(*)[]`. `unique_ptr` did not have this issue, but I've added tests to
make sure.
2024-01-09 20:41:24 +01:00
Sanjay Marreddi
0804ef2d15
[libc++] Fix regex_search to match $ alone with match_default flag (#77256)
Using `regex_search` with the regex_constant `match_default` and a
simple regex pattern `$` is expected to match general strings such as
_"a", "ab", "abc"..._ at `[last, last)` positions. But, the current
implementation fails to do so.

Fixes #75042
2024-01-09 20:39:36 +01:00
Wu Yingcong
a43e0f90b6
[libc++][test] try to directly create socket file in /tmp when filepath is too long (#77058)
If TMP is set to a folder which path is too long, the current libcxx
test helper function `create_socket()` will fail because of the test
temp folder `test_root`'s path is too long to be used in socket
creation.
In such case, this patch will try to create the socket file directly in
`/tmp` folder.

This patch also add an assertion for `bind()`.
2024-01-09 20:15:44 +01:00
Mark de Wever
f0fd8fd752
[libc++][CI] Moves CI badge to main README. (#77247)
The current CI badge is currently in libc++ documentation. This does not
seem the right place:
- The typical location on GitHub is on the main README.
- The documentation is shipped as part of the release:
- This link does not work in off-line mode. Currently our documentation
works in off-line mode.
- The status in the release documentation does not reflect the status of
the shipped library. So users looking at it may see a red status and get
confused.

This moves the badge to the README.
2024-01-09 19:12:42 +01:00
Mark de Wever
d29297239f
[libc++] Implements P2517R1. (#77239)
As pointed out by @Zingam the paper was implemented in libc++ as an
extension. This patch does the bookkeeping. The inital release version
is based on historical release dates.

Completes:
- Add a conditional noexcept specification to std::apply
2024-01-09 19:11:40 +01:00
Louis Dionne
ca06c330fd
[libc++] Allow running the test suite with optimizations (#68753)
This patch adds a configuration of the libc++ test suite that enables
optimizations when building the tests. It also adds a new CI
configuration to exercise this on a regular basis. This is added in the
context of [1], which requires building with optimizations in order to
hit the bug.

[1]: https://github.com/llvm/llvm-project/issues/68552
2024-01-09 10:39:14 -05:00
Advenam Tacet
1ea7a56057 Revert "[ASan][libc++] String annotations optimizations fix with lambda (#76200)"
This reverts commit c68a9d25e9.
2024-01-09 00:45:34 +01:00
Tacet
5351ded68d
[libc++] Remove usage of internal string function in sstream (#75858)
This function replaces a call to `__move_assign` (internal function)
with two calls to public member functions (`resize` and `erase`). The
order of calls is chosen for the best performance.

This change is required to [turn on ASan string annotations for short
strings](https://github.com/llvm/llvm-project/pull/75882) (Short String
Optimization - SSO).

The `std::basic_string` class's `void __move_assign(basic_string&&
__str, size_type __pos, size_type __len)` function operates on
uninitialized strings, where it is reasonable to assume that the memory
is not poisoned. However, in `sstream` this function is applied to
existing strings that already have poisoned memory.

String ASan annotations turned on here:
https://github.com/llvm/llvm-project/pull/72677
2024-01-08 18:56:43 +01:00
Tacet
c68a9d25e9
[ASan][libc++] String annotations optimizations fix with lambda (#76200)
This commit addresses optimization and instrumentation challenges
encountered within comma constructors.
1) _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS does not work in comma
constructors.
2) Code inside comma constructors is not always correctly optimized.
Problematic code examples:
- `: __r_(((__str.__is_long() ? 0 : (__str.__annotate_delete(), 0)),
std::move(__str.__r_))) {`
- `: __r_(__r_([&](){ if(!__s.__is_long()) __s.__annotate_delete();
return std::move(__s.__r_);}())) {`

However, lambda with argument seems to be correctly optimized. The patch employs this.

Use of lambda based on an idea from @ldionne.
2024-01-08 18:02:17 +01:00
Mark de Wever
01410103a6
[libc++][doc] Marks LWG3257 as complete (#77237)
The macros were already updated
- __cpp_lib_string_view in 466df1718e
- __cpp_lib_array_constexpr in 77b9abfc8e

Based on the dates of the commit and that
 P0858 "Constexpr iterator requirements"
was completed in LLVM 12, set this issue as completed in the same
version.

Completes
- LWG3257 Missing feature testing macro update from P0858
2024-01-08 17:24:42 +01:00
David Spickett
acbb491ab2
[libcxx] Require qemu-system-arm for armv7m builder (#77067)
And add a check in the python script that the binary given to `--qemu`
actually exists. Otherwise you get a generic Python error:
```
 # .---command stderr------------
 # | Traceback (most recent call last):
 # |   File "/home/david.spickett/modules-llvm-project/libcxx/utils/qemu_baremetal.py", line 70, in <module>
 # |     exit(main())
 # |   File "/home/david.spickett/modules-llvm-project/libcxx/utils/qemu_baremetal.py", line 66, in main
 # |     os.execvp(qemu_commandline[0], qemu_commandline)
 # |   File "/usr/lib/python3.8/os.py", line 568, in execvp
 # |     _execvpe(file, args)
 # |   File "/usr/lib/python3.8/os.py", line 610, in _execvpe
 # |     raise last_exc
 # |   File "/usr/lib/python3.8/os.py", line 601, in _execvpe
 # |     exec_func(fullname, *argrest)
 # | FileNotFoundError: [Errno 2] No such file or directory
 # `-----------------------------
 # error: command failed with exit status: 1
```
When it tries to run the entire command later.

For the builder, it's only ever going to use qemu-system-arm so error at
config time if it's not there.
2024-01-08 08:55:39 +00:00
Hristo Hristov
92e243173c
Reapply "[libc++][streams] P1759R6: Native handles and file streams" (#77190)
Fixes build on Windows in C++26 mode.

Reverted in:
40c07b559a
Original PR: https://github.com/llvm/llvm-project/pull/76632

---------

Co-authored-by: Zingam <zingam@outlook.com>
2024-01-07 18:01:03 +02:00
Mark de Wever
3e498b3db5 [libc++][doc] Minor release notes style fixes. 2024-01-07 15:19:22 +01:00
Mark de Wever
e497f68923 [NFC][libc++] Formats tuple.
The fix used macros that confuses clang-format. This is formatted with
clang-format and then excluded from formatting.
2024-01-07 15:01:25 +01:00
Mark de Wever
1f9c2ddd8c
[libc++][test] Improves suspurious clang diagnostics. (#77234)
As suggested by @philnik777 this is a better fix than
02a33b72fd

Fixes: https://github.com/llvm/llvm-project/issues/77123
2024-01-07 14:49:19 +01:00
Haowei Wu
40c07b559a Revert "[libc++][streams] P1759R6: Native handles and file streams (#76632)"
This reverts commit 255f95a403, which
contains a breaking libcxx test on Windows when using C++26
2024-01-05 17:23:40 -08:00
Konstantin Varlamov
4f215fdd62
[libc++][hardening] Categorize more assertions. (#75918)
Also introduce `_LIBCPP_ASSERT_PEDANTIC` for assertions violating which
results in a no-op or other benign behavior, but which may nevertheless
indicate a bug in the invoking code.
2024-01-05 16:29:23 -08:00
Mark de Wever
02a33b72fd
"Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (#76833)
…te initialization" (#76272)""

With updates the libc++ tests.

This reverts commit 2205d23 and relands
86dc6e1 and
7ab16fb.

Original commit was reverted because of failing libc++ tests, see #76232
for the discussion.

The errors in the tests are spurious in the first place (coming from
initialization of invalid classes), so update the tests to match new
behavior that does not show those errors.

The original patch was written by @ilya-biryukov 

To fix the CI two libc++ tests are temporary disabled for clang-18.
2024-01-05 19:43:10 +01:00
Hristo Hristov
255f95a403
[libc++][streams] P1759R6: Native handles and file streams (#76632)
Implements: `P1759R6` https://wg21.link/P1759R6

- https://eel.is/c++draft/filebuf
- https://eel.is/c++draft/ifstream
- https://eel.is/c++draft/ofstream
- https://eel.is/c++draft/fstream

---------

Co-authored-by: Zingam <zingam@outlook.com>
2024-01-05 11:42:08 +02:00
Hristo Hristov
a72ab9c14d
[libc++][span] P2821R5: span.at() (#74994)
- Implements: [P2821R5: span.at()](https://wg21.link/P2821R5)
  (https://eel.is/c++draft/views.contiguous#views.span)
- Cleaned up `span.operator[]` test

---------

Co-authored-by: Zingam <zingam@outlook.com>
2024-01-05 11:41:22 +02:00
ZijunZhaoCCK
0414cf09f0
Move nondiscard tests of ranges::contains() to the right place. (#76887)
nondiscard tests of ranges::contains() should be in
ranges.nodiscard_extensions files rather than nodiscard_extensions files
2024-01-04 14:25:13 -08:00