diff options
author | Peng Liu <winner245@hotmail.com> | 2025-02-05 22:38:32 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-05 22:38:32 -0500 |
commit | efa287dd8a0920b20c3fe69253d8438ec8944383 (patch) | |
tree | 898aae2a86fb1c748527d0dd2b8b2aec336feba1 /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | |
parent | 4a2a8ed70da7ec44f0aa9092595e5b0f81a7e841 (diff) | |
download | llvm-efa287dd8a0920b20c3fe69253d8438ec8944383.zip llvm-efa287dd8a0920b20c3fe69253d8438ec8944383.tar.gz llvm-efa287dd8a0920b20c3fe69253d8438ec8944383.tar.bz2 |
[libc++] Slightly simplify max_size and add new tests for vector (#119990)
This PR slightly simplifies the implementation of `vector<bool>::max_size`
and adds extensive tests for the `max_size()` function for both `vector<bool>`
and `vector<T>`. The main purposes of the new tests include:
- Verify correctness of `max_size()` under various `size_type` and
`difference_type` definitions: check that `max_size()` works properly
with allocators that have custom `size_type` and `difference_type`. This
is particularly useful for `vector<bool>`, as different `size_type` lead
to different `__storage_type` of different word lengths, resulting in
varying `max_size()` values for `vector<bool>`. Additionally, different
`difference_type` also sets different upper limit of `max_size()` for
both `vector<bool>` and `std::vector`. These tests were previously
missing.
- Eliminate incorrect implementations: Special tests are added to identify and
reject incorrect implementations of `vector<bool>::max_size` that unconditionally
return `std::min<size_type>(size-max, __internal_cap_to_external(allocator-max-size))`.
This can cause overflow in the `__internal_cap_to_external()` call and lead
to incorrect results. The new tests ensure that such incorrect
implementations are identified.
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
0 files changed, 0 insertions, 0 deletions