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++/62196] running time segment fault with valarray
Date: Tue, 14 Mar 2023 10:28:49 +0000	[thread overview]
Message-ID: <bug-62196-4-2p10obq58j@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-62196-4@http.gcc.gnu.org/bugzilla/>

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

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

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

commit r13-6656-gabb958ada1e4d195f31740659cd8af8bebce7bfd
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Mar 6 14:41:59 2023 +0000

    libstdc++: Add assertions to std::mask_array operations [PR62196]

    Add assertions to diagnose incorrect uses of valarray masks.

    The assignment operators of std::mask_array do not have any explicit
    preconditions in the standard, but the assignment operator
    valarray<T>::operator=(const mask_array<T>&) requires the lengths to
    match, so it seems consistent to also require that when the operands are
    reversed.  In support of that interpretation, libstdc++ has undefined
    behaviour if the right-hand operand has more elements than are selected
    by the mask, and libc++ has undefined behaviour if it has fewer
    elements. Our std::mask_array stores the number of selected elements as
    _M_sz so it's easy to add an assertion that checks it.

    For the valarray::operator[] that takes a valarray<bool> mask,
    [valarray.sub] in the standard says: "In each case the selected
    element(s) shall exist." This makes it undefined to have a mask that
    refers to out-of-range elements. We can easily check this too.

    libstdc++-v3/ChangeLog:

            PR libstdc++/62196
            * include/bits/mask_array.h (mask_array): Add assertions to
            assignment operators.
            * include/std/valarray (valarray::operator[](valarray<bool>)):
            Add assertions.
            * testsuite/26_numerics/valarray/mask-1_neg.cc: New test.
            * testsuite/26_numerics/valarray/mask-2_neg.cc: New test.
            * testsuite/26_numerics/valarray/mask-3_neg.cc: New test.
            * testsuite/26_numerics/valarray/mask-4_neg.cc: New test.
            * testsuite/26_numerics/valarray/mask-5_neg.cc: New test.
            * testsuite/26_numerics/valarray/mask-6_neg.cc: New test.
            * testsuite/26_numerics/valarray/mask-7_neg.cc: New test.
            * testsuite/26_numerics/valarray/mask-8_neg.cc: New test.
            * testsuite/26_numerics/valarray/mask.cc: New test.

  parent reply	other threads:[~2023-03-14 10:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-62196-4@http.gcc.gnu.org/bugzilla/>
2023-03-02 16:53 ` redi at gcc dot gnu.org
2023-03-14 10:28 ` cvs-commit at gcc dot gnu.org [this message]
2023-03-14 14:23 ` 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-62196-4-2p10obq58j@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).