8000 build: add `-Wundef` by fanquake · Pull Request #29876 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

build: add -Wundef #29876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 24, 2024
Merged

build: add -Wundef #29876

merged 5 commits into from
Jun 24, 2024

Conversation

fanquake
Copy link
Member
@fanquake fanquake commented Apr 15, 2024

Turn on -Wundef.

> Warn if an undefined identifier is evaluated in an #if directive. Such identifiers are replaced with zero..

Note that this is still beneficial with CMake, and may even be nice to have enabled prior, to catch any change in behaviour.

If we end up with this enabled, it should probably be enough to fix #16419.

@DrahtBot
Copy link
Contributor
DrahtBot commented Apr 15, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK hebasto
Concept ACK katesalazar
Stale ACK laanwj, ryanofsky

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29775 (Testnet4 including PoW difficulty adjustment fix by fjahr)
  • #29432 (Stratum v2 Template Provider (take 3) by Sjors)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@laanwj
Copy link
Member
laanwj commented Apr 15, 2024

Concept ACK, issues with misspelled or otherwise missing defines can be really sneaky (and have caused some hard to find bugs in the past), this ia good check to have.

@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin/bitcoin/runs/23825959417

@DrahtBot
Copy link
Contributor

Guix builds (on x86_64)

File commit 58446e1
(master)
commit 36d728a
(master and this pull)
SHA256SUMS.part e64bcc6f819997a4... 3435d6ddfe201135...
*-aarch64-linux-gnu-debug.tar.gz e9dbd78db7ec28a6... 798d3da5d7bea84f...
*-aarch64-linux-gnu.tar.gz 9aa2e1822187deeb... 6a6909988b7b4ba7...
*-arm-linux-gnueabihf-debug.tar.gz b16c1210927617d7... 695cb3aab6fe5378...
*-arm-linux-gnueabihf.tar.gz 573dd0d104ff2f18... d31b3bfaca31bfc5...
*-arm64-apple-darwin-unsigned.tar.gz 5dc92c1599c5b5b8... b68a96df1fc4f423...
*-arm64-apple-darwin-unsigned.zip 3c56b6dc994cadeb... 442cd22ce81d573a...
*-arm64-apple-darwin.tar.gz e83e7e6c83aa4796... aa2bfb98a7fbf383...
*-powerpc64-linux-gnu-debug.tar.gz 7134fd5e2ada4a9e... 8ac217c17a2884c6...
*-powerpc64-linux-gnu.tar.gz a1d3dac39d378d8d... 65654bf93e1c5408...
*-riscv64-linux-gnu-debug.tar.gz 171fd29eee7c062b... 117e59ebe5ecb6e4...
*-riscv64-linux-gnu.tar.gz 84d2958f708b4b0b... 2a3cec2b987ac31e...
*-x86_64-apple-darwin-unsigned.tar.gz 4b45d8205294d3af... 449d4036c5c530fe...
*-x86_64-apple-darwin-unsigned.zip 2d5af9a020c99f17... bfb9940ed37d3729...
*-x86_64-apple-darwin.tar.gz 6adce47f81f36e76... a56c483bfcdb34ac...
*-x86_64-linux-gnu-debug.tar.gz 30d17373f2655e6c... c111f0081452b7fe...
*-x86_64-linux-gnu.tar.gz 4829a910aa342010... e15c51770902d52f...
*.tar.gz 2621583f029a602f... a205f40ba1639482...
guix_build.log ab18d5cc2f844ae9... 7a9079f009388c74...
guix_build.log.diff f556fe2ac3b66192...

Copy link
Member
@laanwj laanwj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK cc09c16

Copy link
Member
@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK.

Copy link
Member
@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK cc09c16.

I suggest to consider updating a help string in

AC_DEFINE_UNQUOTED([HAVE_O_CLOEXEC], [$HAVE_O_CLOEXEC], [Define to 1 if O_CLOEXEC flag is available.])
to "Define to 1 if O_CLOEXEC flag is available, and to 0 if not."

As a follow up, the #16344 might be reconsidered.

@fanquake
Copy link
Member Author
fanquake commented May 3, 2024

Rebased on #25972. Please review that first.

I suggest to consider updating a help string in

