Addressing most of the remaining build warnings from issue thread #1617.
0cmake -B build \
1 -DCMAKE_C_COMPILER=clang \
2 -DSECP256K1_ENABLE_MODULE_ECDH=ON \
3 -DSECP256K1_ENABLE_MODULE_RECOVERY=ON \
4 -DSECP256K1_ENABLE_MODULE_EXTRAKEYS=ON \
5 -DSECP256K1_ENABLE_MODULE_SCHNORRSIG=ON \
6 -DSECP256K1_ENABLE_MODULE_MUSIG=ON \
7 -DSECP256K1_ENABLE_MODULE_ELLSWIFT=ON \
8 -DSECP256K1_BUILD_TESTS=OFF \
9 -DSECP256K1_BUILD_EXHAUSTIVE_TESTS=OFF \
10 -DSECP256K1_BUILD_CTIME_TESTS=OFF \
11 -DSECP256K1_BUILD_BENCHMARK=OFF \
12 -DSECP256K1_BUILD_EXAMPLES=OFF \
13 -DCMAKE_C_FLAGS="-Wall -Wextra -Wshorten-64-to-32 -Werror=shorten-64-to-32"
14
15cmake --build build --verbose
0/Users/csjones/Developer/secp256k1/src/modinv64_impl.h:279:39: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
1 279 | w = (f * g * (f * f - 2)) & m;
2 | ~ ~~~~~~~~~~~~~~~~~~~~~~^~~
3/Users/csjones/Developer/secp256k1/src/modinv64_impl.h:289:19: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
4 289 | w = f + (((f + 1) & 4) << 1);
5 | ~ ~~^~~~~~~~~~~~~~~~~~~~~~
6/Users/csjones/Developer/secp256k1/src/modinv64_impl.h:290:26: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
7 290 | w = (-w * g) & m;
8 | ~ ~~~~~~~~~^~~
9/Users/csjones/Developer/secp256k1/src/modinv64_impl.h:370:39: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
10 370 | w = (f * g * (f * f - 2)) & m;
11 | ~ ~~~~~~~~~~~~~~~~~~~~~~^~~
12/Users/csjones/Developer/secp256k1/src/modinv64_impl.h:380:19: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
13 380 | w = f + (((f + 1) & 4) << 1);
14 | ~ ~~^~~~~~~~~~~~~~~~~~~~~~
15/Users/csjones/Developer/secp256k1/src/modinv64_impl.h:381:26: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
16 381 | w = (-w * g) & m;
17 | ~ ~~~~~~~~~^~~
18In file included from /Users/csjones/Developer/secp256k1/src/secp256k1.c:28:
19In file included from /Users/csjones/Developer/secp256k1/src/scalar_impl.h:20:
20/Users/csjones/Developer/secp256k1/src/scalar_4x64_impl.h:112:42: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'int' [-Werror,-Wshorten-64-to-32]
21 112 | overflow = secp256k1_u128_to_u64(&t) + secp256k1_scalar_check_overflow(r);
22 | ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23/Users/csjones/Developer/secp256k1/src/scalar_4x64_impl.h:637:10: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
24 637 | m6 = c0;
25 | ~ ^~
26/Users/csjones/Developer/secp256k1/src/scalar_4x64_impl.h:657:13: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
27 657 | p4 = c0 + m6;
28 | ~ ~~~^~~~
29/Users/csjones/Developer/secp256k1/src/scalar_4x64_impl.h:677:34: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'unsigned int' [-Werror,-Wshorten-64-to-32]
30 677 | secp256k1_scalar_reduce(r, c + secp256k1_scalar_check_overflow(r));
31 | ~~~~~~~~~~~~~~~~~~~~~~~ ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32In file included from /Users/csjones/Developer/secp256k1/src/secp256k1.c:30:
33/Users/csjones/Developer/secp256k1/src/ecmult_impl.h:536:21: error: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
34 536 | for (i = n_wnaf - 1; i >= 0; i--) {
35 | ~ ~~~~~~~^~~
36/Users/csjones/Developer/secp256k1/src/ecmult_impl.h:580:52: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
37 580 | for(j = ECMULT_TABLE_SIZE(bucket_window+2) - 1; j > 0; j--) {
38 | ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
39In file included from /Users/csjones/Developer/secp256k1/src/secp256k1.c:32:
40In file included from /Users/csjones/Developer/secp256k1/src/ecmult_gen_impl.h:14:
41/Users/csjones/Developer/secp256k1/src/hash_impl.h:151:52: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
42 151 | secp256k1_write_be32(&sizedesc[0], hash->bytes >> 29);
43 | ~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~^~~~~
44/Users/csjones/Developer/secp256k1/src/hash_impl.h:152:52: error: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
45 152 | secp256k1_write_be32(&sizedesc[4], hash->bytes << 3);
46 | ~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~^~~~
4714 errors generated.
I applied most of the suggested fixes from #1617 (comment) and used an explicit cast of (uint32_t) in scalar_4x64_impl.h for the two warnings not mentioned in the original issue thread. The warnings in ecmult_impl.h were skipped.
0/Users/csjones/Developer/secp256k1/src/ecmult_impl.h:536:21: error: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
1 536 | for (i = n_wnaf - 1; i >= 0; i--) {
2 | ~ ~~~~~~~^~~
3/Users/csjones/Developer/secp256k1/src/ecmult_impl.h:580:52: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
4 580 | for(j = ECMULT_TABLE_SIZE(bucket_window+2) - 1; j > 0; j--) {
5 | ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
62 errors generated.
EDIT: Investigating failing CI Fixed.