From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6C193385829B; Mon, 18 Mar 2024 14:06:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C193385829B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710770760; bh=cWa6xuIFKxmtlVu6dgZr27HylrnxQsX9WdPVu5aIyzM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LYzDA+z1qRJ8EdIU7N76GEOaTiUcKK3RVQahNx5iHOEYq2WlbbNBx9anDJpucqjzU w3+eO+3CvL8j7TpNdkzbMsDaRTxWErJIZzN7sB63vuyg5+2UMhmvwBXb4kQuHwpe80 VokKiYWuB01568RjwIJcDUV9e4eeWDs7atJIy3Dw= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/108846] std::copy, std::copy_n and std::copy_backward on potentially overlapping subobjects Date: Mon, 18 Mar 2024 14:05:56 +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: 13.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi 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=3D108846 --- Comment #26 from GCC Commits --- The releases/gcc-12 branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:8ec265c1464dec74f98e6914cd164af5090a39ff commit r12-10250-g8ec265c1464dec74f98e6914cd164af5090a39ff Author: Jonathan Wakely Date: Sat Feb 25 14:28:36 2023 +0000 libstdc++: Do not use memmove for 1-element ranges [PR108846] This avoids overwriting tail padding when algorithms like std::copy are used to write a single value through a pointer to a base subobject. The pointer arithmetic on a Base* is valid for N=3D=3D1, but the copy/m= ove operation needs to be done using assignment, not a memmove or memcpy of sizeof(Base) bytes. Instead of putting a check for N=3D=3D1 in all of copy, copy_n, move et= c. this adds it to the __copy_move and __copy_move_backward partial specializations used for trivially copyable types. When N=3D=3D1 those partial specializations dispatch to new static member functions of the partial specializations for non-trivial types, so that a copy/move assignment is done appropriately for the _IsMove constant. libstdc++-v3/ChangeLog: PR libstdc++/108846 * include/bits/stl_algobase.h (__copy_move) Add __assign_one static member function. (__copy_move): Likewise. (__copy_move): Do not use memmove for a single value. (__copy_move_backward): Likewise. * testsuite/25_algorithms/copy/108846.cc: New test. * testsuite/25_algorithms/copy_backward/108846.cc: New test. * testsuite/25_algorithms/copy_n/108846.cc: New test. * testsuite/25_algorithms/move/108846.cc: New test. * testsuite/25_algorithms/move_backward/108846.cc: New test. (cherry picked from commit 822a11a1e642e0abe92a996e7033a5066905a447)=