-Wmaybe-uninitialized when compiling with -O1 #1361

issue hebasto openend this issue on June 27, 2023
  1. hebasto commented at 11:29 am on June 27, 2023: member
     0$ ./autogen.sh && ./configure CFLAGS=-O1
     1$ make clean > /dev/null && make > /dev/null 
     2In file included from src/secp256k1.c:30:
     3In function 'secp256k1_ecmult_strauss_wnaf',
     4    inlined from 'secp256k1_ecmult' at src/ecmult_impl.h:353:5:
     5src/ecmult_impl.h:291:5: warning: 'aux' may be used uninitialized [-Wmaybe-uninitialized]
     6  291 |     secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);
     7      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     8In file included from src/secp256k1.c:29:
     9src/group_impl.h: In function 'secp256k1_ecmult':
    10src/group_impl.h:224:13: note: by argument 3 of type 'const secp256k1_fe *' to 'secp256k1_ge_table_set_globalz' declared here
    11  224 | static void secp256k1_ge_table_set_globalz(size_t len, secp256k1_ge *a, const secp256k1_fe *zr) {
    12      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    13src/ecmult_impl.h:345:18: note: 'aux' declared here
    14  345 |     secp256k1_fe aux[ECMULT_TABLE_SIZE(WINDOW_A)];
    15      |                  ^~~
    16In file included from src/secp256k1.c:30,
    17                 from src/bench_internal.c:8:
    18In function secp256k1_ecmult_strauss_wnaf,
    19    inlined from secp256k1_ecmult at src/ecmult_impl.h:353:5:
    20src/ecmult_impl.h:291:5: warning: aux may be used uninitialized [-Wmaybe-uninitialized]
    21  291 |     secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);
    22      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    23In file included from src/secp256k1.c:29:
    24src/group_impl.h: In function secp256k1_ecmult:
    25src/group_impl.h:224:13: note: by argument 3 of type const secp256k1_fe * to secp256k1_ge_table_set_globalz declared here
    26  224 | static void secp256k1_ge_table_set_globalz(size_t len, secp256k1_ge *a, const secp256k1_fe *zr) {
    27      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    28src/ecmult_impl.h:345:18: note: aux declared here
    29  345 |     secp256k1_fe aux[ECMULT_TABLE_SIZE(WINDOW_A)];
    30      |                  ^~~
    

    Using gcc 12.2.

    No warnings with clang 15.

  2. real-or-random commented at 12:52 pm on June 27, 2023: contributor

    Wrapping the call in if (no > 0) suppresses this:

    0    if (no > 0) {
    1        secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);
    2    }
    

    (Or adding SECP256K1_INLINE to secp256k1_ge_table_set_globalz, but this seems a bit arbitrary…)

  3. hebasto commented at 1:10 pm on June 27, 2023: member

    Wrapping the call in if (no > 0) suppresses this:

    0    if (no > 0) {
    1        secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);
    2    }
    

    Would if (no) be more consistent with the code in for loop above?

  4. real-or-random commented at 2:27 pm on June 27, 2023: contributor

    Would if (no) be more consistent with the code in for loop above?

    I think so.

  5. hebasto cross-referenced this on Jun 28, 2023 from issue Avoid `-Wmaybe-uninitialized` when compiling with `gcc -O1` by hebasto
  6. real-or-random closed this on Jul 3, 2023


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-30 01:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me