Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36b8d02

Browse files
MikeDvorskiyldionne
authored andcommitted
[pstl] A hot fix for exclusive_scan (+ lost enable_if in declaration)
It fixes an ambiguity issue in case of a user has a custom policy and calls a version of exclusive_scan with binary operation. Differential Revision: https://reviews.llvm.org/D62719
1 parent c48442c commit 36b8d02

3 files changed

Lines changed: 52 additions & 6 deletions

File tree

pstl/include/pstl/internal/glue_numeric_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIte
6060
_ForwardIterator2 __result, _Tp __init);
6161

6262
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
63-
_ForwardIterator2
63+
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
6464
exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
6565
_ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op);
6666

pstl/include/pstl/internal/glue_numeric_impl.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,25 @@ __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardItera
101101
exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
102102
_ForwardIterator2 __result, _Tp __init)
103103
{
104-
return transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __init,
105-
std::plus<_Tp>(), __pstl::__internal::__no_op());
104+
using namespace __pstl;
105+
return __internal::__pattern_transform_scan(
106+
std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __pstl::__internal::__no_op(), __init,
107+
std::plus<_Tp>(), /*inclusive=*/std::false_type(),
108+
__internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2>(__exec),
109+
__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2>(__exec));
106110
}
107111

108112
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
109-
_ForwardIterator2
113+
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
110114
exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
111115
_ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op)
112116
{
113-
return transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __init,
114-
__binary_op, __pstl::__internal::__no_op());
117+
using namespace __pstl;
118+
return __internal::__pattern_transform_scan(
119+
std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __pstl::__internal::__no_op(), __init,
120+
__binary_op, /*inclusive=*/std::false_type(),
121+
__internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2>(__exec),
122+
__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2>(__exec));
115123
}
116124

117125
// [inclusive.scan]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// -*- C++ -*-
2+
//===-- scan.fail.cpp -----------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
// UNSUPPORTED: c++98, c++03, c++11, c++14
11+
12+
#include <execution>
13+
#include <numeric>
14+
15+
struct CustomPolicy
16+
{
17+
constexpr std::false_type
18+
__allow_vector()
19+
{
20+
return std::false_type{};
21+
}
22+
constexpr std::false_type
23+
__allow_parallel()
24+
{
25+
return std::false_type{};
26+
}
27+
} policy;
28+
29+
int32_t
30+
main()
31+
{
32+
int *first = nullptr, *last = nullptr, *result = nullptr;
33+
34+
std::exclusive_scan(policy, first, last, result, 0); // expected-error {{no matching function for call to 'exclusive_scan'}}
35+
std::exclusive_scan(policy, first, last, result, 0, std::plus<int>()); // expected-error {{no matching function for call to 'exclusive_scan'}}
36+
37+
return 0;
38+
}

0 commit comments

Comments
 (0)