diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-03-03 21:38:57 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-03-03 21:39:19 +0000 |
commit | 462f6c2041fad058abcdd5122e99a024f69a39d5 (patch) | |
tree | f6c890cf99d1ae83cf91bfd4a5d751e89d71a5e9 /gcc | |
parent | 0e0ffbfc23ba98ac40cbc6330e2750a6448b79d9 (diff) | |
download | gcc-462f6c2041fad058abcdd5122e99a024f69a39d5.zip gcc-462f6c2041fad058abcdd5122e99a024f69a39d5.tar.gz gcc-462f6c2041fad058abcdd5122e99a024f69a39d5.tar.bz2 |
libstdc++: Workaround is_trivially_copyable<volatile T> (PR 94013)
Several algorithms check the is_trivially_copyable trait to decide
whether to dispatch to memmove or memcmp as an optimization. Since
r271435 (CWG DR 2094) the trait is true for volatile-qualified scalars,
but we can't use memmove or memcmp when the type is volatile. We need to
also check for volatile types.
This is complicated by the fact that in C++20 (but not earlier standards)
iterator_traits<volatile T*>::value_type is T, so we can't just check
whether the value_type is volatile.
The solution in this patch is to introduce new traits __memcpyable and
__memcmpable which combine into a single trait the checks for pointers,
the value types being the same, and the type being trivially copyable
but not volatile-qualified.
PR libstdc++/94013
* include/bits/cpp_type_traits.h (__memcpyable, __memcmpable): New
traits to control when to use memmove and memcmp optimizations.
(__is_nonvolatile_trivially_copyable): New helper trait.
* include/bits/ranges_algo.h (__lexicographical_compare_fn): Do not
use memcmp optimization with volatile data.
* include/bits/ranges_algobase.h (__equal_fn): Use __memcmpable.
(__copy_or_move, __copy_or_move_backward): Use __memcpyable.
* include/bits/stl_algobase.h (__copy_move_a2): Use __memcpyable.
(__copy_move_backward_a2): Likewise.
(__equal_aux1): Use __memcmpable.
(__lexicographical_compare_aux): Do not use memcmp optimization with
volatile data.
* testsuite/25_algorithms/copy/94013.cc: New test.
* testsuite/25_algorithms/copy_backward/94013.cc: New test.
* testsuite/25_algorithms/equal/94013.cc: New test.
* testsuite/25_algorithms/fill/94013.cc: New test.
* testsuite/25_algorithms/lexicographical_compare/94013.cc: New test.
* testsuite/25_algorithms/move/94013.cc: New test.
* testsuite/25_algorithms/move_backward/94013.cc: New test.
Diffstat (limited to 'gcc')
0 files changed, 0 insertions, 0 deletions