I don't touch that here, and it's not clear why we need to change a single instsance out of many help strings that could be similarly updated, so going to leave things as they are.

@fanquake fanquake marked this pull request as draft May 3, 2024 07:42
@DrahtBot
Copy link
Contributor
DrahtBot commented May 3, 2024

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin/bitcoin/runs/24544741593

@katesalazar
Copy link
Contributor

Concept ACK

@theuni
Copy link
Member
theuni commented Jun 6, 2024

Any reason this is still in draft? I agree it seems useful do enable before the CMake switch.

@fanquake
Copy link
Member Author

Any reason this is still in draft? I agree it seems useful do enable before the CMake switch.

Rebased, and fixed the conflict. Added another change for the Win64 CI. We'll probably need to fixup the failing ARM and previous releases job upstream:

In file included from minisketch/src/fields/generic_common_impl.h:12,
                 from minisketch/src/fields/generic_4bytes.cpp:12:
minisketch/src/fields/../int_utils.h:162:7: error: "HAVE_CLZ" is not defined, evaluates to 0 [-Werror=undef]
  162 | #elif HAVE_CLZ
      |       ^~~~~~~~

This was the multiprocess job failure:

/bin/bash ../libtool  --tag=CXX --preserve-dup-deps  --mode=link /usr/bin/ccache clang++ -m32 -std=c++20 -g -O2 -O0 -g3 -ftrapv -fdebug-prefix-map=/ci_container_base/ci/scratch/build/bitcoin-i686-pc-linux-gnu=. -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wgnu -Wformat -Wformat-security -Wvla -Wshadow-field -Wthread-safety -Wloop-analysis -Wredundant-decls -Wunused-member-function -Wdate-time -Wconditional-uninitialized -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wdocumentation -Wundef -Wno-unused-parameter -Wno-self-assign -Werror   -fPIE -pipe -std=c++20 -O1 -g -Wno-error=documentation   -Wl,-z,relro -Wl,-z,now -Wl,-z,separate-code -pie     -pthread -lpthread -L/ci_container_base/depends/i686-pc-linux-gnu/lib  -o bitcoind bitcoind-bitcoind.o  init/bitcoind-bitcoind.o libbitcoin_node.a libbitcoin_wallet.a libbitcoin_common.a libbitcoin_util.a libunivalue.la libbitcoin_zmq.a libbitcoin_consensus.a crypto/libbitcoin_crypto_base.la crypto/libbitcoin_crypto_sse41.la crypto/libbitcoin_crypto_avx2.la crypto/libbitcoin_crypto_x86_shani.la  leveldb/libleveldb.la crc32c/libcrc32c.la   leveldb/libmemenv.la secp256k1/libsecp256k1.la -ldb_cxx-4.8 -lminiupnpc -lnatpmp -L/ci_container_base/depends/i686-pc-linux-gnu/lib -levent_pthreads -levent  -L/ci_container_base/depends/i686-pc-linux-gnu/lib -levent  -L/ci_container_base/depends/i686-pc-linux-gnu/lib -lzmq -lpthread -lrt  -L/ci_container_base/depends/i686-pc-linux-gnu/lib -lsqlite3 -lm  -latomic
libtool: link: /usr/bin/ccache clang++ -m32 -std=c++20 -g -O2 -O0 -g3 -ftrapv -fdebug-prefix-map=/ci_container_base/ci/scratch/build/bitcoin-i686-pc-linux-gnu=. -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wgnu -Wformat -Wformat-security -Wvla -Wshadow-field -Wthread-safety -Wloop-analysis -Wredundant-decls -Wunused-member-function -Wdate-time -Wconditional-uninitialized -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wdocumentation -Wundef -Wno-unused-parameter -Wno-self-assign -Werror -fPIE -pipe -std=c++20 -O1 -g -Wno-error=documentation -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,-z -Wl,separate-code -pie -o bitcoind bitcoind-bitcoind.o init/bitcoind-bitcoind.o  -lpthread -L/ci_container_base/depends/i686-pc-linux-gnu/lib libbitcoin_node.a libbitcoin_wallet.a libbitcoin_common.a libbitcoin_util.a ./.libs/libunivalue.a libbitcoin_zmq.a libbitcoin_consensus.a crypto/.libs/libbitcoin_crypto_base.a crypto/.libs/libbitcoin_crypto_sse41.a crypto/.libs/libbitcoin_crypto_avx2.a crypto/.libs/libbitcoin_crypto_x86_shani.a leveldb/.libs/libleveldb.a crc32c/.libs/libcrc32c.a leveldb/.libs/libmemenv.a secp256k1/.libs/libsecp256k1.a -ldb_cxx-4.8 -lminiupnpc -lnatpmp -levent_pthreads -levent -levent -lzmq -lpthread -lrt -lsqlite3 -lm -latomic -pthread
/usr/bin/ccache clang++ -m32 -std=c++20 -DHAVE_CONFIG_H -I. -I../src/config  -DDEBUG -DDEBUG_LOCKORDER -DDEBUG_LOCKCONTENTION -DRPC_DOC_CHECK -DABORT_ON_FAILED_ASSUME -fmacro-prefix-map=/ci_container_base/ci/scratch/build/bitcoin-i686-pc-linux-gnu=.  -DHAVE_BUILD_INFO -D_FILE_OFFSET_BITS=64 -DPROVIDE_FUZZ_MAIN_FUNCTION -I. -I./minisketch/include -I./secp256k1/include -I./univalue/include -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -I/ci_container_base/depends/i686-pc-linux-gnu/include/ -DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE -g -O2 -O0 -g3 -ftrapv -fdebug-prefix-map=/ci_container_base/ci/scratch/build/bitcoin-i686-pc-linux-gnu=. -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wgnu -Wformat -Wformat-security -Wvla -Wshadow-field -Wthread-safety -Wloop-analysis -Wredundant-decls -Wunused-member-function -Wdate-time -Wconditional-uninitialized -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wdocumentation -Wundef -Wno-unused-parameter -Wno-self-assign -Werror   -fPIE -I/ci_container_base/depends/i686-pc-linux-gnu/include -pthread  -pipe -std=c++20 -O1 -g -Wno-error=documentation -c -o ipc/capnp/libbitcoin_ipc_a-protocol.o `test -f 'ipc/capnp/protocol.cpp' || echo './'`ipc/capnp/protocol.cpp
In file included from ipc/capnp/protocol.cpp:7:
In file included from ./ipc/capnp/init.capnp.h:6:
In file included from /ci_container_base/depends/i686-pc-linux-gnu/include/capnp/generated-header-support.h:26:
In file included from /ci_container_base/depends/i686-pc-linux-gnu/include/capnp/raw-schema.h:24:
In file included from /ci_container_base/depends/i686-pc-linux-gnu/include/capnp/common.h:31:
/ci_container_base/depends/i686-pc-linux-gnu/include/kj/windows-sanity.h:39:6: error: '_WIN32' is not defined, evaluates to 0 [-Werror,-Wundef]
   39 | #if !_WIN32 && !__CYGWIN__
      |      ^
