Skip to content

Warn on and add missing [[noreturn]] - #35911

Open
fanquake wants to merge 4 commits into
bitcoin:masterfrom
fanquake:missing_noreturn
Open

fanquake wants to merge 4 commits into
bitcoin:masterfrom
fanquake:missing_noreturn

Conversation

@fanquake

@fanquake fanquake commented Aug 6, 2026 •

Copy link
Copy Markdown
Member

Missing [[noreturn]] attributes can cause compiler false positives and other issues; see discussion in #35896 (comment). Add missing attributes, and turn on compiler warnings.

Some [[noreturn]] additions may appear redundant, however they suppress warnings for various compiler versions, see discussion in #35911 (comment), and could be dropped in future, when support for those compilers is removed.

Related:
bitcoin-core/libmultiprocess#339.
bitcoin-core/leveldb-subtree#64.
arun11299/cpp-subprocess#132.

@DrahtBot

DrahtBot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK hebasto
Stale ACK stickies-v

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #37047 (fuzz: unpoison argc/argv in LLVMFuzzerInitialize under MSan by fanquake)
  • #37034 (init: avoid pointing to a disabled debug log on failure by l0rinc)
  • #36820 (refactor: remove more dead code by fanquake)
  • #36631 (fuzz: add a custom mutator for PSBT by brunoerg)
  • #36167 (build: Enable -Wunused by fanquake)
  • #35355 (Use atomics for determining whether trace logging is enabled by ajtowns)
  • #34132 (coins,dbwrapper: make database point-read failures fatal by l0rinc)

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.

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice. lgtm. Left some style nits, but feel free to ignore.

../src/test/fuzz/fuzz.cpp:239:26: warning: code will never be executed [-Wunreachable-code]

This looks like a compiler bug?

Comment thread src/test/util/setup_common.cpp Resolved
Comment thread src/test/threadpool_tests.cpp Resolved
Comment thread src/util/subprocess.h Resolved
@DrahtBot

DrahtBot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/31089666107/job/92577355450
LLM reason (✨ experimental): CI failed at build time because clang with -Werror rejected fuzz test code in src/test/fuzz/fuzz.cpp (invalid noreturn function return and unreachable code).

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly 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.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

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

Comment thread src/test/fuzz/fuzz.cpp Resolved
@fanquake

fanquake commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

Opened bitcoin-core/leveldb-subtree#64 for the leveldb changes.

@DrahtBot

DrahtBot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/31093313597/job/92589235946
LLM reason (✨ experimental): CI failed because the lint check subtree detected that a subtree directory was modified without the required subtree merge.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly 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.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

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

Comment thread CMakeLists.txt Resolved

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Concept ACK.

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you submit commit 2b6dee1 in a separate PR? That way, we can review and land it sooner to unbreak the nightly CI.

@fanquake

fanquake commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

Could you submit commit 2b6dee1 in a separate PR?

It is part of #35896.

@DrahtBot

DrahtBot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/31164196113/job/92821231499
LLM reason (✨ experimental): CI failed because the linter’s “subtree” check detected modified subtree directories without a corresponding subtree merge.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly 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.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

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

@stickies-v

Copy link
Copy Markdown
Contributor

Concept ACK

@fanquake
fanquake marked this pull request as ready for review November 21, 2026 08:51
@fanquake

Copy link
Copy Markdown
Member Author

Rebased.

