This fixes a conflict between how Parallel Mode has always used the _GLIBCXX_ASSERTIONS macro and the new meaning we gave it for GCC 6 (enabling the lightweight debug checks).
It doesn't make sense for Parallel Mode to own that macro, and it might be useful to enable Parallel Mode assertions without the other checks, so I've changed all the Parallel Mode headers to check _GLIBCXX_PARALLEL_ASSERTIONS instead. If that's not defined then it defaults to the value of _GLIBCXX_ASSERTIONS, to preserve the old behaviour. PR libstdc++/71856 * include/bits/c++config (_GLIBCXX_ASSERTIONS): Define to 1 not empty. * include/parallel/compiletime_settings.h (_GLIBCXX_ASSERTIONS): Rename to _GLIBCXX_PARALLEL_ASSERTIONS and make default value depend on _GLIBCXX_ASSERTIONS. * include/parallel/balanced_quicksort.h: Rename _GLIBCXX_ASSERTIONS. Include <unistd.h> for sleep. * include/parallel/losertree.h: Rename _GLIBCXX_ASSERTIONS. * include/parallel/merge.h: Likewise. * include/parallel/multiway_merge.h: Likewise. * include/parallel/partition.h: Likewise. * include/parallel/queue.h: Likewise. * include/parallel/sort.h: Likewise. * testsuite/25_algorithms/headers/algorithm/ parallel_algorithm_assert.cc: New.
commit 530690e778b4257f6e52ef1199d536dbd392e4ba Author: redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Wed Jul 13 17:22:57 2016 +0000 libstdc++/71856 Define _GLIBCXX_PARALLEL_ASSERTIONS PR libstdc++/71856 * include/bits/c++config (_GLIBCXX_ASSERTIONS): Define to 1 not empty. * include/parallel/compiletime_settings.h (_GLIBCXX_ASSERTIONS): Rename to _GLIBCXX_PARALLEL_ASSERTIONS and make default value depend on _GLIBCXX_ASSERTIONS. * include/parallel/balanced_quicksort.h: Rename _GLIBCXX_ASSERTIONS. Include <unistd.h> for sleep. * include/parallel/losertree.h: Rename _GLIBCXX_ASSERTIONS. * include/parallel/merge.h: Likewise. * include/parallel/multiway_merge.h: Likewise. * include/parallel/partition.h: Likewise. * include/parallel/queue.h: Likewise. * include/parallel/sort.h: Likewise. * testsuite/25_algorithms/headers/algorithm/ parallel_algorithm_assert.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@238307 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index 57024e4..4625607 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -414,7 +414,7 @@ namespace std // Debug Mode implies checking assertions. #ifdef _GLIBCXX_DEBUG -# define _GLIBCXX_ASSERTIONS +# define _GLIBCXX_ASSERTIONS 1 #endif // Disable std::string explicit instantiation declarations in order to assert. diff --git a/libstdc++-v3/include/parallel/balanced_quicksort.h b/libstdc++-v3/include/parallel/balanced_quicksort.h index 65dec30..9d09ed2 100644 --- a/libstdc++-v3/include/parallel/balanced_quicksort.h +++ b/libstdc++-v3/include/parallel/balanced_quicksort.h @@ -51,8 +51,11 @@ #include <parallel/random_number.h> #include <parallel/queue.h> -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS #include <parallel/checkers.h> +#ifdef _GLIBCXX_HAVE_UNISTD_H +#include <unistd.h> +#endif #endif namespace __gnu_parallel @@ -110,7 +113,7 @@ namespace __gnu_parallel __median_of_three_iterators(__begin, __begin + (__end - __begin) / 2, __end - 1, __comp); -#if defined(_GLIBCXX_ASSERTIONS) +#if defined(_GLIBCXX_PARALLEL_ASSERTIONS) // Must be in between somewhere. _DifferenceType __n = __end - __begin; @@ -147,7 +150,7 @@ namespace __gnu_parallel std::iter_swap(__begin + __split_pos, __pivot_pos); __pivot_pos = __begin + __split_pos; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _RAIter __r; for (__r = __begin; __r != __pivot_pos; ++__r) _GLIBCXX_PARALLEL_ASSERT(__comp(*__r, *__pivot_pos)); @@ -194,7 +197,7 @@ namespace __gnu_parallel _DifferenceType __split_pos = __qsb_divide(__begin, __end, __comp, __num_threads); -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT(0 <= __split_pos && __split_pos < (__end - __begin)); #endif @@ -267,7 +270,7 @@ namespace __gnu_parallel _Piece __current = __tl._M_initial; _DifferenceType __elements_done = 0; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _DifferenceType __total_elements_done = 0; #endif @@ -297,7 +300,7 @@ namespace __gnu_parallel __pred); // Left side: < __pivot_pos; __right side: >= __pivot_pos. -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT(__begin <= __split_pos1 && __split_pos1 < __end); #endif @@ -328,7 +331,7 @@ namespace __gnu_parallel // Elements equal to pivot are done. __elements_done += (__split_pos2 - __split_pos1); -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS __total_elements_done += (__split_pos2 - __split_pos1); #endif // Always push larger part onto stack. @@ -359,7 +362,7 @@ namespace __gnu_parallel { __gnu_sequential::sort(__begin, __end, __comp); __elements_done += __n; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS __total_elements_done += __n; #endif @@ -372,7 +375,7 @@ namespace __gnu_parallel __elements_done = 0; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS double __search_start = omp_get_wtime(); #endif @@ -380,7 +383,7 @@ namespace __gnu_parallel bool __successfully_stolen = false; while (__wait && *__tl._M_elements_leftover > 0 && !__successfully_stolen -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // Possible dead-lock. && (omp_get_wtime() < (__search_start + 1.0)) #endif @@ -399,7 +402,7 @@ namespace __gnu_parallel #endif } -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS if (omp_get_wtime() >= (__search_start + 1.0)) { sleep(1); @@ -409,7 +412,7 @@ namespace __gnu_parallel #endif if (!__successfully_stolen) { -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT(*__tl._M_elements_leftover == 0); #endif return; @@ -475,7 +478,7 @@ namespace __gnu_parallel __qsb_conquer(__tls, __begin, __begin + __n, __comp, 0, __num_threads, true); -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // All stack must be empty. _Piece __dummy; for (_ThreadIndex __i = 1; __i < __num_threads; ++__i) diff --git a/libstdc++-v3/include/parallel/compiletime_settings.h b/libstdc++-v3/include/parallel/compiletime_settings.h index f4fb404..47f0a59 100644 --- a/libstdc++-v3/include/parallel/compiletime_settings.h +++ b/libstdc++-v3/include/parallel/compiletime_settings.h @@ -55,10 +55,10 @@ #define _GLIBCXX_SCALE_DOWN_FPU 0 #endif -#ifndef _GLIBCXX_ASSERTIONS +#ifndef _GLIBCXX_PARALLEL_ASSERTIONS /** @brief Switch on many _GLIBCXX_PARALLEL_ASSERTions in parallel code. * Should be switched on only locally. */ -#define _GLIBCXX_ASSERTIONS 0 +#define _GLIBCXX_PARALLEL_ASSERTIONS (_GLIBCXX_ASSERTIONS+0) #endif #ifndef _GLIBCXX_RANDOM_SHUFFLE_CONSIDER_L1 diff --git a/libstdc++-v3/include/parallel/losertree.h b/libstdc++-v3/include/parallel/losertree.h index 7b4bb44..f1ee128 100644 --- a/libstdc++-v3/include/parallel/losertree.h +++ b/libstdc++-v3/include/parallel/losertree.h @@ -222,7 +222,7 @@ namespace __gnu_parallel __delete_min_insert(_Tp __key, bool __sup) { using std::swap; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top! _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); #endif @@ -324,7 +324,7 @@ namespace __gnu_parallel __delete_min_insert(_Tp __key, bool __sup) { using std::swap; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top! _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); #endif @@ -451,7 +451,7 @@ namespace __gnu_parallel void __delete_min_insert(const _Tp& __key, bool __sup) { -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top! _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); #endif @@ -533,7 +533,7 @@ namespace __gnu_parallel void __delete_min_insert(const _Tp& __key, bool __sup) { -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top! _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); #endif @@ -620,7 +620,7 @@ namespace __gnu_parallel int __get_min_source() { -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top! _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); #endif @@ -687,7 +687,7 @@ namespace __gnu_parallel { _M_losers[0] = _M_losers[__init_winner(1)]; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top at the beginning // (0 sequences!) _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); @@ -700,7 +700,7 @@ namespace __gnu_parallel __delete_min_insert(_Tp __key, bool) { using std::swap; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top! _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); #endif @@ -755,7 +755,7 @@ namespace __gnu_parallel unsigned int __left = __init_winner(2 * __root); unsigned int __right = __init_winner(2 * __root + 1); -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // If __left one is sentinel then __right one must be, too. if (_M_losers[__left]._M_source == -1) _GLIBCXX_PARALLEL_ASSERT(_M_losers[__right]._M_source == -1); @@ -782,7 +782,7 @@ namespace __gnu_parallel { _M_losers[0] = _M_losers[__init_winner(1)]; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top at the beginning // (0 sequences!) _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); @@ -795,7 +795,7 @@ namespace __gnu_parallel __delete_min_insert(_Tp __key, bool) { using std::swap; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top! _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); #endif @@ -865,7 +865,7 @@ namespace __gnu_parallel int __get_min_source() { -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top! _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); #endif @@ -932,7 +932,7 @@ namespace __gnu_parallel { _M_losers[0] = _M_losers[__init_winner(1)]; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top at the beginning // (0 sequences!) _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); @@ -942,7 +942,7 @@ namespace __gnu_parallel void __delete_min_insert(const _Tp& __key, bool __sup) { -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top! _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); #endif @@ -998,7 +998,7 @@ namespace __gnu_parallel unsigned int __left = __init_winner(2 * __root); unsigned int __right = __init_winner(2 * __root + 1); -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // If __left one is sentinel then __right one must be, too. if (_M_losers[__left]._M_source == -1) _GLIBCXX_PARALLEL_ASSERT(_M_losers[__right]._M_source == -1); @@ -1025,7 +1025,7 @@ namespace __gnu_parallel { _M_losers[0] = _M_losers[__init_winner(1)]; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top at the beginning // (0 sequences!) _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); @@ -1035,7 +1035,7 @@ namespace __gnu_parallel void __delete_min_insert(const _Tp& __key, bool __sup) { -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // no dummy sequence can ever be at the top! _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1); #endif diff --git a/libstdc++-v3/include/parallel/merge.h b/libstdc++-v3/include/parallel/merge.h index c240a52..717054f 100644 --- a/libstdc++-v3/include/parallel/merge.h +++ b/libstdc++-v3/include/parallel/merge.h @@ -113,7 +113,7 @@ namespace __gnu_parallel typedef typename std::iterator_traits<_RAIter2>::value_type _ValueType2; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT(__max_length >= 0); #endif diff --git a/libstdc++-v3/include/parallel/multiway_merge.h b/libstdc++-v3/include/parallel/multiway_merge.h index bb7b218..9e9fdf8 100644 --- a/libstdc++-v3/include/parallel/multiway_merge.h +++ b/libstdc++-v3/include/parallel/multiway_merge.h @@ -46,7 +46,7 @@ #include <parallel/parallel.h> #include <parallel/losertree.h> #include <parallel/multiseq_selection.h> -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS #include <parallel/checkers.h> #endif @@ -256,7 +256,7 @@ namespace __gnu_parallel if (__length == 0) return __target; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _DifferenceTp __orig_length = __length; #endif @@ -310,7 +310,7 @@ namespace __gnu_parallel __finish: ; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT( ((_RAIter1)__seq0 - __seqs_begin[0].first) + ((_RAIter1)__seq1 - __seqs_begin[1].first) + @@ -597,7 +597,7 @@ namespace __gnu_parallel for (_SeqNumber __t = 0; __t < __k; ++__t) { -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT(__seqs_begin[__t].first != __seqs_begin[__t].second); #endif @@ -608,7 +608,7 @@ namespace __gnu_parallel _SeqNumber __source; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _DifferenceType __i = 0; #endif @@ -618,7 +618,7 @@ namespace __gnu_parallel // Take out. __source = __lt.__get_min_source(); -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT(0 <= __source && __source < __k); _GLIBCXX_PARALLEL_ASSERT(__i == 0 || !__comp(*(__seqs_begin[__source].first), *(__target - 1))); @@ -627,7 +627,7 @@ namespace __gnu_parallel // Feed. *(__target++) = *(__seqs_begin[__source].first++); -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS ++__i; #endif // Replace from same __source. @@ -690,7 +690,7 @@ namespace __gnu_parallel __target_end = multiway_merge_loser_tree_unguarded<UnguardedLoserTree> (__seqs_begin, __seqs_end, __target, __sentinel, __length, __comp); -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT(__target_end == __target + __length); _GLIBCXX_PARALLEL_ASSERT(__is_sorted(__target, __target_end, __comp)); #endif @@ -936,7 +936,7 @@ namespace __gnu_parallel typedef typename std::iterator_traits<_RAIter1>::value_type _ValueType; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS for (_RAIterIterator __s = __seqs_begin; __s != __seqs_end; ++__s) { _GLIBCXX_PARALLEL_ASSERT(__is_sorted((*__s).first, @@ -990,7 +990,7 @@ namespace __gnu_parallel (__seqs_begin, __seqs_end, __target, __sentinel, __length, __comp); break; } -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT( __is_sorted(__target, __target + __length, __comp)); #endif @@ -1230,7 +1230,7 @@ namespace __gnu_parallel _Compare __comp, _ThreadIndex __num_threads) { -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT(__seqs_end - __seqs_begin > 1); #endif @@ -1318,7 +1318,7 @@ namespace __gnu_parallel delete[] __chunks; } // parallel -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT( __is_sorted(__target, __target + __length, __comp)); #endif diff --git a/libstdc++-v3/include/parallel/partition.h b/libstdc++-v3/include/parallel/partition.h index d3ca65b..16dadf5 100644 --- a/libstdc++-v3/include/parallel/partition.h +++ b/libstdc++-v3/include/parallel/partition.h @@ -234,7 +234,7 @@ namespace __gnu_parallel break; } -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT(__swapstart != -1); #endif @@ -257,7 +257,7 @@ namespace __gnu_parallel break; } -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS _GLIBCXX_PARALLEL_ASSERT(__swapstart != -1); #endif @@ -265,7 +265,7 @@ namespace __gnu_parallel __begin + __thread_right_border + __chunk_size, __begin + __swapstart); } -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS # pragma omp barrier # pragma omp single diff --git a/libstdc++-v3/include/parallel/queue.h b/libstdc++-v3/include/parallel/queue.h index 46fd4bf..cb525c2 100644 --- a/libstdc++-v3/include/parallel/queue.h +++ b/libstdc++-v3/include/parallel/queue.h @@ -86,7 +86,7 @@ namespace __gnu_parallel int __former_front, __former_back; __decode2(__former_borders, __former_front, __former_back); *(_M_base + __former_front % _M_max_size) = __t; -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS // Otherwise: front - back > _M_max_size eventually. _GLIBCXX_PARALLEL_ASSERT(((__former_front + 1) - __former_back) <= _M_max_size); diff --git a/libstdc++-v3/include/parallel/sort.h b/libstdc++-v3/include/parallel/sort.h index 16a7925..12cef0d 100644 --- a/libstdc++-v3/include/parallel/sort.h +++ b/libstdc++-v3/include/parallel/sort.h @@ -36,7 +36,7 @@ #include <parallel/features.h> #include <parallel/parallel.h> -#if _GLIBCXX_ASSERTIONS +#if _GLIBCXX_PARALLEL_ASSERTIONS #include <parallel/checkers.h> #endif diff --git a/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/parallel_algorithm_assert.cc b/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/parallel_algorithm_assert.cc new file mode 100644 index 0000000..b9a6016 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/parallel_algorithm_assert.cc @@ -0,0 +1,28 @@ +// { dg-do compile } +// { dg-require-parallel-mode "" } +// { dg-options "-fopenmp" { target *-*-* } } + +// Copyright (C) 2016 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#ifndef _GLIBCXX_ASSERTIONS +# define _GLIBCXX_ASSERTIONS 1 +#endif +#include <parallel/algorithm> +#ifndef _GLIBCXX_PARALLEL_ASSERTIONS +# error "_GLIBCXX_ASSERTIONS does not enable _GLIBCXX_PARALLEL_ASSERTIONS" +#endif