aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2023-02-25 14:28:36 +0000
committerJonathan Wakely <jwakely@redhat.com>2023-02-28 09:49:11 +0000
commit822a11a1e642e0abe92a996e7033a5066905a447 (patch)
tree123c11aa9575f6e123ba010b3737568aff8ec4d0 /gcc
parenta41a56dee5c2d48337739d60c43cab5074bcc8e7 (diff)
downloadgcc-822a11a1e642e0abe92a996e7033a5066905a447.zip
gcc-822a11a1e642e0abe92a996e7033a5066905a447.tar.gz
gcc-822a11a1e642e0abe92a996e7033a5066905a447.tar.bz2
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==1, but the copy/move operation needs to be done using assignment, not a memmove or memcpy of sizeof(Base) bytes. Instead of putting a check for N==1 in all of copy, copy_n, move etc. this adds it to the __copy_move and __copy_move_backward partial specializations used for trivially copyable types. When N==1 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<false, false, RA>) Add __assign_one static member function. (__copy_move<true, false, RA>): Likewise. (__copy_move<IsMove, true, RA>): Do not use memmove for a single value. (__copy_move_backward<IsMove, true, RA>): 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.
Diffstat (limited to 'gcc')
0 files changed, 0 insertions, 0 deletions