Skip to content

Commit

Permalink
Clean up build warnings (#26)
Browse files Browse the repository at this point in the history
Several variables are used only in assertions. In release builds those
assertions get optimized out leaving otherwise unused variables behind
resulting in unused-but-set-variable warnings. This commit applies the
UNUSED() utility already defined in libff for this purpose.

Signed-off-by: Dan Middleton <[email protected]>

Merged-by: Dev Ojha <[email protected]>
  • Loading branch information
dcmiddle authored Aug 25, 2020
1 parent 1a54539 commit d5768ab
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libff/algebra/curves/tests/test_bilinearity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void pairing_test()
assert(ans1 != GT_one);
assert((ans1^Fr<ppT>::field_char()) == GT_one);
printf("\n\n");
UNUSED(GT_one); // Prevent release build warnings
}

template<typename ppT>
Expand All @@ -72,6 +73,9 @@ void double_miller_loop_test()
const Fqk<ppT> ans_2 = ppT::miller_loop(prec_P2, prec_Q2);
const Fqk<ppT> ans_12 = ppT::double_miller_loop(prec_P1, prec_Q1, prec_P2, prec_Q2);
assert(ans_1 * ans_2 == ans_12);
UNUSED(ans_1); // Prevent release build warnings
UNUSED(ans_2);
UNUSED(ans_12);
}

template<typename ppT>
Expand Down Expand Up @@ -106,6 +110,7 @@ void affine_pairing_test()
assert(ans1 != GT_one);
assert((ans1^Fr<ppT>::field_char()) == GT_one);
printf("\n\n");
UNUSED(GT_one); // Prevent release build warnings
}

int main(void)
Expand Down
14 changes: 14 additions & 0 deletions libff/algebra/curves/tests/test_groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,27 @@ void test_group()
assert((GroupT::order() * one) - one != zero);

test_mixed_add<GroupT>();

// Prevent release build warnings
UNUSED(rand1);
UNUSED(rand2);
UNUSED(randsum);
UNUSED(zero);
UNUSED(one);
UNUSED(two);
UNUSED(three);
UNUSED(four);
UNUSED(five);
UNUSED(a);
UNUSED(b);
}

template<typename GroupT>
void test_mul_by_q()
{
GroupT a = GroupT::random_element();
assert((GroupT::base_field_char()*a) == a.mul_by_q());
UNUSED(a); // Prevent release build warnings
}

template<typename GroupT>
Expand Down
20 changes: 20 additions & 0 deletions libff/algebra/fields/tests/test_fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ void test_field()
assert(a * a.inverse() == one);
assert((a + b) * c.inverse() == a * c.inverse() + (b.inverse() * c).inverse());

// Prevent release build warnings
UNUSED(rand1);
UNUSED(rand2);
UNUSED(randsum);
UNUSED(zero);
UNUSED(one);
UNUSED(a);
UNUSED(b);
UNUSED(c);
UNUSED(d);
}

template<typename FieldT>
Expand All @@ -60,6 +70,8 @@ void test_sqrt()
FieldT a = FieldT::random_element();
FieldT asq = a.squared();
assert(asq.sqrt() == a || asq.sqrt() == -a);
UNUSED(a); // Prevent release build warnings
UNUSED(asq);
}
}

Expand All @@ -70,6 +82,7 @@ void test_two_squarings()
assert(a.squared() == a * a);
assert(a.squared() == a.squared_complex());
assert(a.squared() == a.squared_karatsuba());
UNUSED(a); // Prevent release build warnings
}

template<typename FieldT>
Expand All @@ -82,9 +95,11 @@ void test_Frobenius()
{
const FieldT a_qi = a.Frobenius_map(power);
assert(a_qi == a_q);
UNUSED(a_qi); // Prevent release build warnings

a_q = a_q ^ FieldT::base_field_char();
}
UNUSED(a); // Prevent release build warnings
}

template<typename FieldT>
Expand All @@ -94,6 +109,7 @@ void test_unitary_inverse()
FieldT a = FieldT::random_element();
FieldT aqcubed_minus1 = a.Frobenius_map(FieldT::extension_degree()/2) * a.inverse();
assert(aqcubed_minus1.inverse() == aqcubed_minus1.unitary_inverse());
UNUSED(aqcubed_minus1); // Prevent release build warnings
}

template<typename FieldT>
Expand All @@ -109,6 +125,7 @@ void test_cyclotomic_squaring<Fqk<edwards_pp> >()
// beta = a^((q^(k/2)-1)*(q+1))
FieldT beta = a_unitary.Frobenius_map(1) * a_unitary;
assert(beta.cyclotomic_squared() == beta.squared());
UNUSED(beta); // Prevent release build warnings
}

template<>
Expand All @@ -121,6 +138,7 @@ void test_cyclotomic_squaring<Fqk<mnt4_pp> >()
// beta = a^(q^(k/2)-1)
FieldT beta = a_unitary;
assert(beta.cyclotomic_squared() == beta.squared());
UNUSED(beta); // Prevent release build warnings
}

template<>
Expand All @@ -133,6 +151,7 @@ void test_cyclotomic_squaring<Fqk<mnt6_pp> >()
// beta = a^((q^(k/2)-1)*(q+1))
FieldT beta = a_unitary.Frobenius_map(1) * a_unitary;
assert(beta.cyclotomic_squared() == beta.squared());
UNUSED(beta); // Prevent release build warnings
}

template<typename ppT>
Expand Down Expand Up @@ -199,6 +218,7 @@ void test_Fp4_tom_cook()
c3 = FieldT(12).inverse() * (FieldT(5)*v0 - FieldT(7)*v1) - FieldT(24).inverse()*(v2 - FieldT(7)*v3 + v4 + v5) + FieldT(15)*v6;

assert(res == correct_res);
UNUSED(correct_res); // Prevent release build warnings

// {v0, v3, v4, v5}
const FieldT u = (FieldT::one() - beta).inverse();
Expand Down

0 comments on commit d5768ab

Please sign in to comment.