Warn on and add missing [[noreturn]]

bitcoin/bitcoin: PR #35911

1 minor finding · 2 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[minor] · clang-cl misses the build-dependent -Wmissing-noreturn suppression

A clang-cl Release build with BUILD_FUZZ_BINARY=ON and BUILD_FOR_FUZZING=OFF is expected to warn, or fail with CMAKE_COMPILE_WARNING_AS_ERROR=ON, because the suppression is skipped; this diagnostic was not reproduced.

Location: src/test/fuzz/fuzz.cpp:135 (head).

Details and suggested fix

CMakeLists.txt enables -Wmissing-noreturn for clang-cl too, and test_fuzz inherits it through core_interface. In the documented Release compile/link configuration, both G_FUZZING_BUILD and G_ABORT_ON_FAILED_ASSUME are false, so initialize() always exits. However, clang-cl defines __clang__ but not __GNUC__, so both diagnostic guards skip the suppression. Widen both guards to defined(__GNUC__) || defined(__clang__). Keep these build-dependent functions unannotated because they can return in Debug or BUILD_FOR_FUZZING=ON builds. Windows fuzz CI uses the latter configuration and therefore does not cover this case.


Optional improvements

Link

[suggestion] · [[noreturn]] conflicts with returning IPC proxy overrides

[[noreturn]] on the deprecated IPC virtuals advertises stronger control-flow guarantees than their generated proxies provide after a successful reply; no in-tree C++ caller using these methods through a proxy was found.

Location: src/interfaces/init.h:51 (head).

Details and suggested fix

libmultiprocess generates overrides of Init::makeMiningOld2() and BlockTemplate::submitSolutionOld7() because both remain in the schemas. The generated methods call clientInvoke() and then return normally on success, with return result; for submitSolutionOld7(). The base interface consequently supplies non-returning control-flow information for methods whose proxy implementations can return. Current server defaults throw, as the local and Python tests expect; a GCC or Clang miscompile at virtual call sites has not been established. Leave these two virtuals unannotated and suppress -Wmissing-noreturn locally, retaining the throwing defaults without overstating the proxy interface's guarantee.


Link

[suggestion] · Helper relocation obscures the diagnostic changes in 8e457a89

Separating the unchanged fuzz.cpp helper relocation would make the warning-suppression change in 8e457a89 independently reviewable without changing behavior.

Location: src/test/fuzz/fuzz.cpp:123 at 8e457a899932 (commit) (commit).

Details and suggested fix

7ba20e50829c90a44564de81219c4619dc1bccb1 annotates signal_handler() in place. Its direct child, 8e457a8999320150d26d7dd9261cf895622efffb, then moves the unchanged read_stdin(), read_file(), g_input_path, and signal_handler() block above initialize() while adding the diagnostic region. The relocation keeps those helpers outside the suppression, but mixes the small pragma change with roughly 40 lines of movement. Extract the relocation into a move-only commit between those two commits so reviewers can verify unchanged movement separately from suppression scope. The helpers do not depend on initialize(), and 8966ea43b93081f659d064151ff2f82274303684 enables the warning only afterward, so this preserves the final tree and introduces no intermediate build dependency.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Bitcoin Core adopted [[noreturn]] to make exceptional control flow visible to analysis tools: the original 2017 proposal explicitly sought fewer false-positive and false-negative reports about unused or unreachable code, with possible additional compiler optimizations.

This explains why annotating existing aborting or throwing helpers matters even without changing their bodies. The affected behavior is primarily the compiler's model of reachable execution, rather than a new Bitcoin protocol rule.

Source 1 · Source 2

The preceding #35896 discussion supplies a concrete example of the analysis problem: adding noreturn to the assertion-failure helper removed a GCC warning encountered with defaulted comparisons. The explanation was that the optimizer otherwise still saw a path with a plausibly null transaction pointer; the warning depended on language mode, member layout, and whether the comparison was visible to optimization.

This connects the broad annotation policy to an observed failure mode: missing termination information can produce misleading diagnostics far from the helper itself. It also explains why changing source structure merely to silence such a warning can obscure the underlying control-flow issue.

Source 1 · Source 2