-Wmaybe-uninitialized warnings under LTO #27343

issue fanquake openend this issue on March 27, 2023
  1. fanquake commented at 1:43 pm on March 27, 2023: member

    Building under GCC 14.0.1 with -flto (Fedora Rawhide) currently results in a number of -Wmaybe-uninitialized warnings. Some of these are things we might not want to “fix”, i.e in test code. Some come from leveldb etc. Open this issue to document them, as some exist with current versions of GCC, and GCC 14.0 will be released soon:

      0leveldb/db/memtable.cc: In function 'GetLengthPrefixedSlice':
      1leveldb/db/memtable.cc:18:22: warning: 'len' may be used uninitialized [-Wmaybe-uninitialized]
      2   18 |   return Slice(p, len);
      3      |                      ^
      4leveldb/db/memtable.cc:15:12: note: 'len' was declared here
      5   15 |   uint32_t len;
      6      |            ^
      7In function 'GetLengthPrefixedSlice',
      8    inlined from 'operator()' at leveldb/db/memtable.cc:32:35,
      9    inlined from 'KeyIsAfterNode' at ./leveldb/db/skiplist.h:257:37,
     10    inlined from 'FindGreaterOrEqual' at ./leveldb/db/skiplist.h:268:23:
     11leveldb/db/memtable.cc:18:22: warning: 'len' may be used uninitialized [-Wmaybe-uninitialized]
     12   18 |   return Slice(p, len);
     13      |                      ^
     14leveldb/db/memtable.cc: In member function 'FindGreaterOrEqual':
     15leveldb/db/memtable.cc:15:12: note: 'len' was declared here
     16   15 |   uint32_t len;
     17      |            ^
     18leveldb/db/memtable.cc: In member function 'Get':
     19leveldb/db/memtable.cc:119:39: warning: 'key_length' may be used uninitialized [-Wmaybe-uninitialized]
     20  119 |             Slice(key_ptr, key_length - 8), key.user_key()) == 0) {
     21      |                                       ^
     22leveldb/db/memtable.cc:116:14: note: 'key_length' was declared here
     23  116 |     uint32_t key_length;
     24      |              ^
     25In member function 'operator=',
     26    inlined from '__ct ' at test/prevector_tests.cpp:215:49,
     27    inlined from 'test_method.isra' at test/prevector_tests.cpp:222:34:
     28random.cpp:749:19: warning: 'D.58376.bitbuf' is used uninitialized [-Wuninitialized]
     29  749 |     bitbuf = from.bitbuf;
     30      |                   ^
     31test/prevector_tests.cpp: In function 'test_method.isra':
     32test/prevector_tests.cpp:215:22: note: '<anonymous>' declared here
     33  215 |         rand_cache = FastRandomContext(rand_seed);
     34      |                      ^
     35leveldb/db/memtable.cc: In function 'GetLengthPrefixedSlice':
     36leveldb/db/memtable.cc:18:22: warning: 'len' may be used uninitialized [-Wmaybe-uninitialized]
     37   18 |   return Slice(p, len);
     38      |                      ^
     39leveldb/db/memtable.cc:15:12: note: 'len' was declared here
     40   15 |   uint32_t len;
     41      |            ^
     42leveldb/db/memtable.cc: In function 'GetLengthPrefixedSlice':
     43leveldb/db/memtable.cc:18:22: warning: 'len' may be used uninitialized [-Wmaybe-uninitialized]
     44   18 |   return Slice(p, len);
     45      |                      ^
     46leveldb/db/memtable.cc:15:12: note: 'len' was declared here
     47   15 |   uint32_t len;
     48      |            ^
     49In function 'GetLengthPrefixedSlice',
     50    inlined from 'operator()' at leveldb/db/memtable.cc:32:35,
     51    inlined from 'KeyIsAfterNode' at ./leveldb/db/skiplist.h:257:37,
     52    inlined from 'FindGreaterOrEqual' at ./leveldb/db/skiplist.h:268:23:
     53leveldb/db/memtable.cc:18:22: warning: 'len' may be used uninitialized [-Wmaybe-uninitialized]
     54   18 |   return Slice(p, len);
     55      |                      ^
     56leveldb/db/memtable.cc: In member function 'FindGreaterOrEqual':
     57leveldb/db/memtable.cc:15:12: note: 'len' was declared here
     58   15 |   uint32_t len;
     59      |            ^
     60In function 'GetLengthPrefixedSlice',
     61    inlined from 'operator()' at leveldb/db/memtable.cc:32:35,
     62    inlined from 'KeyIsAfterNode' at ./leveldb/db/skiplist.h:257:37,
     63    inlined from 'FindGreaterOrEqual' at ./leveldb/db/skiplist.h:268:23:
     64leveldb/db/memtable.cc:18:22: warning: 'len' may be used uninitialized [-Wmaybe-uninitialized]
     65   18 |   return Slice(p, len);
     66      |                      ^
     67leveldb/db/memtable.cc: In member function 'FindGreaterOrEqual':
     68leveldb/db/memtable.cc:15:12: note: 'len' was declared here
     69   15 |   uint32_t len;
     70      |            ^
     71leveldb/db/memtable.cc: In member function 'Get':
     72leveldb/db/memtable.cc:119:39: warning: 'key_length' may be used uninitialized [-Wmaybe-uninitialized]
     73  119 |             Slice(key_ptr, key_length - 8), key.user_key()) == 0) {
     74      |                                       ^
     75leveldb/db/memtable.cc:116:14: note: 'key_length' was declared here
     76  116 |     uint32_t key_length;
     77      |              ^
     78In member function 'operator=',
     79    inlined from 'Seed.constprop' at test/util/random.cpp:32:33:
     80random.cpp:749:19: warning: 'D.69037.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
     81  749 |     bitbuf = from.bitbuf;
     82      |                   ^
     83test/util/random.cpp: In function 'Seed.constprop':
     84test/util/random.cpp:32:33: note: '<anonymous>' declared here
     85   32 |     ctx = FastRandomContext(seed);
     86      |                                 ^
     87leveldb/db/memtable.cc: In member function 'Get':
     88leveldb/db/memtable.cc:119:39: warning: 'key_length' may be used uninitialized [-Wmaybe-uninitialized]
     89  119 |             Slice(key_ptr, key_length - 8), key.user_key()) == 0) {
     90      |                                       ^
     91leveldb/db/memtable.cc:116:14: note: 'key_length' was declared here
     92  116 |     uint32_t key_length;
     93      |              ^
     94In member function 'operator=',
     95    inlined from 'Seed' at test/util/random.cpp:32:33,
     96    inlined from 'SeedInsecureRand' at ./test/util/random.h:41:13,
     97    inlined from '__ct_base ' at test/util/setup_common.cpp:184:21:
     98random.cpp:749:19: warning: 'D.40691.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
     99  749 |     bitbuf = from.bitbuf;
    100      |                   ^
    101test/util/random.cpp: In member function '__ct_base ':
    102test/util/random.cpp:32:33: note: '<anonymous>' declared here
    103   32 |     ctx = FastRandomContext(seed);
    104      |                                 ^
    105leveldb/db/memtable.cc: In function 'GetLengthPrefixedSlice':
    106leveldb/db/memtable.cc:18:22: warning: 'len' may be used uninitialized [-Wmaybe-uninitialized]
    107   18 |   return Slice(p, len);
    108      |                      ^
    109leveldb/db/memtable.cc:15:12: note: 'len' was declared here
    110   15 |   uint32_t len;
    111      |            ^
    112In function 'GetLengthPrefixedSlice',
    113    inlined from 'operator()' at leveldb/db/memtable.cc:32:35,
    114    inlined from 'KeyIsAfterNode' at ./leveldb/db/skiplist.h:257:37,
    115    inlined from 'FindGreaterOrEqual' at ./leveldb/db/skiplist.h:268:23:
    116leveldb/db/memtable.cc:18:22: warning: 'len' may be used uninitialized [-Wmaybe-uninitialized]
    117   18 |   return Slice(p, len);
    118      |                      ^
    119leveldb/db/memtable.cc: In member function 'FindGreaterOrEqual':
    120leveldb/db/memtable.cc:15:12: note: 'len' was declared here
    121   15 |   uint32_t len;
    122      |            ^
    123leveldb/db/memtable.cc: In member function 'Get':
    124leveldb/db/memtable.cc:119:39: warning: 'key_length' may be used uninitialized [-Wmaybe-uninitialized]
    125  119 |             Slice(key_ptr, key_length - 8), key.user_key()) == 0) {
    126      |                                       ^
    127leveldb/db/memtable.cc:116:14: note: 'key_length' was declared here
    128  116 |     uint32_t key_length;
    129      |              ^
    130test/fuzz/float.cpp: In function 'float_fuzz_target':
    131test/fuzz/float.cpp:49:40: warning: 'tmp' may be used uninitialized [-Wmaybe-uninitialized]
    132   49 |         uint64_t encoded = EncodeDouble(d);
    133      |                                        ^
    134test/fuzz/float.cpp:21:20: note: 'tmp' was declared here
    135   21 |             double tmp;
    136      |                    ^
    137In member function 'operator=',
    138    inlined from 'operator()' at test/fuzz/addrman.cpp:127:9,
    139    inlined from '__ct ' at test/fuzz/addrman.cpp:127:9,
    140    inlined from 'addrman_serdeser_fuzz_target' at test/fuzz/addrman.cpp:295:69:
    141random.cpp:749:19: warning: 'D.36455.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
    142  749 |     bitbuf = from.bitbuf;
    143      |                   ^
    144test/fuzz/addrman.cpp: In function 'addrman_serdeser_fuzz_target':
    145test/fuzz/addrman.cpp:127:9: note: '<anonymous>' declared here
    146  127 |         WITH_LOCK(m_impl->cs, m_impl->insecure_rand = FastRandomContext{ConsumeUInt256(fuzzed_data_provider)});
    147      |         ^
    148In member function 'operator=',
    149    inlined from 'operator()' at test/fuzz/addrman.cpp:127:9,
    150    inlined from '__ct ' at test/fuzz/addrman.cpp:127:9,
    151    inlined from 'addrman_serdeser_fuzz_target' at test/fuzz/addrman.cpp:296:69:
    152random.cpp:749:19: warning: 'D.36632.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
    153  749 |     bitbuf = from.bitbuf;
    154      |                   ^
    155test/fuzz/addrman.cpp: In function 'addrman_serdeser_fuzz_target':
    156test/fuzz/addrman.cpp:127:9: note: '<anonymous>' declared here
    157  127 |         WITH_LOCK(m_impl->cs, m_impl->insecure_rand = FastRandomContext{ConsumeUInt256(fuzzed_data_provider)});
    158      |         ^
    159In member function 'operator=',
    160    inlined from 'SeedInsecureRand' at ./test/util/random.h:39:72,
    161    inlined from 'SeedInsecureRand' at ./test/util/random.h:36:20,
    162    inlined from 'test_method' at test/cuckoocache_tests.cpp:40:21,
    163    inlined from 'test_cuckoocache_no_fakes_invoker' at test/cuckoocache_tests.cpp:38:1:
    164random.cpp:749:19: warning: 'D.46810.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
    165  749 |     bitbuf = from.bitbuf;
    166      |                   ^
    167./test/util/random.h: In function 'test_cuckoocache_no_fakes_invoker':
    168./test/util/random.h:39:72: note: '<anonymous>' declared here
    169   39 |         g_insecure_rand_ctx = FastRandomContext(/*fDeterministic=*/true);
    170      |                                                                        ^
    171In member function 'operator=',
    172    inlined from 'SeedInsecureRand' at ./test/util/random.h:39:72,
    173    inlined from 'SeedInsecureRand' at ./test/util/random.h:36:20,
    174    inlined from 'test_cache' at test/cuckoocache_tests.cpp:58:21,
    175    inlined from 'test_method' at test/cuckoocache_tests.cpp:117:84,
    176    inlined from 'cuckoocache_hit_rate_ok_invoker' at test/cuckoocache_tests.cpp:109:1:
    177random.cpp:749:19: warning: 'D.48398.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
    178  749 |     bitbuf = from.bitbuf;
    179      |                   ^
    180./test/util/random.h: In function 'cuckoocache_hit_rate_ok_invoker':
    181./test/util/random.h:39:72: note: '<anonymous>' declared here
    182   39 |         g_insecure_rand_ctx = FastRandomContext(/*fDeterministic=*/true);
    183      |                                                                        ^
    184In member function 'operator=',
    185    inlined from 'SeedInsecureRand' at ./test/util/random.h:39:72,
    186    inlined from 'SeedInsecureRand' at ./test/util/random.h:36:20,
    187    inlined from 'test_cache_erase' at test/cuckoocache_tests.cpp:129:21,
    188    inlined from 'test_method' at test/cuckoocache_tests.cpp:185:72,
    189    inlined from 'cuckoocache_erase_ok_invoker' at test/cuckoocache_tests.cpp:182:1:
    190random.cpp:749:19: warning: 'D.50490.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
    191  749 |     bitbuf = from.bitbuf;
    192      |                   ^
    193./test/util/random.h: In function 'cuckoocache_erase_ok_invoker':
    194./test/util/random.h:39:72: note: '<anonymous>' declared here
    195   39 |         g_insecure_rand_ctx = FastRandomContext(/*fDeterministic=*/true);
    196      |                                                                        ^
    197In function '__fill_a1',
    198    inlined from '__fill_a1' at /usr/include/c++/14/bits/stl_algobase.h:981:21,
    199    inlined from '__fill_a' at /usr/include/c++/14/bits/stl_algobase.h:998:21,
    200    inlined from 'fill' at /usr/include/c++/14/bits/stl_algobase.h:1029:20,
    201    inlined from 'PollutePubKey' at wallet/test/wallet_tests.cpp:503:14:
    202/usr/include/c++/14/bits/stl_algobase.h:952:18: warning: '__builtin_memset' specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
    203  952 |         *__first = __tmp;
    204      |                  ^
    205In member function 'operator=',
    206    inlined from 'SeedInsecureRand' at ./test/util/random.h:39:0,
    207    inlined from 'test_method' at test/util_tests.cpp:448:21,
    208    inlined from 'util_seed_insecure_rand_invoker' at test/util_tests.cpp:446:1:
    209random.cpp:749:19: warning: 'D.49511.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
    210  749 |     bitbuf = from.bitbuf;
    211      |                   ^
    212./test/util/random.h: In function 'util_seed_insecure_rand_invoker':
    213./test/util/random.h:39: note: '<anonymous>' declared here
    214   39 |         g_insecure_rand_ctx = FastRandomContext(/*fDeterministic=*/true);
    215In member function 'operator=',
    216    inlined from 'operator()' at test/fuzz/addrman.cpp:127:9,
    217    inlined from '__ct ' at test/fuzz/addrman.cpp:127:9,
    218    inlined from 'make_unique' at /usr/include/c++/14/bits/unique_ptr.h:1076:30,
    219    inlined from 'addrman_fuzz_target' at test/fuzz/addrman.cpp:228:97:
    220random.cpp:749:19: warning: 'D.38104.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
    221  749 |     bitbuf = from.bitbuf;
    222      |                   ^
    223test/fuzz/addrman.cpp: In function 'addrman_fuzz_target':
    224test/fuzz/addrman.cpp:127:9: note: '<anonymous>' declared here
    225  127 |         WITH_LOCK(m_impl->cs, m_impl->insecure_rand = FastRandomContext{ConsumeUInt256(fuzzed_data_provider)});
    226      |         ^
    227In member function 'operator=',
    228    inlined from 'operator()' at test/fuzz/addrman.cpp:127:9,
    229    inlined from '__ct ' at test/fuzz/addrman.cpp:127:9,
    230    inlined from 'make_unique' at /usr/include/c++/14/bits/unique_ptr.h:1076:30,
    231    inlined from 'addrman_fuzz_target' at test/fuzz/addrman.cpp:235:66:
    232random.cpp:749:19: warning: 'D.41251.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
    233  749 |     bitbuf = from.bitbuf;
    234      |                   ^
    235test/fuzz/addrman.cpp: In function 'addrman_fuzz_target':
    236test/fuzz/addrman.cpp:127:9: note: '<anonymous>' declared here
    237  127 |         WITH_LOCK(m_impl->cs, m_impl->insecure_rand = FastRandomContext{ConsumeUInt256(fuzzed_data_provider)});
    238      |         ^
    239In member function 'operator=',
    240    inlined from 'Seed' at test/util/random.cpp:32:33,
    241    inlined from 'SeedInsecureRand' at ./test/util/random.h:41:13,
    242    inlined from '__ct_base ' at test/util/setup_common.cpp:184:21:
    243random.cpp:749:19: warning: 'D.39055.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
    244  749 |     bitbuf = from.bitbuf;
    245      |                   ^
    246test/util/random.cpp: In member function '__ct_base ':
    247test/util/random.cpp:32:33: note: '<anonymous>' declared here
    248   32 |     ctx = FastRandomContext(seed);
    249      |                                 ^
    250In member function 'operator=',
    251    inlined from 'test_method' at test/orphanage_tests.cpp:57:56,
    252    inlined from 'DoS_mapOrphans_invoker' at test/orphanage_tests.cpp:49:1:
    253random.cpp:749:19: warning: 'D.45887.bitbuf' may be used uninitialized [-Wmaybe-uninitialized]
    254  749 |     bitbuf = from.bitbuf;
    255      |                   ^
    256test/orphanage_tests.cpp: In function 'DoS_mapOrphans_invoker':
    257test/orphanage_tests.cpp:57:56: note: '<anonymous>' declared here
    258   57 |     g_insecure_rand_ctx = FastRandomContext{uint256{33}};
    259      |                                                        ^
    260In member function '__ct ',
    261    inlined from 'construct_at' at /usr/include/c++/14/bits/stl_construct.h:97:14,
    262    inlined from 'construct' at /usr/include/c++/14/bits/alloc_traits.h:536:21,
    263    inlined from '_M_realloc_append' at /usr/include/c++/14/bits/vector.tcc:634:26,
    264    inlined from 'emplace_back' at /usr/include/c++/14/bits/vector.tcc:123:21,
    265    inlined from 'test_method' at test/logging_tests.cpp:166:45,
    266    inlined from 'logging_LogPrintMacros_CategoryName_invoker' at test/logging_tests.cpp:156:1:
    267/usr/include/c++/14/bits/stl_pair.h:444:11: warning: 'category' may be used uninitialized [-Wmaybe-uninitialized]
    268  444 |         : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y))
    269      |           ^
    270test/logging_tests.cpp: In function 'logging_LogPrintMacros_CategoryName_invoker':
    271test/logging_tests.cpp:163:25: note: 'category' was declared here
    272  163 |         BCLog::LogFlags category;
    273      |                         ^
    
  2. maflcko commented at 2:09 pm on March 27, 2023: member
  3. fanquake commented at 11:23 am on March 28, 2023: member

    Fuzz ones removed in #27344

    Thanks. Retested at 8d31d769b7b504104f162a03c94bbc95dec7d849 and updated the op to drop those (other than in float).

  4. maflcko commented at 11:38 am on March 28, 2023: member

    Yeah, that is a false positive. Not sure if gcc are going to fix it, but if you want to work around, you can try something like:

     0diff --git a/src/test/fuzz/float.cpp b/src/test/fuzz/float.cpp
     1index 8714ab8a04..57f8d4cec8 100644
     2--- a/src/test/fuzz/float.cpp
     3+++ b/src/test/fuzz/float.cpp
     4@@ -7,11 +7,13 @@
     5 #include <test/fuzz/fuzz.h>
     6 #include <test/fuzz/util.h>
     7 #include <util/serfloat.h>
     8+#include <util/check.h>
     9 #include <version.h>
    10 
    11 #include <cassert>
    12 #include <cmath>
    13 #include <limits>
    14+#include <optional>
    15 
    16 FUZZ_TARGET(float)
    17 {
    18@@ -19,7 +21,7 @@ FUZZ_TARGET(float)
    19 
    20     {
    21         const double d{[&] {
    22-            double tmp;
    23+            std::optional<double> tmp;
    24             CallOneOf(
    25                 fuzzed_data_provider,
    26                 // an actual number
    27@@ -43,7 +45,7 @@ FUZZ_TARGET(float)
    28                       }); },
    29                 // Anything from raw memory (also checks that DecodeDouble doesn't crash on any input)
    30                 [&] { tmp = DecodeDouble(fuzzed_data_provider.ConsumeIntegral<uint64_t>()); });
    31-            return tmp;
    32+            return *Assert(tmp);
    33         }()};
    34         (void)memusage::DynamicUsage(d);
    35 
    
  5. fanquake commented at 11:06 am on May 3, 2023: member

    Using master (49d543dcaf6ac1b71f8d607dab464a39aff837ac) & GCC 11.3.0 & LTO:

     0./univalue/include/univalue.h: In member function 'getInt':
     1./univalue/include/univalue.h:146:12: warning: 'result' may be used uninitialized in this function [-Wmaybe-uninitialized]
     2  146 |     return result;
     3      |            ^
     4./univalue/include/univalue.h:141:9: note: 'result' was declared here
     5  141 |     Int result;
     6      |         ^
     7./univalue/include/univalue.h: In member function 'getInt':
     8./univalue/include/univalue.h:146:12: warning: 'result' may be used uninitialized in this function [-Wmaybe-uninitialized]
     9  146 |     return result;
    10      |            ^
    11./univalue/include/univalue.h:141:9: note: 'result' was declared here
    12  141 |     Int result;
    13      |         ^
    

    Noting here incase it gets reported.

  6. maflcko commented at 11:42 am on May 3, 2023: member
    My previous reply should be valid for that one as well
  7. fanquake commented at 11:52 am on May 3, 2023: member
    Yea. I don’t really have an intention of fixing these ones, just keeping tabs so that if they do get reported, we can point to a thread.
  8. fanquake commented at 9:40 am on March 21, 2024: member
    Updated op for GCC 14.0.1. Mostly just the same output.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-03 19:12 UTC

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