Comment thread src/rpc/mining.cpp
static RPCMethod generate()
{
return RPCMethod{"generate", "has been replaced by the -generate cli option. Refer to -help for more information.", {}, {}, RPCExamples{""}, [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue {
return RPCMethod{"generate", "has been replaced by the -generate cli option. Refer to -help for more information.", {}, {}, RPCExamples{""}, [] [[noreturn]] (const RPCMethod& self, const JSONRPCRequest& request) -> UniValue {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

basically the same question from before ( #35911 (review)):

A human reader will already see the throw, so for them this attribute doesn't add anything. And similarly for a compiler it doesn't add anything either, because it will be cast away from the lambda?

(Same for other lambdas, and virtual functions, etc)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Took at look, and Clang <=21 (Ubuntu clang version 21.1.8 (6ubuntu1)), and I assume the equivalent version of Apple Clang, will warn without the attributes (some output below). I would rather leave a few (possibly redundant) annotations in place, and then just drop them once support for < Clang 22 is dropped?

[163/1145] Building CXX object src/wallet/CMakeFiles/bitcoin_wallet.dir/dump.cpp.o
/root/bitcoin/src/wallet/dump.cpp:54:24: warning: function 'operator()' could be declared with attribute 'noreturn' [-Wmissing-noreturn]
   54 |     auto throw_error = [](bilingual_str message) {
      |                        ^
1 warning generated.
[276/1145] Building CXX object src/CMakeFiles/bitcoin_node.dir/node/interfaces.cpp.o
In file included from /root/bitcoin/src/node/interfaces.cpp:23:
/root/bitcoin/src/interfaces/mining.h:81:18: warning: function 'submitSolutionOld7' could be declared with attribute 'noreturn' [-Wmissing-noreturn]
   81 |     virtual bool submitSolutionOld7(uint32_t, uint32_t, uint32_t, CTransactionRef)
      |                  ^
1 warning generated.
[282/1145] Building CXX object src/CMakeFiles/bitcoin_node.dir/rpc/node.cpp.o
In file included from /root/bitcoin/src/rpc/node.cpp:18:
In file included from /root/bitcoin/src/interfaces/init.h:15:
/root/bitcoin/src/interfaces/mining.h:81:18: warning: function 'submitSolutionOld7' could be declared with attribute 'noreturn' [-Wmissing-noreturn]
   81 |     virtual bool submitSolutionOld7(uint32_t, uint32_t, uint32_t, CTransactionRef)
      |                  ^
In file included from /root/bitcoin/src/rpc/node.cpp:18:
/root/bitcoin/src/interfaces/init.h:51:18: warning: function 'makeMiningOld2' could be declared with attribute 'noreturn' [-Wmissing-noreturn]
   51 |     virtual void makeMiningOld2() { throw std::runtime_error("Old mining interface (@2) not supported. Please update your client!"); }
      |                  ^
2 warnings generated.
[314/1145] Building CXX object src/CMakeFiles/bitcoin_node.dir/rpc/mining.cpp.o
/root/bitcoin/src/rpc/mining.cpp:288:146: warning: function 'operator()' could be declared with attribute 'noreturn' [-Wmissing-noreturn]
  288 |     return RPCMethod{"generate", "has been replaced by the -generate cli option. Refer to -help for more information.", {}, {}, RPCExamples{""}, [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue {
      |                                                                                                                                                  ^
1 warning generated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In Win Cross, Alpine, 32bit Arm i686 & previous releases:

/home/runner/work/_temp/src/test/util/net.cpp:238:11: error: function might be candidate for attribute ‘noreturn’ [-Werror=suggest-attribute=noreturn]
  238 | ZeroSock& ZeroSock::operator=(Sock&& other)
      |           ^~~~~~~~
/home/runner/work/_temp/src/test/util/net.cpp: In member function ‘virtual StaticContentsSock& StaticContentsSock::operator=(Sock&&)’:
/home/runner/work/_temp/src/test/util/net.cpp:258:21: error: function might be candidate for attribute ‘noreturn’ [-Werror=suggest-attribute=noreturn]
  258 | StaticContentsSock& StaticContentsSock::operator=(Sock&& other)
      |                     ^~~~~~~~~~~~~~~~~~
/home/runner/work/_temp/src/test/util/net.cpp: In member function ‘virtual DynSock& DynSock::operator=(Sock&&)’:
/home/runner/work/_temp/src/test/util/net.cpp:378:10: error: function might be candidate for attribute ‘noreturn’ [-Werror=suggest-attribute=noreturn]
  378 | DynSock& DynSock::operator=(Sock&&)
      |          ^~~~~~~

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok, I see. Seems fine then

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a link to this to the PR description.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would rather leave a few (possibly redundant) annotations in place, and then just drop them once support for < Clang 22 is dropped?

Should we add a TODO comment? Otherwise, it will be easy to forget to drop them when the time comes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure if it's needed (this is also a few years away), and they are not only for Clang. Otherwise feel free to propose a diff.

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task Alpine (musl): https://github.com/bitcoin/bitcoin/actions/runs/45035866867/job/137249377761
LLM reason (✨ experimental): The build failed because -Werror promoted GCC’s suggest-attribute=noreturn warnings in src/test/util/net.cpp to errors.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly 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.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

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

@stickies-v stickies-v left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK 53ab81e

Comment thread src/test/fuzz/fuzz.cpp Resolved
Comment thread src/interfaces/init.h
virtual bool canListenIpc() { return false; }
virtual const char* exeName() { return nullptr; }
virtual void makeMiningOld2() { throw std::runtime_error("Old mining interface (@2) not supported. Please update your client!"); }
[[noreturn]] virtual void makeMiningOld2() { throw std::runtime_error("Old mining interface (@2) not supported. Please update your client!"); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: it's a bit awkward to mark a virtual method as [[noreturn]] when an override can be implemented to return.

The libmultiprocess generated ProxyClient method overrides can return. I don't think anything in-tree calls makeMiningOld2 (or submitSolutionOld7) via IPC, but if that changes, a newer client (with noreturn) that calls an older server (that may return) can cause UB. The IPC interface is experimental, but at the same time the only reason we have these Old functions to handle version mismatches gracefully. Perhaps it makes sense to just not mark these kinds of functions as virtual?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clang 22.1 and later handles such cases correctly and emits no warning.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. See #35911 (comment).

@stickies-v

Copy link
Copy Markdown
Contributor

re-ACK 1de12da

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The implementation of MakeWalletLoader() depends on the ENABLE_WALLET configuration variable.

We could use a pragma here:

--- a/src/dummywallet.cpp
+++ b/src/dummywallet.cpp
@@ -57,9 +57,18 @@ const WalletInitInterface& g_wallet_init_interface = DummyWalletInit();

 namespace interfaces {

+#if defined(__GNUC__) || defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmissing-noreturn"
+#endif
+
 std::unique_ptr<WalletLoader> MakeWalletLoader(Chain& chain, ArgsManager& args)
 {
     throw std::logic_error("Wallet function called in non-wallet build.");
 }

+#if defined(__GNUC__) || defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+
 } // namespace interfaces

Comment thread src/test/fuzz/fuzz.cpp Resolved
@DrahtBot
DrahtBot requested a review from hebasto December 3, 2026 12:26
@fanquake

fanquake commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Rebased for #37047 and addressed comments.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants