Skip to content

Commit

Permalink
[MISC] Add workaround for bogus gcc 12.1 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed May 17, 2022
1 parent 92ee7cc commit 030faeb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
11 changes: 11 additions & 0 deletions include/seqan3/core/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@
# endif
#endif

/*!\brief Workaround bogus memcpy errors in GCC 12.1. (Wrestrict and Wstringop-overflow)
* \see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105545
*/
#ifndef SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
# if defined(__GNUC__) && (__GNUC__ == 12 && __GNUC_MINOR__ < 2)
# define SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY 1
# else
# define SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY 0
# endif
#endif

/*!\brief gcc only: Constrain friend declarations to limit access to internals.
*
* \details
Expand Down
7 changes: 7 additions & 0 deletions include/seqan3/utility/container/small_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,14 @@ class small_vector
for (size_type i = sz + length - 1; i > pos_as_num + length - 1; --i)
data_[i] = data_[i - length];

#if SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif // SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
std::ranges::copy(begin_it, end_it, &data_[pos_as_num]);
#if SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
#pragma GCC diagnostic pop
#endif // SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
sz += length;
return begin() + pos_as_num;
}
Expand Down
21 changes: 21 additions & 0 deletions test/unit/alphabet/container/container_concept_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,20 @@ TEST(container, sequence_container_former_travis_bug)
s.insert(0, 1, 'E');
EXPECT_EQ("Exmplr", s);

#if SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wrestrict"
#endif // SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
// insert(size_type index, const char* s)
s.insert(2, "e");
EXPECT_EQ("Exemplr", s);

// insert(size_type index, string const& str)
s.insert(6, "a"s);
EXPECT_EQ("Exemplar", s);
#if SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
#pragma GCC diagnostic pop
#endif // SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY

// insert(size_type index, string const& str, size_type index_str, size_type count)
s.insert(8, " is an example string."s, 0, 14);
Expand All @@ -96,9 +103,16 @@ TEST(container, sequence_container_former_travis_bug)
EXPECT_EQ("Exemplar is an:== example string", s);
}

#if SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wrestrict"
#endif // SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
// insert(const_iterator pos, std::initializer_list<char>)
s.insert(s.begin() + s.find_first_of('g') + 1, { '.' });
EXPECT_EQ("Exemplar is an:== example string.", s);
#if SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
#pragma GCC diagnostic pop
#endif // SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
#else // ^^^ workaround / no workaround vvv
// insert(const_iterator pos, char ch)
s.insert(s.cbegin() + s.find_first_of('n') + 1, ':');
Expand All @@ -117,8 +131,15 @@ TEST(container, sequence_container_former_travis_bug)
}

// insert(const_iterator pos, std::initializer_list<char>)
#if SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wrestrict"
#endif // SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
s.insert(s.cbegin() + s.find_first_of('g') + 1, { '.' });
EXPECT_EQ("Exemplar is an:== example string.", s);
#if SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
#pragma GCC diagnostic pop
#endif // SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
#endif // SEQAN3_WORKAROUND_GCC_NO_CXX11_ABI
}

Expand Down
19 changes: 11 additions & 8 deletions test/unit/search/helper_search_scheme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ inline void get_ordered_search(auto const & search, auto const & blocks_length,
}

// Helper function for search_error_distribution(res, search).
inline void search_error_distribution(std::vector<std::vector<uint8_t> > & res, auto l, auto u, uint8_t const e)
template <typename t>
void search_error_distribution(std::vector<std::vector<t>> & res, auto l, auto u, uint8_t const e)
{
if (l.size() == 0)
{
res.emplace_back(std::forward<std::vector<uint8_t>>(std::vector<uint8_t>{}));
res.emplace_back(std::forward<std::vector<t>>(std::vector<t>{}));
return;
}

Expand All @@ -58,7 +59,7 @@ inline void search_error_distribution(std::vector<std::vector<uint8_t> > & res,

for (uint8_t i = std::max(e, l0); i <= u0; ++i)
{
std::vector<std::vector<uint8_t> > res_recursive;
std::vector<std::vector<t>> res_recursive;
search_error_distribution(res_recursive, l, u, i);
for (auto & res_elem : res_recursive)
{
Expand All @@ -70,21 +71,23 @@ inline void search_error_distribution(std::vector<std::vector<uint8_t> > & res,

// Compute all possible error distributions given a search.
// The result is in the same order as the search (i.e. search.pi).
inline void search_error_distribution(std::vector<std::vector<uint8_t> > & res, auto const & search)
template <typename t>
void search_error_distribution(std::vector<std::vector<t>> & res, auto const & search)
{
res.clear();
std::vector<uint8_t> l(search.l.begin(), search.l.end());
std::vector<uint8_t> u(search.u.begin(), search.u.end());
std::vector<t> l(search.l.begin(), search.l.end());
std::vector<t> u(search.u.begin(), search.u.end());
search_error_distribution(res, l, u, 0u);
}

// Compute all possible error distributions for each search given a search scheme.
inline void search_scheme_error_distribution(std::vector<std::vector<uint8_t> > & res, auto const & search_scheme)
template <typename t>
void search_scheme_error_distribution(std::vector<std::vector<t>> & res, auto const & search_scheme)
{
res.clear();
for (auto && search : search_scheme)
{
std::vector<std::vector<uint8_t> > res_search;
std::vector<std::vector<t>> res_search;
search_error_distribution(res_search, search);
for (auto & single_error_distribution : res_search)
order_search_vector(single_error_distribution, search);
Expand Down
12 changes: 9 additions & 3 deletions test/unit/search/search_scheme_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

#include <gtest/gtest.h>

#if SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY
using integral_t = uint16_t;
#else
using integral_t = uint8_t;
#endif // SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY

template <uint8_t min_error, uint8_t max_error, bool precomputed_scheme>
void error_distributions(auto & expected, auto & actual)
{
Expand All @@ -39,7 +45,7 @@ void error_distributions(auto & expected, auto & actual)

TEST(search_scheme_test, error_distribution_coverage_optimum_search_schemes)
{
std::vector<std::vector<uint8_t> > expected, actual;
std::vector<std::vector<integral_t>> expected, actual;

error_distributions<0, 0, true>(expected, actual);
EXPECT_EQ(actual, expected);
Expand Down Expand Up @@ -74,7 +80,7 @@ TEST(search_scheme_test, error_distribution_coverage_optimum_search_schemes)

TEST(search_scheme_test, error_distribution_coverage_computed_search_schemes)
{
std::vector<std::vector<uint8_t> > expected, actual;
std::vector<std::vector<integral_t>> expected, actual;

error_distributions<0, 0, false>(expected, actual);
EXPECT_EQ(actual, expected);
Expand Down Expand Up @@ -117,7 +123,7 @@ TEST(search_scheme_test, error_distribution_coverage_computed_search_schemes)
template <uint8_t min_error, uint8_t max_error, bool precomputed_scheme>
bool check_disjoint_search_scheme()
{
std::vector<std::vector<uint8_t> > error_distributions;
std::vector<std::vector<integral_t> > error_distributions;

auto const & oss{seqan3::detail::optimum_search_scheme<min_error, max_error>};
seqan3::search_scheme_error_distribution(error_distributions, oss);
Expand Down

0 comments on commit 030faeb

Please sign in to comment.