Skip to content

Commit

Permalink
[libc++] Remove usage of internal string function in sstream (#75858)
Browse files Browse the repository at this point in the history
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](llvm/llvm-project#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:
llvm/llvm-project#72677

NOKEYCHECK=True
GitOrigin-RevId: 5351ded68d579921a61b26a34e36046c22f668bd
  • Loading branch information
Tacet authored and copybara-github committed Jan 8, 2024
1 parent 81fc38e commit 4b7fced
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/sstream
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ public:
typename string_type::size_type __pos = __view.empty() ? 0 : __view.data() - __str_.data();
// In C++23, this is just string_type(std::move(__str_), __pos, __view.size(), __str_.get_allocator());
// But we need something that works in C++20 also.
string_type __result(__str_.get_allocator());
__result.__move_assign(std::move(__str_), __pos, __view.size());
__str_.clear();
string_type __result(std::move(__str_), __str_.get_allocator());
__result.resize(__pos + __view.size());
__result.erase(0, __pos);
__init_buf_ptrs();
return __result;
}
Expand Down

0 comments on commit 4b7fced

Please sign in to comment.