Skip to content

Commit

Permalink
ARROW-17567: [C++] Avoid internal compiler error with gcc 7 and c++17 (
Browse files Browse the repository at this point in the history
…apache#14004)

The current compute kernel fails to compile with gcc6/7 and c++14/17, due to a known bug of gcc. It is triggered when a const integer is capture by reference in a lambda function, and is parenthesized in that lambda code. Capturing the const ints by value fixes this issue.

See also:  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83204 and kokkos/kokkos-kernels#349

Lead-authored-by: Jin Shang <shangjin1997@gmail.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Co-authored-by: jinshang <jinshang@tencent.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
  • Loading branch information
3 people authored and fatemehp committed Oct 17, 2022
1 parent 8cd435b commit 1a2361e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cpp/src/arrow/compute/kernels/aggregate_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ enable_if_t<std::is_floating_point<SumType>::value, SumType> SumArray(

// reduce summation of one block (may be smaller than kBlockSize) from leaf node
// continue reducing to upper level if two summations are ready for non-leaf node
auto reduce = [&](SumType block_sum) {
// (capture `levels` by value because of ARROW-17567)
auto reduce = [&, levels](SumType block_sum) {
int cur_level = 0;
uint64_t cur_level_mask = 1ULL;
sum[cur_level] += block_sum;
Expand Down
13 changes: 9 additions & 4 deletions cpp/src/arrow/compute/kernels/scalar_set_lookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ struct SetLookupState : public KernelState {
auto visit_valid = [&](T v) {
const auto memo_size = static_cast<int32_t>(memo_index_to_value_index.size());
int32_t unused_memo_index;
auto on_found = [&](int32_t memo_index) { DCHECK_LT(memo_index, memo_size); };
auto on_not_found = [&](int32_t memo_index) {
// (capture `memo_size` by value because of ARROW-17567)
auto on_found = [&, memo_size](int32_t memo_index) {
DCHECK_LT(memo_index, memo_size);
};
auto on_not_found = [&, memo_size](int32_t memo_index) {
DCHECK_EQ(memo_index, memo_size);
memo_index_to_value_index.push_back(index);
};
Expand All @@ -79,8 +82,10 @@ struct SetLookupState : public KernelState {
};
auto visit_null = [&]() {
const auto memo_size = static_cast<int32_t>(memo_index_to_value_index.size());
auto on_found = [&](int32_t memo_index) { DCHECK_LT(memo_index, memo_size); };
auto on_not_found = [&](int32_t memo_index) {
auto on_found = [&, memo_size](int32_t memo_index) {
DCHECK_LT(memo_index, memo_size);
};
auto on_not_found = [&, memo_size](int32_t memo_index) {
DCHECK_EQ(memo_index, memo_size);
memo_index_to_value_index.push_back(index);
};
Expand Down

0 comments on commit 1a2361e

Please sign in to comment.