How to reproduce -Werror=sign-compare failures locally? #19123

issue maflcko openend this issue on May 31, 2020
  1. maflcko commented at 1:10 pm on May 31, 2020: member

    I tried gcc and clang, but those failures won’t show for me. See #18637 (comment)

    While I like the warning and error, if developers can’t see them on their boxes, it makes it tedious to fix those issues up.

  2. maflcko added the label Feature on May 31, 2020
  3. maflcko added the label Questions and Help on May 31, 2020
  4. maflcko removed the label Feature on May 31, 2020
  5. ajtowns commented at 2:53 pm on July 1, 2020: contributor
     0#include <cstddef>
     1
     2int main(void)
     3{
     4    int x = -2;
     5    size_t y = 3;
     6    if (x == y*y) {
     7        return 1;
     8    }
     9    return 0;
    10}
    

    gives me errors for both gcc (v9.3) and clang (v9.0):

    0$ g++ -Wall -W -Werror -o testsign test.cc
    1test.cc: In function ‘int main()’:
    2test.cc:7:11: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare]
    3    7 |     if (x == y*y) {
    4      |         ~~^~~~~~
    5cc1plus: all warnings being treated as errors
    
    0$ clang++ -Wall -W -Werror -o testsign test.cc
    1test.cc:7:11: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
    2    if (x == y*y) {
    3        ~ ^  ~~~
    41 error generated.
    

    If I say if (x*x == y*y), g++ stops complaining though.

  6. maflcko commented at 1:41 pm on July 2, 2020: member
    Will reopen the next time I run into this again
  7. maflcko closed this on Jul 2, 2020

  8. maflcko commented at 1:30 pm on July 11, 2020: member

    Steps to reproduce on commit 5f96bce9b7f38c687817d58e8b54a5b7ebfe91b3

    Clang

     0Options used to compile and link:
     1  multiprocess  = no
     2  with wallet   = yes
     3  with gui / qt = yes
     4    with qr     = yes
     5  with zmq      = yes
     6  with test     = yes
     7    with fuzz   = no
     8  with bench    = yes
     9  with upnp     = no
    10  use asm       = yes
    11  sanitizers    = 
    12  debug enabled = no
    13  gprof enabled = no
    14  werror        = no
    15
    16  target os     = linux
    17  build os      = linux-gnu
    18
    19  CC            = /usr/bin/ccache clang
    20  CFLAGS        = -g -O2
    21  CPPFLAGS      =   -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2  -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS
    22  CXX           = /usr/bin/ccache clang++ -std=c++17
    23  CXXFLAGS      =   -Wstack-protector -fstack-protector-all  -Wall -Wextra -Wgnu -Wformat -Wvla -Wshadow-field -Wswitch -Wformat-security -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunused-variable -Wdate-time -Wconditional-uninitialized -Wsign-compare -Wunreachable-code-loop-increment  -Wno-unused-parameter -Wno-self-assign -Wno-unused-local-typedef -Wno-deprecated-register -Wno-implicit-fallthrough -Wno-deprecated-copy   -g -O2
    24  LDFLAGS       = -pthread  -Wl,-z,relro -Wl,-z,now -pie  
    25  ARFLAGS       = cr
    

    GCC

     0Options used to compile and link:
     1  multiprocess  = no
     2  with wallet   = yes
     3  with gui / qt = yes
     4    with qr     = yes
     5  with zmq      = yes
     6  with test     = yes
     7    with fuzz   = no
     8  with bench    = yes
     9  with upnp     = no
    10  use asm       = yes
    11  sanitizers    = 
    12  debug enabled = no
    13  gprof enabled = no
    14  werror        = no
    15
    16  target os     = linux
    17  build os      = linux-gnu
    18
    19  CC            = /usr/bin/ccache gcc
    20  CFLAGS        = -g -O2
    21  CPPFLAGS      =   -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2  -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS
    22  CXX           = /usr/bin/ccache g++ -std=c++11
    23  CXXFLAGS      =   -fstack-reuse=none -Wstack-protector -fstack-protector-all  -Wall -Wextra -Wformat -Wvla -Wswitch -Wredundant-decls -Wunused-variable -Wdate-time -Wsign-compare -Wsuggest-override  -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-deprecated-copy   -g -O2 -fno-extended-identifiers
    24  LDFLAGS       = -pthread  -Wl,-z,relro -Wl,-z,now -pie  
    25  ARFLAGS       = cr
    
  9. maflcko reopened this on Jul 11, 2020

  10. ajtowns commented at 2:48 am on July 13, 2020: contributor

    If I checkout 5f96bce9b7f38c687817d58e8b54a5b7ebfe91b3 and apply

     0$ git diff
     1diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
     2index 0f7c3e5b39..54a2b53182 100644
     3--- a/src/wallet/test/wallet_tests.cpp
     4+++ b/src/wallet/test/wallet_tests.cpp
     5@@ -812,6 +812,11 @@ BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup)
     6 
     7         LOCK(wallet->cs_wallet);
     8         BOOST_CHECK(wallet->HasWalletSpend(prev_hash));
     9+        int x = 1;
    10+        if (wallet->mapWallet.count(block_hash) == 1) (void)0;
    11+        if (wallet->mapWallet.count(block_hash) == (int)1) (void)0;
    12+        if (wallet->mapWallet.count(block_hash) == x) (void)0;
    13+        if (wallet->mapWallet.count(block_hash) == -1) (void)0;
    14         BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_hash), 1);
    15 
    16         std::vector<uint256> vHashIn{ block_hash }, vHashOut;
    

    Then ./configure CC=clang CXX=clang++ --with-incompatible-bdb --enable-zmq --without-miniupnpc --enable-c++17 (clang 9.0.1) I get the following errors:

    0wallet/test/wallet_tests.cpp:818:49: warning: comparison of integers of different signs: 'std::map<uint256, CWalletTx, std::less<uint256>, std::allocator<std::pair<const uint256, CWalletTx> > >::size_type' (aka 'unsigned long') and 'int' [-Wsign-compare]
    1        if (wallet->mapWallet.count(block_hash) == x) (void)0;
    2            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~
    3wallet/test/wallet_tests.cpp:819:49: warning: comparison of integers of different signs: 'std::map<uint256, CWalletTx, std::less<uint256>, std::allocator<std::pair<const uint256, CWalletTx> > >::size_type' (aka 'unsigned long') and 'int' [-Wsign-compare]
    4        if (wallet->mapWallet.count(block_hash) == -1) (void)0;
    

    same errors with gcc (9.3.0), give or take some wording. The two travis reports reportedly have clang version 7.0.0, and Apple clang 11.0.0, both of which I think are Xcode versions rather than llvm versions. Wikipedia claims xcode clang 11.0.0 corresponds to llvm clang 8.0.0, but trying clang 8 and clang 7 in Debian, and clang 6 in bionic gives me the same collection of errors as above, so I think this must be some Xcode specific thing, where other compilers are able to figure out the value is a constant that’s always in range, and just emit correct code, rather than a warning?

  11. Empact commented at 4:24 pm on June 9, 2021: member

    I’m currently running Mac OS 10.15.7 (19H1217)

    0$ /usr/local/bin/ccache gcc --version
    1Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
    2Apple clang version 12.0.0 (clang-1200.0.32.29)
    3Target: x86_64-apple-darwin19.6.0
    4Thread model: posix
    5InstalledDir: /Library/Developer/CommandLineTools/usr/bin
    
     0Options used to compile and link:
     1  external signer = no
     2  multiprocess    = no
     3  with libs       = yes
     4  with wallet     = yes
     5    with sqlite   = yes
     6    with bdb      = yes
     7  with gui / qt   = yes
     8    with qr       = yes
     9  with zmq        = no
    10  with test       = yes
    11  with bench      = yes
    12  with upnp       = yes
    13  with natpmp     = no
    14  use asm         = yes
    15  ebpf tracing    = yes
    16  sanitizers      = 
    17  debug enabled   = no
    18  gprof enabled   = no
    19  werror          = no
    20
    21  target os       = darwin
    22  build os        = darwin19.6.0
    23
    24  CC              = /usr/local/bin/ccache gcc
    25  CFLAGS          = -pthread -g -O2
    26  CPPFLAGS        =  -fmacro-prefix-map=$(abs_srcdir)=.  -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2  -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -DPROVIDE_FUZZ_MAIN_FUNCTION
    27  CXX             = /usr/local/bin/ccache g++ -std=c++17
    28  CXXFLAGS        =  -fdebug-prefix-map=$(abs_srcdir)=.  -Wstack-protector -fstack-protector-all -fcf-protection=full  -Wall -Wextra -Wgnu -Wformat -Wformat-security -Wvla -Wshadow-field -Wswitch -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunused-variable -Wunused-member-function -Wdate-time -Wconditional-uninitialized -Wsign-compare -Woverloaded-virtual -Wunreachable-code-loop-increment  -Wno-unused-parameter -Wno-self-assign -Wno-unused-local-typedef -Wno-implicit-fallthrough   -g -O2
    29  LDFLAGS         = -lpthread  -Wl,-bind_at_load   -Wl,-headerpad_max_install_names -Wl,-dead_strip -Wl,-dead_strip_dylibs
    30  ARFLAGS         = cr
    

    The above setting show warnings when building 93e38d5c06d9b32326585121b46bb59041d7cfed.

  12. maflcko commented at 6:26 am on July 9, 2021: member
    According to #22176 (comment) this can be reproduced on OpenBSD 6.9, clang 10.0.1
  13. maflcko closed this on Jan 17, 2022

  14. bitcoin locked this on Jan 17, 2023
  15. bitcoin unlocked this on Jun 15, 2023
  16. maflcko commented at 3:57 pm on June 15, 2023: member

    Another way to reproduce (at least for 32-bit) would be:

    ( cd depends && make HOST=i686-pc-linux-gnu CC='clang -m32' CXX='clang++ -m32 -Wsign-compare' NO_QT=1 NO_WALLET=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 -j $(nproc) ) && ./autogen.sh && CONFIG_SITE="$PWD/depends/i686-pc-linux-gnu/share/config.site" ./configure && make -j $(nproc) src/bitcoind

  17. bitcoin locked this on Jun 14, 2024

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 16:13 UTC

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