/ci_container_base/depends/i686-pc-linux-gnu/include/kj/windows-sanity.h:39:17: error: '__CYGWIN__' is not defined, evaluates to 0 [-Werror,-Wundef]
   39 | #if !_WIN32 && !__CYGWIN__
      |                 ^
In file included from ipc/capnp/protocol.cpp:7:
In file included from ./ipc/capnp/init.capnp.h:6:
In file included from /ci_container_base/depends/i686-pc-linux-gnu/include/capnp/generated-header-support.h:26:
In file included from /ci_container_base/depends/i686-pc-linux-gnu/include/capnp/raw-schema.h:24:
/ci_container_base/depends/i686-pc-linux-gnu/include/capnp/common.h:33:5: error: 'CAPNP_DEBUG_TYPES' is not defined, evaluates to 0 [-Werror,-Wundef]
   33 | #if CAPNP_DEBUG_TYPES
      |     ^
In file included from ipc/capnp/protocol.cpp:7:
In file included from ./ipc/capnp/init.capnp.h:6:
In file included from /ci_container_base/depends/i686-pc-linux-gnu/include/capnp/generated-header-support.h:26:
/ci_container_base/depends/i686-pc-linux-gnu/include/capnp/raw-schema.h:26:5: error: '_MSC_VER' is not defined, evaluates to 0 [-Werror,-Wundef]
   26 | #if _MSC_VER && !defined(__clang__)
      |     ^
