From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 359403858439; Tue, 14 Mar 2023 10:28:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 359403858439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678789731; bh=aISteEgIFN9X/3Wbn8OBhUlTyVUJBFTZNu+2uDxehnE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=upXJXQhLZ1Bm99Wd4Ym5d01NohZlfiDfnQSBPharlPM1iRosVqtqJIrwh+5Gxj2ek DuFsjyErt7lTiutLUlhKlPy50O4+ighZJdSxC2k3CH+bPXp+yzFsyh/orboY907NEX 9JqOY0JO5/F7duiywl4Lm2xDvamN6pOlNUbcQqZM= From: "cvs-commit at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 4.9.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D62196 --- Comment #3 from CVS Commits --- The master branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:abb958ada1e4d195f31740659cd8af8bebce7bfd commit r13-6656-gabb958ada1e4d195f31740659cd8af8bebce7bfd Author: Jonathan Wakely 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::operator=3D(const mask_array&) 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 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)): 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.=