Files
gcc/libstdc++-v3/include/pstl/memory_impl.h
Jonathan Wakely 9c75032b40 libstdc++: Protect PSTL headers against overloaded commas
Reported upstream: https://github.com/uxlfoundation/oneDPL/issues/2342

libstdc++-v3/ChangeLog:

	* include/pstl/algorithm_impl.h (__for_each_n_it_serial):
	Protect against overloaded comma operator.
	(__brick_walk2): Likewise.
	(__brick_walk2_n): Likewise.
	(__brick_walk3): Likewise.
	(__brick_move_destroy::operator()): Likewise.
	(__brick_calc_mask_1): Likewise.
	(__brick_copy_by_mask): Likewise.
	(__brick_partition_by_mask): Likewise.
	(__brick_calc_mask_2): Likewise.
	(__brick_reverse): Likewise.
	(__pattern_partial_sort_copy): Likewise.
	* include/pstl/memory_impl.h (__brick_uninitialized_move):
	Likewise.
	(__brick_uninitialized_copy): Likewise.
	* include/pstl/numeric_impl.h (__brick_transform_scan):
	Likewise.
2025-07-14 12:54:42 +01:00

108 lines
4.1 KiB
C++

// -*- C++ -*-
//===-- memory_impl.h -----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _PSTL_MEMORY_IMPL_H
#define _PSTL_MEMORY_IMPL_H
#include <iterator>
#include "unseq_backend_simd.h"
namespace __pstl
{
namespace __internal
{
//------------------------------------------------------------------------
// uninitialized_move
//------------------------------------------------------------------------
template <typename _ForwardIterator, typename _OutputIterator>
_OutputIterator
__brick_uninitialized_move(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
/*vector=*/std::false_type) noexcept
{
using _ValueType = typename std::iterator_traits<_OutputIterator>::value_type;
for (; __first != __last; ++__first, (void) ++__result)
{
::new (std::addressof(*__result)) _ValueType(std::move(*__first));
}
return __result;
}
template <typename _RandomAccessIterator, typename _OutputIterator>
_OutputIterator
__brick_uninitialized_move(_RandomAccessIterator __first, _RandomAccessIterator __last, _OutputIterator __result,
/*vector=*/std::true_type) noexcept
{
using __ValueType = typename std::iterator_traits<_OutputIterator>::value_type;
using _ReferenceType1 = typename std::iterator_traits<_RandomAccessIterator>::reference;
using _ReferenceType2 = typename std::iterator_traits<_OutputIterator>::reference;
return __unseq_backend::__simd_walk_2(
__first, __last - __first, __result,
[](_ReferenceType1 __x, _ReferenceType2 __y) { ::new (std::addressof(__y)) __ValueType(std::move(__x)); });
}
template <typename _Iterator>
void
__brick_destroy(_Iterator __first, _Iterator __last, /*vector*/ std::false_type) noexcept
{
using _ValueType = typename std::iterator_traits<_Iterator>::value_type;
for (; __first != __last; ++__first)
__first->~_ValueType();
}
template <typename _RandomAccessIterator>
void
__brick_destroy(_RandomAccessIterator __first, _RandomAccessIterator __last, /*vector*/ std::true_type) noexcept
{
using _ValueType = typename std::iterator_traits<_RandomAccessIterator>::value_type;
using _ReferenceType = typename std::iterator_traits<_RandomAccessIterator>::reference;
__unseq_backend::__simd_walk_1(__first, __last - __first, [](_ReferenceType __x) { __x.~_ValueType(); });
}
//------------------------------------------------------------------------
// uninitialized copy
//------------------------------------------------------------------------
template <typename _ForwardIterator, typename _OutputIterator>
_OutputIterator
__brick_uninitialized_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
/*vector=*/std::false_type) noexcept
{
using _ValueType = typename std::iterator_traits<_OutputIterator>::value_type;
for (; __first != __last; ++__first, (void) ++__result)
{
::new (std::addressof(*__result)) _ValueType(*__first);
}
return __result;
}
template <typename _RandomAccessIterator, typename _OutputIterator>
_OutputIterator
__brick_uninitialized_copy(_RandomAccessIterator __first, _RandomAccessIterator __last, _OutputIterator __result,
/*vector=*/std::true_type) noexcept
{
using __ValueType = typename std::iterator_traits<_OutputIterator>::value_type;
using _ReferenceType1 = typename std::iterator_traits<_RandomAccessIterator>::reference;
using _ReferenceType2 = typename std::iterator_traits<_OutputIterator>::reference;
return __unseq_backend::__simd_walk_2(
__first, __last - __first, __result,
[](_ReferenceType1 __x, _ReferenceType2 __y) { ::new (std::addressof(__y)) __ValueType(__x); });
}
} // namespace __internal
} // namespace __pstl
#endif /* _PSTL_MEMORY_IMPL_H */