public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6915] libstdc++: Tell GCC what basic_string::_M_is_local() means [PR109299]
@ 2023-03-28 20:14 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-03-28 20:14 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:bf78b43873b0b7e8f9a430df38749b8b61f9c9b8
commit r13-6915-gbf78b43873b0b7e8f9a430df38749b8b61f9c9b8
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Mar 28 10:50:40 2023 +0100
libstdc++: Tell GCC what basic_string::_M_is_local() means [PR109299]
This avoids a bogus warning about overflowing a buffer, because GCC
can't tell that we don't copy into the buffer unless it fits. By adding
a __builtin_unreachable() hint we inform the compiler about the
invariant that the buffer is only used when it's big enough.
This can also improve codegen, by eliminating dead code that GCC
couldn't tell was unreachable.
libstdc++-v3/ChangeLog:
PR libstdc++/109299
* include/bits/basic_string.h (basic_string::_M_is_local()): Add
hint for compiler that local strings fit in the local buffer.
Diff:
---
libstdc++-v3/include/bits/basic_string.h | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 1b8ebca7dad..5d040e2897d 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -271,7 +271,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX20_CONSTEXPR
bool
_M_is_local() const
- { return _M_data() == _M_local_data(); }
+ {
+ if (_M_data() == _M_local_data())
+ {
+ if (_M_string_length > _S_local_capacity)
+ __builtin_unreachable();
+ return true;
+ }
+ return false;
+ }
// Create & Destroy
_GLIBCXX20_CONSTEXPR
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-28 20:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-28 20:14 [gcc r13-6915] libstdc++: Tell GCC what basic_string::_M_is_local() means [PR109299] Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).