[all-commits] [llvm/llvm-project] a5b3d3: [libc++] Fix {std, ranges}::copy for vector<bool> ...
Peng Liu via All-commits
all-commits at lists.llvm.org
Wed Mar 19 08:56:13 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: a5b3d3a03f3291b1b62c7c25bc40b494660421cb
https://github.com/llvm/llvm-project/commit/a5b3d3a03f3291b1b62c7c25bc40b494660421cb
Author: Peng Liu <winner245 at hotmail.com>
Date: 2025-03-19 (Wed, 19 Mar 2025)
Changed paths:
M libcxx/include/__algorithm/copy.h
M libcxx/include/__fwd/bit_reference.h
M libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp
M libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.pass.cpp
Log Message:
-----------
[libc++] Fix {std, ranges}::copy for vector<bool> with small storage types (#131545)
The current implementation of `{std, ranges}::copy` fails to copy
`vector<bool>` correctly when the underlying storage type
(`__storage_type`) is smaller than `int`, such as `unsigned char`,
`unsigned short`, `uint8_t` and `uint16_t`. The root cause is that the
unsigned small storage type undergoes integer promotion to (signed)
`int`, which is then left and right shifted, leading to UB (before
C++20) and sign-bit extension (since C++20) respectively. As a result,
the underlying bit mask evaluations become incorrect, causing erroneous
copying behavior.
This patch resolves the issue by correcting the internal bitwise
operations, ensuring that `{std, ranges}::copy` operates correctly for
`vector<bool>` with any custom (unsigned) storage types.
Fixes #131692.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list