public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/109703] [12/13/14 Regression] __builtin_unreachable() reached since r13-6915-gbf78b43873b0b7
Date: Wed, 03 May 2023 12:24:44 +0000	[thread overview]
Message-ID: <bug-109703-4-rYQ8KTu1Ya@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109703-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:d50f2599d7b23bdba05a9102645d082ed9bcb05f

commit r13-7282-gd50f2599d7b23bdba05a9102645d082ed9bcb05f
Author: Kefu Chai <kefu.chai@scylladb.com>
Date:   Mon May 1 21:24:26 2023 +0100

    libstdc++: Set _M_string_length before calling _M_dispose() [PR109703]

    This always sets _M_string_length in the constructor for ranges of input
    iterators, such as stream iterators.

    We copy from the source range to the local buffer, and then repeatedly
    reallocate a larger one if necessary. When disposing the old buffer,
    _M_is_local() is used to tell if the buffer is the local one or not (and
    so must be deallocated). In addition to comparing the buffer address
    with the local buffer, _M_is_local() has an optimization hint so that
    the compiler knows that for a string using the local buffer, there is an
    invariant that _M_string_length <= _S_local_capacity (added for PR109299
    via r13-6915-gbf78b43873b0b7).  But we failed to set _M_string_length in
    the constructor taking a pair of iterators, so the invariant might not
    hold, and __builtin_unreachable() is reached. This causes UBsan errors,
    and potentially misoptimization.

    To ensure the invariant holds, _M_string_length is initialized to zero
    before doing anything else, so that _M_is_local() doesn't see an
    uninitialized value.

    This issue only surfaces when constructing a string with a range of
    input iterator, and the uninitialized _M_string_length happens to be
    greater than _S_local_capacity, i.e., 15 for the std::string
    specialization.

    libstdc++-v3/ChangeLog:

            PR libstdc++/109703
            * include/bits/basic_string.h (basic_string(Iter, Iter, Alloc)):
            Initialize _M_string_length.

    Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
    Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
    (cherry picked from commit cbf6c7a1d16490a1e63e9a5ce00e9a5c44c4c2f2)

  parent reply	other threads:[~2023-05-03 12:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-02 19:05 [Bug libstdc++/109703] New: __builtin_unreachable() reached christian.morales.vega at gmail dot com
2023-05-02 20:10 ` [Bug libstdc++/109703] [13/14 Regression] " pinskia at gcc dot gnu.org
2023-05-02 20:11 ` [Bug libstdc++/109703] [12/13/14 " pinskia at gcc dot gnu.org
2023-05-02 20:14 ` pinskia at gcc dot gnu.org
2023-05-02 20:35 ` [Bug libstdc++/109703] [12/13/14 Regression] __builtin_unreachable() reached since r13-6915-gbf78b43873b0b7 redi at gcc dot gnu.org
2023-05-03  2:00 ` pinskia at gcc dot gnu.org
2023-05-03 12:19 ` cvs-commit at gcc dot gnu.org
2023-05-03 12:24 ` cvs-commit at gcc dot gnu.org [this message]
2023-05-03 13:24 ` cvs-commit at gcc dot gnu.org
2023-05-03 13:25 ` redi at gcc dot gnu.org
2023-05-04 15:43 ` pinskia at gcc dot gnu.org
2023-05-09 11:22 ` redi at gcc dot gnu.org
2023-07-04 16:41 ` redi 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-109703-4-rYQ8KTu1Ya@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).