Skip to content

Commit

Permalink
fix new compiler warnings in gcc13 and clang18
Browse files Browse the repository at this point in the history
  • Loading branch information
hurchalla committed Mar 11, 2024
1 parent 249677b commit 8c631e3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
21 changes: 15 additions & 6 deletions build_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# This is a working convenience script for invoking the testing builds and then
# running the tests.
# The syntax is
# ./build_tests [-c<compiler_name>] [-r] [-a] [-u] [-t] [-m<Release|Debug|Profile>]
# ./build_tests [-c<compiler_name>] [-r] [-a] [-u] [-t] [-m<Release|Debug|Profile>] [-l<standard_library_name>]
#
# -c allows you to select the compiler, rather than using the default.
# -r specifies to run all tests after the build. Without -r, no tests will run.
Expand All @@ -25,6 +25,7 @@
# repository. Without -t, only tests for this repository will be compiled.
# -m allows you to choose between Release, Debug, and Profile(Release with
# debug symbols) build configurations, rather than using the default.
# -l allows you to choose between either libstdc++ or libc++ when using clang.
#
# Currently it supports clang, gcc, and icc but you'll need to customize the
# section under "#Compiler commands" to match the compilers on your system. The
Expand Down Expand Up @@ -167,12 +168,12 @@



while getopts ":m:c:h-:raut" opt; do
while getopts ":m:l:c:h-:raut" opt; do
case $opt in
h)
;&
-)
echo "Usage: build_tests [-c<compiler_name>] [-r] [-a] [-u] [-t] [-m<Release|Debug|Profile>]" >&2
echo "Usage: build_tests [-c<compiler_name>] [-r] [-a] [-u] [-t] [-m<Release|Debug|Profile>] [-l<standard_library_name>]" >&2
exit 1
;;
c)
Expand All @@ -181,6 +182,9 @@ while getopts ":m:c:h-:raut" opt; do
m)
mode=$OPTARG
;;
l)
library=$OPTARG
;;
r)
run_tests=true
;;
Expand Down Expand Up @@ -212,6 +216,10 @@ if [ -z "$mode" ]; then
mode=Debug
fi

if [ -n "$library" ]; then
cpp_stdlib="-stdlib=$library"
fi


# Compiler commands
if [ "${compiler,,}" = "gcc" ] || [ "${compiler,,}" = "g++" ]; then
Expand Down Expand Up @@ -506,7 +514,7 @@ if [ "${mode,,}" = "release" ]; then
-DBENCH_HURCHALLA_FACTORING=ON \
$test_all_hurchalla_libs \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="$cpp_standard \
-DCMAKE_CXX_FLAGS="$cpp_standard $cpp_stdlib \
$use_inline_asm $use_all_inline_asm \
$gcc_static_analysis" "${clang_static_analysis[@]}" \
$cmake_cpp_compiler $cmake_c_compiler
Expand All @@ -522,7 +530,8 @@ elif [ "${mode,,}" = "debug" ]; then
$test_all_hurchalla_libs \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXE_LINKER_FLAGS="$clang_ubsan_link_flags" \
-DCMAKE_CXX_FLAGS="$cpp_standard $clang_ubsan $gcc_ubsan \
-DCMAKE_CXX_FLAGS="$cpp_standard $cpp_stdlib \
$clang_ubsan $gcc_ubsan \
$use_inline_asm $use_all_inline_asm \
$gcc_static_analysis" "${clang_static_analysis[@]}" \
$cmake_cpp_compiler $cmake_c_compiler
Expand All @@ -538,7 +547,7 @@ elif [ "${mode,,}" = "profile" ]; then
$test_all_hurchalla_libs \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_EXE_LINKER_FLAGS="-ldl" \
-DCMAKE_CXX_FLAGS="$cpp_standard \
-DCMAKE_CXX_FLAGS="$cpp_standard $cpp_stdlib \
$use_inline_asm $use_all_inline_asm" \
$cmake_cpp_compiler $cmake_c_compiler
exit_on_failure
Expand Down
1 change: 1 addition & 0 deletions include/hurchalla/factoring/detail/is_prime_miller_rabin.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#endif
#ifdef __clang__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunknown-warning-option"
# pragma GCC diagnostic ignored "-Wbitwise-instead-of-logical"
#endif

Expand Down
14 changes: 14 additions & 0 deletions test/detail_tests/test_factorize_wheel210.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,24 @@ void test_factor_wheel210(T x, const std::vector<T>& answer)
FactorArrayAdapter faa(arr);
factorize_wheel210::call(std::back_inserter(faa), x);
auto num_factors = faa.size();
EXPECT_TRUE(num_factors <= arr.size());
EXPECT_TRUE(num_factors == answer.size());

#if !defined(__GNUC__) || defined(__clang__)
// gcc10 appears to have a compiler bug, claiming that when we are called by
// TEST(...basic_tests_8), the line below for std::sort accesses the array
// out of bounds. It's a compile-time warning/error with gcc10. I can find
// no problem in the code, and the run-time test above for
// (num_factors <= arr.size()) doesn't fail in any compiler.
// --- Therefore we provide an alternate #else for gcc ---
std::sort(arr.begin(), arr.begin()+num_factors);
EXPECT_TRUE(std::equal(arr.begin(), arr.begin()+num_factors,
answer.begin()));
#else
std::vector<T> tmp(arr.begin(), arr.begin()+num_factors);
std::sort(tmp.begin(), tmp.end());
EXPECT_TRUE(tmp == answer);
#endif
}


Expand Down
9 changes: 9 additions & 0 deletions test/detail_tests/test_is_prime_miller_rabin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ TEST(HurchallaFactoringIsPrimeMillerRabin, exhaustive_uint16_t) {
}
#endif


#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic warning "-Wstrict-overflow=2"
#endif
TEST(HurchallaFactoringIsPrimeMillerRabin, basic_test1) {
using T = std::uint32_t;
T modulus = 127;
Expand All @@ -90,6 +95,10 @@ TEST(HurchallaFactoringIsPrimeMillerRabin, basic_test1) {
EXPECT_TRUE(is_prime_miller_rabin::call(mFR));
EXPECT_TRUE(is_prime_miller_rabin::call(mQR));
}
#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif


TEST(HurchallaFactoringIsPrimeMillerRabin, basic_test2) {
using T = std::uint32_t;
Expand Down

0 comments on commit 8c631e3

Please sign in to comment.