In file included from ipc/capnp/protocol.cpp:7:
In file included from ./ipc/capnp/init.capnp.h:9:
In file included from /ci_container_base/depends/i686-pc-linux-gnu/include/capnp/capability.h:28:
In file included from /ci_container_base/depends/i686-pc-linux-gnu/include/kj/async.h:24:
/ci_container_base/depends/i686-pc-linux-gnu/include/kj/async-prelude.h:34:6: error: 'KJ_NO_EXCEPTIONS' is not defined, evaluates to 0 [-Werror,-Wundef]
   34 | #if !KJ_NO_EXCEPTIONS
      |      ^
In file included from ipc/capnp/protocol.cpp:7:
In file included from ./ipc/capnp/init.capnp.h:9:
In file included from /ci_container_base/depends/i686-pc-linux-gnu/include/capnp/capability.h:28:
In file included from /ci_container_base/depends/i686-pc-linux-gnu/include/kj/async.h:26:
/ci_container_base/depends/i686-pc-linux-gnu/include/kj/refcount.h:26:5: error: '_MSC_VER' is not defined, evaluates to 0 [-Werror,-Wundef]
   26 | #if _MSC_VER
      |     ^
6 errors generated.
make[2]: *** [Makefile:9738: ipc/capnp/libbitcoin_ipc_a-protocol.o] Error 1
make[2]: Leaving directory '/ci_container_base/ci/scratch/build/bitcoin-i686-pc-linux-gnu/src'
make[1]: *** [Makefile:20118: install-recursive] Error 1
make[1]: Leaving directory '/ci_container_base/ci/scratch/build/bitcoin-i686-pc-linux-gnu/src'

@hebasto
Copy link
Member
hebasto commented Jun 10, 2024

This was the multiprocess job failure:

cc @ryanofsky

@fanquake fanquake marked this pull request as ready for review June 18, 2024 11:56
@fanquake
Copy link
Member Author

This is ready for further review.

@DrahtBot
Copy link
Contributor

Guix builds (on x86_64) [untrusted test-only build, possibly unsafe, not for production use]

File commit 9c5cdf0
(master)
commit f41ceb6
(master and this pull)
SHA256SUMS.part 8f176cd889e88c8c... 92d21483e82b2c1b...
*-aarch64-linux-gnu-debug.tar.gz c4603906c5e521c8... fdc8c845f2e6712d...
*-aarch64-linux-gnu.tar.gz 7f003e10e7ca2269... b6577e5985b7da0c...
*-arm-linux-gnueabihf-debug.tar.gz e4a3366f4709760b... 4d5e494959a1d4 6D40 d6...
*-arm-linux-gnueabihf.tar.gz 5ce86cdc3b81597c... 5bdaf259bc089ed2...
*-arm64-apple-darwin-unsigned.tar.gz e44ea6e8bee2b7f5... 256cfe6927d88cbb...
*-arm64-apple-darwin-unsigned.zip bd2feb2c203fd085... 8702bade54b719f3...
*-arm64-apple-darwin.tar.gz e6e67247faef3bd2... 1117533e8c50ee2b...
*-powerpc64-linux-gnu-debug.tar.gz 59c87ca578af3674... 94e8e0491e60cfa9...
*-powerpc64-linux-gnu.tar.gz c42749de73d93831... eda06147241168b9...
*-riscv64-linux-gnu-debug.tar.gz 088a788947cf2c8e... 5c208613a156427c...
*-riscv64-linux-gnu.tar.gz 7160ceb124bc9cf2... 45530d68ca9aafd3...
*-x86_64-apple-darwin-unsigned.tar.gz 78167426b180f468... c0342ac292fc7609...
*-x86_64-apple-darwin-unsigned.zip 779c80cc3c01c447... 1d806bf0ecd64155...
*-x86_64-apple-darwin.tar.gz 8b498a9181e91cdb... 02dd017c2db27448...
*-x86_64-linux-gnu-debug.tar.gz c44d3d010deda4b7... 57a68a9bbe06fc76...
*-x86_64-linux-gnu.tar.gz 1700f4111e39a2b7... bdfc16c0956a4575...
*.tar.gz 8ebf38cec0d3f4eb... 8ed68c8fceaf06c4...
guix_build.log 554e151400868aa2... 670b3c580f73892f...
guix_build.log.diff f4e73142d6abed0e...

