From 0edac0d32bb46271e865db0524c4b1b09cf486eb Mon Sep 17 00:00:00 2001 From: Lucas Czech Date: Tue, 12 Nov 2024 17:20:30 +0100 Subject: [PATCH] Various CI compiler fixes --- lib/genesis/taxonomy/functions/kmer.cpp | 6 +++++- lib/genesis/utils/core/std.hpp | 11 +++++++++-- lib/genesis/utils/io/parser.cpp | 3 +++ lib/genesis/utils/math/bit.hpp | 14 ++++++++++++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/genesis/taxonomy/functions/kmer.cpp b/lib/genesis/taxonomy/functions/kmer.cpp index d2e5d62c..c4ddf2cc 100644 --- a/lib/genesis/taxonomy/functions/kmer.cpp +++ b/lib/genesis/taxonomy/functions/kmer.cpp @@ -125,7 +125,7 @@ void assign_children_to_group_( ) { // Get the data and assert that we are in the right type of taxon auto& data = taxon.data(); - assert( data.group_status = KmerTaxonData::GroupStatus::kAssigned ); + assert( data.group_status == KmerTaxonData::GroupStatus::kAssigned ); assert( data.group_index != std::numeric_limits::max() ); // In some previous iteration of the procedur, we already decided that this taxon here is @@ -299,6 +299,10 @@ size_t group_with_target_number_of_groups( TaxonGroupingSearchParams const& para // in which case we cannot get any closer to our target number of groups. while( true ) { + // The current limit always is in between the low and high + assert( limit_l <= limit_c ); + assert( limit_c <= limit_h ); + // Construct groups with the current limits. // Depending on whether the given params want us to modify the number of sequences, // or their total combined length per group, we set the internal "limit" here, which can diff --git a/lib/genesis/utils/core/std.hpp b/lib/genesis/utils/core/std.hpp index 11eb3aad..99beaf8f 100644 --- a/lib/genesis/utils/core/std.hpp +++ b/lib/genesis/utils/core/std.hpp @@ -227,6 +227,11 @@ struct genesis_invoke_result // container traits // ------------------------------------------------------------------------- +// Implement void_t for C++11. +// We are not using the C++17 version here, for simplicity. +template +using void_t = void; + template struct is_container : std::false_type {}; @@ -236,7 +241,7 @@ struct is_container : std::false_type {}; */ template struct is_container< - T, std::void_t< + T, void_t< typename T::value_type, decltype(std::declval().begin()), decltype(std::declval().end()) @@ -252,7 +257,9 @@ template struct has_reserve : std::false_type {}; template -struct has_reserve().reserve(std::declval()))>> : std::true_type {}; +struct has_reserve< + T, void_t().reserve(std::declval()))> +> : std::true_type {}; // Convenience variable template for has_reserve trait template diff --git a/lib/genesis/utils/io/parser.cpp b/lib/genesis/utils/io/parser.cpp index 7f67335b..27a9bed4 100644 --- a/lib/genesis/utils/io/parser.cpp +++ b/lib/genesis/utils/io/parser.cpp @@ -266,6 +266,9 @@ size_t parse_unsigned_integer_from_chars_( utils::InputStream& source ) using namespace utils; T x = 0; + // If we want to use __builtin_mul_overflow here, we should check its existence first, + // using __has_builtin first. See genesis/utils/math/bit.hpp for examples. + // Hardcoded base 10. See below for other version that allows to select base. auto raise_and_add_ = []( T& val, unsigned char c ) { return !( diff --git a/lib/genesis/utils/math/bit.hpp b/lib/genesis/utils/math/bit.hpp index b585b168..b6c6a8ce 100644 --- a/lib/genesis/utils/math/bit.hpp +++ b/lib/genesis/utils/math/bit.hpp @@ -57,12 +57,20 @@ namespace utils { // Pop Count // ================================================================================================ +// Following the preprocessor documentation for __has_builtin +// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fbuiltin.html +#ifdef __has_builtin +# if __has_builtin(__builtin_popcount) && __has_builtin(__builtin_popcountl) && __has_builtin(__builtin_popcountll) +# define GENESIS_HAS_BUILTIN_POPCOUNT +# endif +#endif + /** * @brief Compute the pop count (Hamming weight) of an unsigned int. */ template inline -#if defined(__cpp_lib_bitops) || (defined(__has_builtin) && __has_builtin(__builtin_popcountll)) +#if defined(__cpp_lib_bitops) || defined(GENESIS_HAS_BUILTIN_POPCOUNT) constexpr #endif typename std::enable_if::value, uint64_t>::type @@ -75,7 +83,7 @@ pop_count( T n ) // https://en.cppreference.com/w/cpp/numeric/popcount return std::popcount(n); - #elif defined(__has_builtin) && __has_builtin(__builtin_popcountll) + #elif defined(GENESIS_HAS_BUILTIN_POPCOUNT) // Otherwise, use GCC/Clang intrinsic if available. if (sizeof(T) <= sizeof(unsigned int)) { @@ -112,6 +120,8 @@ pop_count( T n ) #endif } +#undef GENESIS_HAS_BUILTIN_POPCOUNT + // ================================================================================================ // Bit Extract // ================================================================================================