From 9aa733becb7ecda4d0b632bfbbb3cc80d8925f01 Mon Sep 17 00:00:00 2001 From: Duncan Tebbs Date: Tue, 23 Jul 2019 17:24:28 +0100 Subject: [PATCH 1/4] Fix some compile warnings --- libff/algebra/curves/edwards/edwards_g2.cpp | 2 +- libff/algebra/scalar_multiplication/multiexp.tcc | 2 ++ libff/common/profiling.cpp | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libff/algebra/curves/edwards/edwards_g2.cpp b/libff/algebra/curves/edwards/edwards_g2.cpp index feadd9f4..c0d59d5a 100755 --- a/libff/algebra/curves/edwards/edwards_g2.cpp +++ b/libff/algebra/curves/edwards/edwards_g2.cpp @@ -114,7 +114,7 @@ void edwards_G2::to_special() return; } -#ifdef DEBUG +#if defined(DEBUG) && !defined(NDEBUG) const edwards_G2 copy(*this); #endif diff --git a/libff/algebra/scalar_multiplication/multiexp.tcc b/libff/algebra/scalar_multiplication/multiexp.tcc index 0c85e2bc..69d22973 100755 --- a/libff/algebra/scalar_multiplication/multiexp.tcc +++ b/libff/algebra/scalar_multiplication/multiexp.tcc @@ -136,6 +136,7 @@ T multi_exp_inner( result = result + opt_window_wnaf_exp(*vec_it, scalar_bigint, scalar_bigint.num_bits()); } assert(scalar_it == scalar_end); + UNUSED(scalar_end); return result; } @@ -158,6 +159,7 @@ T multi_exp_inner( result = result + (*scalar_it) * (*vec_it); } assert(scalar_it == scalar_end); + UNUSED(scalar_end); return result; } diff --git a/libff/common/profiling.cpp b/libff/common/profiling.cpp index f2a19858..07fcf7df 100755 --- a/libff/common/profiling.cpp +++ b/libff/common/profiling.cpp @@ -344,6 +344,7 @@ void print_mem(const std::string &s) printf("* Peak vsize (physical memory+swap) in mebibytes (%s): %lu\n", s.c_str(), usage.vsize >> 20); } #else + UNUSED(s); printf("* Memory profiling not supported in NO_PROCPS mode\n"); #endif } From 30f50b8cff3763f19e48b4f63e06c4bfed06b0f4 Mon Sep 17 00:00:00 2001 From: Duncan Tebbs Date: Thu, 21 May 2020 10:32:12 +0100 Subject: [PATCH 2/4] Fix warnings in tests and support checks in release builds --- libff/algebra/curves/tests/test_bilinearity.cpp | 7 +++++++ libff/algebra/curves/tests/test_groups.cpp | 11 +++++++++-- libff/algebra/fields/tests/test_fields.cpp | 7 +++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libff/algebra/curves/tests/test_bilinearity.cpp b/libff/algebra/curves/tests/test_bilinearity.cpp index 963dfc55..7f706600 100755 --- a/libff/algebra/curves/tests/test_bilinearity.cpp +++ b/libff/algebra/curves/tests/test_bilinearity.cpp @@ -4,6 +4,13 @@ * and contributors (see AUTHORS). * @copyright MIT license (see LICENSE file) *****************************************************************************/ + +// If NDEBUG is defined, assert turns into nothing. No checks are made and a +// lot of warnings are generated. +#ifdef NDEBUG +# undef NDEBUG +#endif + #include #include #ifdef CURVE_BN128 diff --git a/libff/algebra/curves/tests/test_groups.cpp b/libff/algebra/curves/tests/test_groups.cpp index b2ecf585..6b5ddbc1 100755 --- a/libff/algebra/curves/tests/test_groups.cpp +++ b/libff/algebra/curves/tests/test_groups.cpp @@ -4,6 +4,13 @@ * and contributors (see AUTHORS). * @copyright MIT license (see LICENSE file) *****************************************************************************/ + +// If NDEBUG is defined, assert turns into nothing. No checks are made and a +// lot of warnings are generated. +#ifdef NDEBUG +# undef NDEBUG +#endif + #include #include #include @@ -11,10 +18,10 @@ #ifdef CURVE_BN128 #include #endif -#include - #include +#include + using namespace libff; #ifndef NDEBUG diff --git a/libff/algebra/fields/tests/test_fields.cpp b/libff/algebra/fields/tests/test_fields.cpp index 8412796f..cc327cbd 100755 --- a/libff/algebra/fields/tests/test_fields.cpp +++ b/libff/algebra/fields/tests/test_fields.cpp @@ -4,6 +4,13 @@ * and contributors (see AUTHORS). * @copyright MIT license (see LICENSE file) *****************************************************************************/ + +// If NDEBUG is defined, assert turns into nothing. No checks are made and a +// lot of warnings are generated. +#ifdef NDEBUG +# undef NDEBUG +#endif + #include #include #include From 4ee53c1a18ad9818d89527caaf9b730970208ae7 Mon Sep 17 00:00:00 2001 From: Duncan Tebbs Date: Thu, 21 May 2020 10:32:50 +0100 Subject: [PATCH 3/4] Fix compile warning and formatting in double.cpp --- libff/common/double.cpp | 168 ++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 85 deletions(-) diff --git a/libff/common/double.cpp b/libff/common/double.cpp index 6d9b93c0..49640196 100755 --- a/libff/common/double.cpp +++ b/libff/common/double.cpp @@ -19,177 +19,175 @@ namespace libff { - const double PI = 3.141592653589793238460264338328L; - - Double::Double() - { +Double::Double() +{ val = std::complex(0, 0); - } +} - Double::Double(double real) - { +Double::Double(double real) +{ val = std::complex(real, 0); - } +} - Double::Double(double real, double imag) - { +Double::Double(double real, double imag) +{ val = std::complex(real, imag); - } +} - Double::Double(std::complex num) - { +Double::Double(std::complex num) +{ val = num; - } +} - unsigned Double::add_cnt = 0; - unsigned Double::sub_cnt = 0; - unsigned Double::mul_cnt = 0; - unsigned Double::inv_cnt = 0; +unsigned Double::add_cnt = 0; +unsigned Double::sub_cnt = 0; +unsigned Double::mul_cnt = 0; +unsigned Double::inv_cnt = 0; - Double Double::operator+(const Double &other) const - { +Double Double::operator+(const Double &other) const +{ #ifdef PROFILE_OP_COUNTS ++add_cnt; #endif return Double(val + other.val); - } +} - Double Double::operator-(const Double &other) const - { +Double Double::operator-(const Double &other) const +{ #ifdef PROFILE_OP_COUNTS ++sub_cnt; #endif return Double(val - other.val); - } +} - Double Double::operator*(const Double &other) const - { +Double Double::operator*(const Double &other) const +{ #ifdef PROFILE_OP_COUNTS ++mul_cnt; #endif return Double(val * other.val); - } +} - Double Double::operator-() const - { +Double Double::operator-() const +{ if (val.imag() == 0) return Double(-val.real()); return Double(-val.real(), -val.imag()); - } +} - Double& Double::operator+=(const Double &other) - { +Double& Double::operator+=(const Double &other) +{ #ifdef PROFILE_OP_COUNTS ++add_cnt; #endif this->val = std::complex(val + other.val); return *this; - } +} - Double& Double::operator-=(const Double &other) - { +Double& Double::operator-=(const Double &other) +{ #ifdef PROFILE_OP_COUNTS ++sub_cnt; #endif this->val = std::complex(val - other.val); return *this; - } +} - Double& Double::operator*=(const Double &other) - { +Double& Double::operator*=(const Double &other) +{ #ifdef PROFILE_OP_COUNTS ++mul_cnt; #endif this->val *= std::complex(other.val); return *this; - } +} - bool Double::operator==(const Double &other) const - { +bool Double::operator==(const Double &other) const +{ return (std::abs(val.real() - other.val.real()) < 0.000001) && (std::abs(val.imag() - other.val.imag()) < 0.000001); - } +} - bool Double::operator!=(const Double &other) const - { +bool Double::operator!=(const Double &other) const +{ return Double(val) == other ? 0 : 1; - } +} - bool Double::operator<(const Double &other) const - { +bool Double::operator<(const Double &other) const +{ return (val.real() < other.val.real()); - } +} - bool Double::operator>(const Double &other) const - { +bool Double::operator>(const Double &other) const +{ return (val.real() > other.val.real()); - } +} - Double Double::operator^(const libff::bigint<1> power) const - { +Double Double::operator^(const libff::bigint<1> power) const +{ return Double(pow(val, power.as_ulong())); - } +} - Double Double::operator^(const size_t power) const - { +Double Double::operator^(const size_t power) const +{ return Double(pow(val, power)); - } +} - Double Double::inverse() const - { +Double Double::inverse() const +{ #ifdef PROFILE_OP_COUNTS ++inv_cnt; #endif return Double(std::complex(1) / val); - } +} - libff::bigint<1> Double::as_bigint() const - { +libff::bigint<1> Double::as_bigint() const +{ return libff::bigint<1>(val.real()); - } +} - unsigned long Double::as_ulong() const - { +unsigned long Double::as_ulong() const +{ return round(val.real()); - } +} - Double Double::squared() const - { +Double Double::squared() const +{ return Double(val * val); - } +} - Double Double::one() - { +Double Double::one() +{ return Double(1); - } +} - Double Double::zero() - { +Double Double::zero() +{ return Double(0); - } +} - Double Double::random_element() - { +Double Double::random_element() +{ return Double(std::rand() % 1001); - } +} - Double Double::geometric_generator() - { +Double Double::geometric_generator() +{ return Double(2); - } +} - Double Double::arithmetic_generator() - { +Double Double::arithmetic_generator() +{ return Double(1); - } +} - Double Double::multiplicative_generator = Double(2); +Double Double::multiplicative_generator = Double(2); } // libff From 8f2291c07cc569bae11dc9f5c06a0fba1ad16dd2 Mon Sep 17 00:00:00 2001 From: Duncan Tebbs Date: Thu, 21 May 2020 10:33:26 +0100 Subject: [PATCH 4/4] Warnings as errors in travis build --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 60741f99..ad1fad83 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ before_install: before_script: - git submodule init && git submodule update - - mkdir build && cd build && cmake .. + - mkdir build && cd build && cmake -DCMAKE_CXX_FLAGS="-Werror" .. script: - make