Copy link
Contributor
@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 9e5bd97

@DrahtBot DrahtBot requested review from hebasto and laanwj June 20, 2024 18:17
ryanofsky and others added 5 commits June 21, 2024 09:42
Without this change there are errors from boost like:

/ci_container_base/depends/i686-pc-linux-gnu/include/boost/signals2/expired_slot.hpp:23:28: error: 'what' overrides a member function but is not marked 'override' [-Werror,-Wsuggest-override]
/ci_container_base/depends/i686-pc-linux-gnu/include/boost/signals2/detail/signal_template.hpp:750:32: error: 'lock_pimpl' overrides a member function but is not marked 'override' [-Werror,-Wsuggest-override]
/ci_container_base/depends/i686-pc-linux-gnu/include/boost/signals2/connection.hpp:150:22: error: 'connected' overrides a member function but is not marked 'override' [-Werror,-Wsuggest-override]

There do not seem to be errors from capnproto currently, but add a suppression
for it, too, to be consistent with other libraries.
randomenv.cpp:48:5: warning: 'HAVE_VM_VM_PARAM_H' is not defined, evaluates to 0 [-Wundef]

randomenv.cpp:51:5: warning: 'HAVE_SYS_RESOURCES_H' is not defined, evaluates to 0 [-Wundef]

randomenv.cpp:424:5: error: 'HAVE_SYSCTL' is not defined, evaluates to 0 [-Werror,-Wundef]
```bash
init.cpp:526:5: error: "HAVE_SOCKADDR_UN" is not defined, evaluates to 0 [-Werror=undef]
  526 | #if HAVE_SOCKADDR_UN
      |     ^~~~~~~~~~~~~~~~
init.cpp:541:5: error: "HAVE_SOCKADDR_UN" is not defined, evaluates to 0 [-Werror=undef]
  541 | #if HAVE_SOCKADDR_UN
      |     ^~~~~~~~~~~~~~~~
init.cpp:1318:5: error: "HAVE_SOCKADDR_UN" is not defined, evaluates to 0 [-Werror=undef]
 1318 | #if HAVE_SOCKADDR_UN
```
```
netbase.cpp:26:5: error: "HAVE_SOCKADDR_UN" is not defined, evaluates to 0 [-Werror=undef]
   26 | #if HAVE_SOCKADDR_UN
      |     ^~~~~~~~~~~~~~~~
netbase.cpp:221:5: error: "HAVE_SOCKADDR_UN" is not defined, evaluates to 0 [-Werror=undef]
  221 | #if HAVE_SOCKADDR_UN
      |     ^~~~~~~~~~~~~~~~
netbase.cpp:496:5: error: "HAVE_SOCKADDR_UN" is not defined, evaluates to 0 [-Werror=undef]
  496 | #if HAVE_SOCKADDR_UN
      |     ^~~~~~~~~~~~~~~~
netbase.cpp:531:5: error: "HAVE_SOCKADDR_UN" is not defined, evaluates to 0 [-Werror=undef]
  531 | #if HAVE_SOCKADDR_UN
      |     ^~~~~~~~~~~~~~~~
netbase.cpp:639:5: error: "HAVE_SOCKADDR_UN" is not defined, evaluates to 0 [-Werror=undef]
  639 | #if HAVE_SOCKADDR_UN
```
"Warn if an undefined identifier is evaluated in an #if directive. Such
identifiers are replaced with zero."
@fanquake
Copy link
Member Author

Rebased to fix conflicts.

Copy link
Member
@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK e3dc64f, I have reviewed the code and it looks OK.

@DrahtBot DrahtBot requested a review from ryanofsky June 24, 2024 13:17
@fanquake fanquake merged commit aef5ac7 into bitcoin:master Jun 24, 2024
16 checks passed
@fanquake fanquake deleted the add_wundef branch June 24, 2024 14:15
@hebasto
Copy link
Member
hebasto commented Jul 14, 2024

Ported to the CMake-based build system in hebasto#264.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check usages of #if defined(...)
8 participants
0