diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2023-03-31 13:44:04 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2023-03-31 23:45:13 +0100 |
commit | 4969dcd2b7a94ce6c0d07225b21b5f3c040a4902 (patch) | |
tree | 04096d2c57bcfa03fff5a0c7e8b116aa2f1620f2 /c++tools | |
parent | 92f02e754ca2fbcd56dbd7b3949147d50bab99a0 (diff) | |
download | gcc-4969dcd2b7a94ce6c0d07225b21b5f3c040a4902.zip gcc-4969dcd2b7a94ce6c0d07225b21b5f3c040a4902.tar.gz gcc-4969dcd2b7a94ce6c0d07225b21b5f3c040a4902.tar.bz2 |
libstdc++: Teach optimizer that empty COW strings are empty [PR107087]
The compiler doesn't know about the invariant that the _S_empty_rep()
object is immutable and so _M_length and _M_refcount are always zero.
This means that we get warnings about writing possibly-non-zero length
strings into buffers that can't hold them. If we teach the compiler that
the empty rep is always zero length, it knows it can be copied into any
buffer.
For Stage 1 we might want to also consider adding this to capacity():
if (_S_empty_rep()._M_capacity != 0)
__builtin_unreachable();
And this to _Rep::_M_is_leaked() and _Rep::_M_is_shared():
if (_S_empty_rep()._M_refcount != 0)
__builtin_unreachable();
libstdc++-v3/ChangeLog:
PR tree-optimization/107087
* include/bits/cow_string.h (basic_string::size()): Add
optimizer hint that _S_empty_rep()._M_length is always zero.
(basic_string::length()): Call size().
Diffstat (limited to 'c++tools')
0 files changed, 0 insertions, 0 deletions