public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/107087] [12/13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
Date: Fri, 31 Mar 2023 12:43:43 +0000	[thread overview]
Message-ID: <bug-107087-4-QWSvRhjPR1@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107087-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107087

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I wonder if some other hints about properties of the empty rep would help
codegen:

--- a/libstdc++-v3/include/bits/cow_string.h
+++ b/libstdc++-v3/include/bits/cow_string.h
@@ -204,6 +204,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        bool
        _M_is_leaked() const _GLIBCXX_NOEXCEPT
        {
+#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
+         if (_S_empty_rep()._M_refcount != 0)
+           __builtin_unreachable();
+#endif
+
 #if defined(__GTHREADS)
          // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose,
          // so we need to use an atomic load. However, _M_is_leaked
@@ -218,6 +223,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        bool
        _M_is_shared() const _GLIBCXX_NOEXCEPT
        {
+#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
+         if (_S_empty_rep()._M_refcount != 0)
+           __builtin_unreachable();
+#endif
+
 #if defined(__GTHREADS)
          // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose,
          // so we need to use an atomic load. Another thread can drop last
@@ -907,17 +917,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

     public:
       // Capacity:
+
       ///  Returns the number of characters in the string, not including any
       ///  null-termination.
       size_type
       size() const _GLIBCXX_NOEXCEPT
-      { return _M_rep()->_M_length; }
+      {
+#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
+       if (_S_empty_rep()._M_length != 0)
+         __builtin_unreachable();
+#endif
+       return _M_rep()->_M_length;
+      }

       ///  Returns the number of characters in the string, not including any
       ///  null-termination.
       size_type
       length() const _GLIBCXX_NOEXCEPT
-      { return _M_rep()->_M_length; }
+      { return size(); }

       ///  Returns the size() of the largest possible %string.
       size_type

  parent reply	other threads:[~2023-03-31 12:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-29 14:35 [Bug middle-end/107087] New: " redi at gcc dot gnu.org
2023-03-09 20:48 ` [Bug tree-optimization/107087] " redi at gcc dot gnu.org
2023-03-09 20:49 ` [Bug tree-optimization/107087] [13 Regression] " redi at gcc dot gnu.org
2023-03-15 10:00 ` rguenth at gcc dot gnu.org
2023-03-27 13:00 ` rguenth at gcc dot gnu.org
2023-03-27 13:52 ` rguenth at gcc dot gnu.org
2023-03-27 14:00 ` redi at gcc dot gnu.org
2023-03-28 13:25 ` cvs-commit at gcc dot gnu.org
2023-03-28 13:26 ` rguenth at gcc dot gnu.org
2023-03-30  8:31 ` redi at gcc dot gnu.org
2023-03-31 11:36 ` [Bug tree-optimization/107087] [12/13 " rguenth at gcc dot gnu.org
2023-03-31 11:55 ` redi at gcc dot gnu.org
2023-03-31 12:43 ` redi at gcc dot gnu.org [this message]
2023-03-31 22:45 ` cvs-commit at gcc dot gnu.org
2023-03-31 23:25 ` [Bug tree-optimization/107087] [12 " redi at gcc dot gnu.org
2023-04-27 11:50 ` rguenth at gcc dot gnu.org
2023-04-27 12:00 ` redi at gcc dot gnu.org
2023-04-29  0:41 ` sjames at gcc dot gnu.org
2023-04-29  6:56 ` redi at gcc dot gnu.org
2023-04-29  7:02 ` sjames at gcc dot gnu.org
2023-05-08 12:25 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107087-4-QWSvRhjPR1@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).